Skip to content
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

[develop-v2] main merge #182

Merged
merged 2 commits into from
Jun 4, 2024
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
15 changes: 15 additions & 0 deletions src/main/java/com/lesso/neverland/gpt/application/GptService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lesso.neverland.gpt.application;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.lesso.neverland.gpt.dto.GptResponseDto;
import com.lesso.neverland.gpt.dto.GptRequest;
import com.lesso.neverland.gpt.dto.GptResponse;
Expand Down Expand Up @@ -56,4 +58,17 @@ public GptResponseDto parseResponse(String response) {
// ์ถ”์ถœ๋œ ํ•œ๊ธ€ ๋ถ€๋ถ„๊ณผ ์˜์–ด ๋ถ€๋ถ„์œผ๋กœ CompletePuzzleResponse ๊ฐ์ฒด ์ƒ์„ฑ
return new GptResponseDto(englishPart, koreanPart);
}

public GptResponseDto parse(String response) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());

GptResponseDto responseDto = null;
try {
responseDto = objectMapper.readValue(response, GptResponseDto.class);
} catch (Exception e) {
e.printStackTrace();
}
return responseDto;
}
}
13 changes: 5 additions & 8 deletions src/main/java/com/lesso/neverland/gpt/dto/GptRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
public record GptRequest(String model, List<ChatMessage> messages, Double temperature) {

private static String prefixMessage =
"์ด ๊ธ€๋“ค์€ ํ•œ ์ถ”์–ต์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ๋ช…์ด ์ž‘์„ฑํ•œ ๊ธ€์ด์•ผ. ํ˜•ํƒœ๋ฅผ ๋ณด๋ฉด ํฐ๋”ฐ์˜ดํ‘œ์™€ ์‰ผํ‘œ๋กœ ํ•œ ๋ช…์ด ์ž‘์„ฑํ•œ ๊ธ€์„ ๋ถ„๋ฆฌํ•œ๊ฑฐ์•ผ. ์ฆ‰, ํฐ๋”ฐ์˜ดํ‘œ ์•ˆ์— ๋“ค์–ด๊ฐ„ ๊ธ€์ด ํ•œ ๋ช…์ด ์ž‘์„ฑํ•œ ๊ธ€์ด๋ผ๋Š” ๋œป์ด์•ผ."
+ "์ด ๊ธ€๋“ค์„ ์ž˜ ์ •๋ฆฌํ•ด์„œ 100์ž ์ •๋„์˜ ํ•˜๋‚˜์˜ ๊ธ€๋กœ ๋งŒ๋“ค์–ด์„œ ํ•œ๊ธ€๊ณผ ์˜์–ด๋กœ ๊ฐ๊ฐ ์ž‘์„ฑํ•ด์ค˜. ๊ทผ๋ฐ ์ž˜ ์•Œ์•„์•ผ ํ•  ๊ฒŒ ์ด ๊ธ€๋“ค์„ ์ž‘์„ฑํ•œ ์‚ฌ๋žŒ๋“ค์ด ๋‹ค ๊ฐ™์ด ํ•จ๊ป˜ํ•œ ์ผ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ธ€์„ ์“ธ ๋•Œ ์ฃผ์ฒด๋ฅผ ์šฐ๋ฆฌ๋ผ๊ณ  ํ•ด์•ผํ•ด. ์šฐ๋ฆฌ ์ด ๋•Œ ์ด๋žฌ๋Š”๋ฐ ์ด๋Ÿฐ ๋Š๋‚Œ์œผ๋กœ ๋ง์ด์•ผ. ๋ชจ๋“  ๋‚ด์šฉ์ด ์ ์ ˆํ•˜๊ฒŒ ๋‹ค ๋“ค์–ด๊ฐ”์œผ๋ฉด ์ข‹๊ฒ ์–ด. ๊ทธ๋ƒฅ ์ด์–ด๋ถ™์ด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์ ์ ˆํžˆ ์„ž์–ด์„œ ์ƒˆ๋กœ์šด ๊ธ€๋กœ ์ •๋ฆฌํ•ด๋‹ฌ๋ผ๋Š”๊ฑฐ์•ผ. "
//+ "๊ทธ๋ฆฌ๊ณ  ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ•œ ๊ธ€์ด๋ž‘, ์˜์–ด๋กœ ์ž‘์„ฑํ•œ ๊ธ€ ๋‘ ๊ฐœ๋ฅผ ๋‹ค ๋ฐ˜ํ™˜ํ•ด์ค˜."
+ "๋ฐ˜ํ™˜ํ•  ๋•Œ ํ˜•์‹์€ ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ•œ ๊ธ€์„ ๊ด„ํ˜ธ๋กœ ๋ฌถ๊ณ  ์˜์–ด๋กœ ์ž‘์„ฑํ•œ ๊ธ€์€ ๋˜ ๋”ฐ๋กœ ๊ด„ํ˜ธ๋กœ ๋ฌถ์–ด์„œ ๋ณด๋‚ด์ค˜."
+ "(ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ•œ ๊ธ€ 100์ž), (์˜์–ด๋กœ ์ž‘์„ฑํ•œ ๊ธ€ 100์ž) ์ด ํ˜•์‹์œผ๋กœ ๋ณด๋‚ด๋‹ฌ๋ผ๋Š” ๋ง์ด์•ผ. ๊ฐ ๊ธ€์„ ๊ด„ํ˜ธ๋กœ ๋ฌถ๊ณ  ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ํ•ด์ค˜."
+ "๋‹ค๋ฅธ ๋ถ€๊ฐ€์ ์ธ ๋ง ํ•˜์ง€ ๋ง๊ณ  ๋”ฑ ์ •๋ฆฌํ•œ ๊ธ€๋งŒ ๋ฐ˜ํ™˜ํ•ด์ค˜. ๊ทธ๋ฆฌ๊ณ  ๋งํˆฌ๋ฅผ ์ผ๊ธฐ ์“ด ๊ฒƒ์ฒ˜๋Ÿผ ~ํ–ˆ์–ด. ๋Š๋‚Œ์œผ๋กœ ์ž‘์„ฑํ•ด์ค˜. ๋ฌธ์žฅ์ด ์ข€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ด์–ด์ง€๊ฒŒ ํ•ด์ค„๋ž˜? ์ „์ฒด๊ฐ€ ํ•˜๋‚˜์˜ ์ผ๊ธฐ์ฒ˜๋Ÿผ ๋Š๊ปด์ง€๊ฒŒ ์จ์ค˜. ๊ทธ๋ฆฌ๊ณ  ๊ธ€ ์•ˆ์— ๋”ฐ์˜ดํ‘œ๋‚˜ ์ค„๋ฐ”๊ฟˆ ๋ฌธ์ž ๋„ฃ์ง€ ๋งˆ."
"์ด ๊ธ€๋“ค์€ ํ•œ ์ถ”์–ต์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ๋ช…์ด ์ž‘์„ฑํ•œ ๊ธ€์ด์•ผ. ํฐ๋”ฐ์˜ดํ‘œ์™€ ์‰ผํ‘œ๋กœ ๊ฐ์ž ์ž‘์„ฑํ•œ ๊ธ€์„ ๋ถ„๋ฆฌํ•ด์„œ ๋ณด๋‚ด. ์ฆ‰, ํฐ๋”ฐ์˜ดํ‘œ ์•ˆ์— ๋“ค์–ด๊ฐ„ ๊ธ€์ด ํ•œ ๋ช…์ด ์ž‘์„ฑํ•œ ๊ธ€์ด๋ผ๋Š” ๋œป์ด์•ผ."
+ "์ด ๊ธ€๋“ค์„ ์ž˜ ์ •๋ฆฌํ•ด์„œ 100์ž ์ •๋„์˜ ํ•˜๋‚˜์˜ ๊ธ€๋กœ ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ•ด์ค˜. ๊ทธ๋ฆฌ๊ณ  ์ •๋ฆฌ๋œ ๊ธ€์—์„œ ์ฃผ์ฒด๋ฅผ ์šฐ๋ฆฌ๋ผ๊ณ  ํ‘œํ˜„ํ•ด์ค˜. ๋ชจ๋“  ๋‚ด์šฉ์ด ๋น ์ง€์ง€ ์•Š๊ณ  ์ ์ ˆํ•˜๊ฒŒ ๋‹ค ๋“ค์–ด๊ฐ”์œผ๋ฉด ์ข‹๊ฒ ์–ด. ๊ทธ๋ƒฅ ์ด์–ด ๋ถ™์ด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์ ์ ˆํžˆ ์„ž์–ด์„œ ์ƒˆ๋กœ์šด ๊ธ€๋กœ ์ •๋ฆฌํ•ด ๋‹ฌ๋ผ๋Š”๊ฑฐ์•ผ."
+ "์ „์ฒด์ ์œผ๋กœ ๊ตฌ์–ด์ฒด ๋Š๋‚Œ์œผ๋กœ ~๋‹ค. ๋ง๊ณ  ~ํ–ˆ์—ˆ์–ด. ๋งํˆฌ๋กœ ์ž‘์„ฑํ•ด์ค˜. ๋ง์ด ์ข€ ์ด์–ด์ง€๊ฒŒ ํ•ด์„œ ์ผ๊ธฐ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด."
//+ "ํ•œ๊ธ€๋กœ ์ž‘์„ฑ๋œ ๊ธ€์ด๋ž‘ ์˜์–ด๋กœ ์ž‘์„ฑ๋œ ๊ธ€์„ ๋ฐ˜๋“œ์‹œ ์ค„๋ฐ”๊ฟˆ ๋ฌธ์ž๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ๋ณด๋‚ด์ค˜."
;
+ "๋ฐ˜ํ™˜ํ•  ๋•Œ๋Š” ๋„ค๊ฐ€ ์ •๋ฆฌํ•œ ๊ธ€(ํ•œ๊ธ€๋กœ ์ž‘์„ฑ), ์ •๋ฆฌํ•œ ๊ธ€์„ ์˜์–ด๋กœ ๋ณ€ํ™˜ํ•œ ๊ธ€์„ JSON ํ˜•์‹์œผ๋กœ ๋ณด๋‚ด์ค˜."
+ "๋‹ค๋ฅธ ์„ค๋ช… ์—†์ด JSON๋งŒ ๋ฐ˜ํ™˜ํ•ด์ฃผ๊ณ , JSON์˜ ํ‚ค๋Š” prompt(String), description(String)์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์–ด. description์—๋Š” ํ•œ๊ธ€๋กœ ์ •๋ฆฌํ•œ ๊ธ€์„ ๋‹ด์•„์ฃผ๊ณ , prompt์—๋Š” description์„ ์˜์–ด๋กœ ๋ณ€ํ™˜ํ•œ ๊ธ€์„ ๋‹ด์•„์ค˜."
+ "๋‹ค๋ฅธ ๋ถ€๊ฐ€์ ์ธ ์„ค๋ช…ํ•˜์ง€ ๋ง๊ณ  ๋”ฑ JSON๋งŒ ๋ฐ˜ํ™˜ํ•ด์ค˜.";

public static ChatCompletionRequest from(String inputText) {
return ChatCompletionRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ public BaseResponse<CompletePuzzleResponse> completePuzzle(Long groupIdx, Long p

// GPT ์š”์•ฝ ์ˆ˜ํ–‰
GptResponse response = gptService.completion(gptService.toText(puzzleTextList));
GptResponseDto gptResponseDto = gptService.parseResponse(response.messages().get(0).message());
//GptResponseDto gptResponseDto = gptService.parseResponse(response.messages().get(0).message());
GptResponseDto gptResponseDto = gptService.parse(response.messages().get(0).message());

// Album ์ƒ์„ฑ
Album newAlbum = Album.builder()
Expand Down
Loading