-
Notifications
You must be signed in to change notification settings - Fork 0
[DEV-188/BE] feat: llm 요청에 대한 인터페이스 설계 및 구현 #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "DEV-188/feat/LLM-\uC694\uCCAD\uC5D0-\uB300\uD55C-\uC778\uD130\uD398\uC774\uC2A4-\uC124\uACC4-\uBC0F-\uAD6C\uD604"
Changes from all commits
17b9f52
654f8f2
d5948be
f41d9a9
108f9c9
fbbe273
6143085
1bc8f34
f0a2754
620f713
84d5a1d
74c87a6
983335b
016253a
c06f0bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import com.shyashyashya.refit.global.gemini.GeminiClient; | ||
| import com.shyashyashya.refit.global.gemini.GeminiGenerateRequest; | ||
| import com.shyashyashya.refit.global.gemini.GeminiGenerateResponse; | ||
| import com.shyashyashya.refit.global.gemini.GenerateModel; | ||
| import com.shyashyashya.refit.global.gemini.StarAnalysisGeminiResponse; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.Executor; | ||
|
|
@@ -43,7 +44,10 @@ public CompletableFuture<StarAnalysisDto> createStarAnalysis(Long qnaSetId) { | |
|
|
||
| log.info("Send star analysis generate request to gemini. qnaSetId: {}", qnaSetId); | ||
| CompletableFuture<GeminiGenerateResponse> reqFuture = | ||
| geminiClient.sendAsyncRequest(requestBody, STAR_ANALYSIS_CREATE_REQUEST_TIMEOUT_SEC); | ||
| // geminiClient.sendAsyncRequest(requestBody, GenerateModel.GEMINI_2_5_FLASH_LITE, | ||
| // STAR_ANALYSIS_CREATE_REQUEST_TIMEOUT_SEC); | ||
| geminiClient.sendAsyncTextGenerateRequest( | ||
| requestBody, GenerateModel.GEMMA_3_27B_IT, STAR_ANALYSIS_CREATE_REQUEST_TIMEOUT_SEC); | ||
|
|
||
| return reqFuture | ||
| .thenApplyAsync( | ||
|
|
@@ -72,6 +76,12 @@ private StarAnalysisDto processSuccessRequest( | |
|
|
||
| private StarAnalysisGeminiResponse parseStarAnalysisGeminiResponse(String text) { | ||
| try { | ||
| if (text.startsWith("```json\n")) { | ||
| text = text.substring("```json\n".length()); | ||
| } | ||
| if (text.endsWith("```")) { | ||
| text = text.substring(0, text.length() - "```".length()); | ||
| } | ||
|
Comment on lines
+79
to
+84
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 이 파트가 전에 말씀하셨던 모델별 응답 형식의 차이? 와 관련된 로직일까요? 아니면 테스트 용으로 로직을 작성하는 과정에서 필요하여 작성된 로직일까요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 특정 모델이 응답에 ```json ```을 붙이는 것을 해결하기 위한 로직입니다! |
||
| return objectMapper.readValue(text, StarAnalysisGeminiResponse.class); | ||
| } catch (JsonProcessingException e) { | ||
| throw new CustomException(STAR_ANALYSIS_PARSING_FAILED); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.shyashyashya.refit.global.gemini; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
| import java.util.List; | ||
|
|
||
| public record GeminiEmbeddingRequest(TaskType taskType, Content content, OutputDimensionality outputDimensionality) { | ||
|
|
||
| public enum TaskType { | ||
| SEMANTIC_SIMILARITY, | ||
| CLASSIFICATION, | ||
| CLUSTERING | ||
| } | ||
|
|
||
| public enum OutputDimensionality { | ||
| D2048(2048), | ||
| D1536(1536), | ||
| D768(768), | ||
| D512(512), | ||
| D256(256), | ||
| D128(128); | ||
|
|
||
| private final int value; | ||
|
|
||
| OutputDimensionality(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @JsonValue | ||
| public int value() { | ||
| return value; | ||
| } | ||
| } | ||
|
|
||
| public record Content(List<Part> parts) {} | ||
|
|
||
| public record Part(String text) {} | ||
|
|
||
| public static GeminiEmbeddingRequest of(String text, TaskType taskType, OutputDimensionality outputDimensionality) { | ||
| if (text == null || text.isBlank()) { | ||
| throw new IllegalArgumentException("text must not be blank"); | ||
| } | ||
|
|
||
| Content content = new Content(List.of(new Part(text))); | ||
| return new GeminiEmbeddingRequest(taskType, content, outputDimensionality); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.shyashyashya.refit.global.gemini; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record GeminiEmbeddingResponse(Embedding embedding) { | ||
|
|
||
| public record Embedding(List<Float> values) {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.shyashyashya.refit.global.gemini; | ||
|
|
||
| public enum GenerateModel { | ||
| GEMINI_2_5_PRO("gemini-2.5-pro"), | ||
| GEMINI_2_5_FLASH_LITE("gemini-2.5-flash-lite"), | ||
| GEMINI_2_5_FLASH("gemini-2.5-flash"), | ||
| GEMINI_3_FLASH("gemini-3-flash-preview"), | ||
| GEMINI_3_PRO("gemini-3-pro-preview"), | ||
|
|
||
| GEMMA_3_1B_IT("gemma-3-1b-it"), | ||
| GEMMA_3_4B_IT("gemma-3-4b-it"), | ||
| GEMMA_3_12B_IT("gemma-3-12b-it"), | ||
| GEMMA_3_27B_IT("gemma-3-27b-it"); | ||
|
|
||
| private static final String PREFIX = "https://generativelanguage.googleapis.com/v1beta/models/"; | ||
| private static final String SUFFIX = ":generateContent"; | ||
|
|
||
| private final String name; | ||
| private final String endpoint; | ||
|
|
||
| GenerateModel(String name) { | ||
| this.name = name; | ||
| this.endpoint = PREFIX + name + SUFFIX; | ||
| } | ||
|
|
||
| public String id() { | ||
| return name; | ||
| } | ||
|
|
||
| public String endpoint() { | ||
| return endpoint; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.