Skip to content

Commit

Permalink
feat: 이스케이프 문자열 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
osoohynn committed Nov 29, 2024
1 parent 8f0f325 commit f344786
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ private MessageDto getAnswer() {
.exchange(promptUrl, HttpMethod.POST, requestEntity, Map.class);

try {
Map<String, Object> responseBody = response.getBody();
String assistantMessage = ((List<Map<String, Object>>) responseBody.get("choices"))
String assistantMessage = ((List<Map<String, Object>>) response.getBody().get("choices"))
.stream()
.findFirst()
.map(choice -> (Map<String, Object>) choice.get("message"))
.map(message -> (String) message.get("content"))
.map(content -> content.replaceAll("^\"|\"$", "")) // 문자열 양쪽의 따옴표 제거
.orElse("No response from assistant.");

// 대화 기록 저장
chatHistoryService.addMessage("assistant", assistantMessage);
chatHistoryService.answerHistory.add(assistantMessage);

// 메시지 DTO 반환
return MessageDto.of(assistantMessage);
} catch (Exception e) {
return MessageDto.of("An error occurred while processing the response.");
Expand Down

0 comments on commit f344786

Please sign in to comment.