Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CorsConfigurationSource corsConfigurationSource() {

// 허용할 출처 설정
configuration.setAllowedOrigins(List.of(
"http://localhost:5174",
"http://localhost:5173",
"http://localhost:3000",
"https://presentalk.store",
"https://app.presentalk.store"
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/team4/giftidea/configuration/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.team4.giftidea.configuration;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI giftIdeaOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("🎁 GiftIdea API 문서")
.description("GPT 기반 선물 추천 API")
.version("1.0.0")
.contact(new Contact()
.name("팀4")
.email("team4@giftidea.com")
.url("https://presentalk.store"))
.license(new License()
.name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0")))
.externalDocs(new ExternalDocumentation()
.description("GitHub Repository")
.url("https://github.com/team4/giftidea"))
.servers(List.of(
new Server().url("https://app.presentalk.store").description("🚀 배포 환경"),
new Server().url("http://localhost:8080").description("🛠️ 로컬 개발 환경")
));
}
}
38 changes: 20 additions & 18 deletions src/main/java/com/team4/giftidea/controller/GptController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

@Tag(name = "GPT 추천 API", description = "GPT를 이용하여 사용자 맞춤 선물 추천을 제공하는 API")
@Tag(name = "🎁 GPT 추천 API", description = "카카오톡 대화를 분석하여 GPT를 통해 추천 선물을 제공하는 API")
@RestController
@RequestMapping("/api/gpt")
@Slf4j
Expand All @@ -49,39 +49,41 @@ public GptController(RestTemplate restTemplate, GptConfig gptConfig, ProductServ
* @param theme 선물 테마 (예: "birthday", "valentine")
* @return 추천된 상품 목록
*/
@Operation(summary = "대화 분석 후 추천 상품 반환", description = "카카오톡 대화를 분석하여 GPT API를 통해 키워드를 추출하고, 해당 키워드에 맞는 추천 상품을 반환합니다.")
@Operation(
summary = "카톡 대화 분석 후 선물 추천",
description = "카카오톡 대화 파일을 분석하여 GPT API를 이용해 키워드를 추출하고, 이에 맞는 추천 상품을 반환합니다."
)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "추천 상품 목록 반환"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 파라미터"),
@ApiResponse(responseCode = "415", description = "지원되지 않는 파일 형식"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 발생")
})
@PostMapping("/process")
@PostMapping(value = "/process", consumes = "multipart/form-data", produces = "application/json")
public List<Product> processFileAndRecommend(
@RequestParam("file") @Parameter(description = "카카오톡 대화 내용이 포함된 파일", required = true) MultipartFile file,
@RequestParam("targetName") @Parameter(description = "대상 이름", required = true) String targetName,
@RequestParam("relation") @Parameter(description = "대상과의 관계", required = true) String relation,
@RequestParam("sex") @Parameter(description = "대상 성별", required = true) String sex,
@RequestParam("theme") @Parameter(description = "선물의 주제", required = true) String theme) {
@RequestParam("file") @Parameter(description = "카카오톡 대화 파일 (.txt)", required = true) MultipartFile file,
@RequestParam("targetName") @Parameter(description = "분석 대상 이름 (예: '여자친구')", required = true) String targetName,
@RequestParam("relation") @Parameter(description = "대상과의 관계 (couple, friend, parent 등)", required = true) String relation,
@RequestParam("sex") @Parameter(description = "대상 성별 (male 또는 female)", required = true) String sex,
@RequestParam("theme") @Parameter(description = "선물 주제 (birthday, valentine 등)", required = true) String theme
) {
log.info("대화 분석 시작 - 대상: {}, 관계: {}, 성별: {}, 테마: {}", targetName, relation, sex, theme);

// 1. 파일 전처리
List<String> processedMessages = preprocessKakaoFile(file, targetName);

// 2. GPT API 호출: 전처리된 메시지로 키워드 반환
String categories = generatePrompt(processedMessages, relation, sex, theme); // 이미 키워드를 추출했음
String categories = generatePrompt(processedMessages, relation, sex, theme);

// 3. 키워드 리스트로 변환된 값 그대로 사용
// 3. 키워드 리스트 변환 및 상품 검색
List<String> keywords = Arrays.asList(categories.split(","));
keywords.replaceAll(String::trim); // 공백 제거
keywords.replaceAll(String::trim);
log.debug("🔍 추출된 키워드 목록: {}", keywords);

log.debug("추출된 키워드 목록: {}", keywords);

// 4. 상품 검색 (DB에서 키워드 기반으로 추천 상품 검색)
List<Product> products = productService.searchByKeywords(keywords);
log.debug("🎁 추천된 상품: {}", products);

// 검색된 상품 확인 로그
log.debug("검색된 상품: {}", products);

return products; // 상품 목록 반환
return products;
}

private static final int MAX_TOKENS = 15000; // 15000 토큰 제한
Expand Down