File tree Expand file tree Collapse file tree
main/java/dev/interview/server/ai
test/java/dev/interview/server/ai Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818public class AiController {
1919 private final QuestionGenerationServiceImpl questionGenerationService ;
2020
21- // 질문 생성 API
21+ // 질문 생성 API
2222 @ PostMapping ("/generate-questions" )
23- public Mono <ResponseEntity <?>> generateQuestions (@ RequestBody GenerateQuestionRequest request ) {
24- return questionGenerationService .generateQuestionsAsync (request ) // 비동기 메서드 직접 반환
25- .map (ResponseEntity ::ok )
26- .onErrorResume (IllegalStateException .class , e ->
27- Mono .just (ResponseEntity .status (HttpStatus .TOO_MANY_REQUESTS )
28- .body (new ErrorResponse ("중복 요청입니다. 잠시 후 다시 시도해 주세요" ))));
23+ public ResponseEntity <?> generateQuestions (@ RequestBody GenerateQuestionRequest request ) {
24+ try {
25+
26+ GeneratedQnaResponse response = questionGenerationService .generateQuestions (request );
27+
28+ return ResponseEntity .ok (response );
29+
30+ } catch (IllegalStateException e ) {
31+
32+ return ResponseEntity .status (HttpStatus .TOO_MANY_REQUESTS )
33+
34+ .body (new ErrorResponse ("중복 요청입니다. 잠시 후 다시 시도해 주세요" ));
35+
36+ }
2937 }
3038}
Original file line number Diff line number Diff line change 55import java .util .List ;
66
77public interface EmbeddingService {
8+ List <Float > createEmbedding (String text );
89 Mono <List <Float >> createEmbeddingAsync (String text );
910}
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ public class EmbeddingServiceImpl implements EmbeddingService{
2323 @ Value ("${openai.api.key}" )
2424 private String openAiApiKey ;
2525
26+ @ Override
27+ public List <Float > createEmbedding (String text ) {
28+ return createEmbeddingAsync (text )
29+ .doOnError (e -> log .error ("Embedding 처리 오류: {}" , e .getMessage ()))
30+ .blockOptional ()
31+ .orElse (Collections .emptyList ());
32+ }
33+
2634 // 글 요약 -> 임베딩 벡터 생성 (OpenAI API 사용)
2735 @ Override
2836 public Mono <List <Float >> createEmbeddingAsync (String text ) {
Original file line number Diff line number Diff line change 55import reactor .core .publisher .Mono ;
66
77public interface QuestionGenerationService {
8+ GeneratedQnaResponse generateQuestions (GenerateQuestionRequest request );
89 Mono <GeneratedQnaResponse > generateQuestionsAsync (GenerateQuestionRequest request );
910}
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ public class QuestionGenerationServiceImpl implements QuestionGenerationService
2222 private final EmbeddingService embeddingService ; // 임베딩 생성
2323 private final RedisLockService redisLockService ;
2424
25+ @ Override
26+ public GeneratedQnaResponse generateQuestions (GenerateQuestionRequest request ) {
27+ return generateQuestionsAsync (request )
28+ .doOnError (e -> log .error ("질문 생성 실패: {}" , e .getMessage ()))
29+ .blockOptional ()
30+ .orElseThrow (() -> new RuntimeException ("질문 생성 실패" ));
31+ }
32+
2533 // 전체 질문 생성 프로세스
2634 @ Override
2735 public Mono <GeneratedQnaResponse > generateQuestionsAsync (GenerateQuestionRequest request ) {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ void generatedQuestions_success() throws Exception {
5050 ));
5151
5252 // test용 config에 등록된 gptClient mock이 사용됨
53- when (gptClient .generateQuestions (any (), any ())).thenReturn (response );
53+ // when(gptClient.generateQuestions(any(), any())).thenReturn(response);
5454
5555 // when & then
5656 mockMvc .perform (post ("/api/ai/generate-questions" )
You can’t perform that action at this time.
0 commit comments