Skip to content

Commit

Permalink
fix: Chatting 안 되는 문제 해결 (#255)
Browse files Browse the repository at this point in the history
## 변경사항
'''
Content type 'application/json;charset=UTF-8' not supported
'''
와 같은 문제로 ChatCompletionResponse로 convert를 못하던 문제를 해결..!
record 내부에 중첩으로 record를 선언해서 생긴 문제 같음.

## 고려사항

## Comment

## Test

## 질문사항

Signed-off-by: Unan <[email protected]>
  • Loading branch information
unanchoi authored Nov 14, 2024
1 parent 343f358 commit bbaa71b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TestUseCase {
private final SettingService settingService;

public HyperClovaTestResponse testHyperClova(HyperClovaTestRequest request) {
final ChatCompletionResponse response = hyperClovaService.generateChatCompletion(request.content());
ChatCompletionResponse response = hyperClovaService.generateChatCompletion(request.content());
return HyperClovaTestResponse.builder()
.content(response.result().message().content())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ChatLogEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
private ChatRole role;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "complete_quest")
public class CompleteQuestEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site.offload.external.hyperclova;

public record AiFilter(String groupName, String name, int score) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@

@Builder
public record ChatCompletionResponse(Status status, Result result) {

public record Status(String code, String message) {}

public record Message(String role, String content) {}

public record AiFilter(String groupName, String name, String score, String result) {}

public record Result(Message message, int inputLength, int outputLength, String stopReason, int seed, List<AiFilter> aiFilter) {}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -63,20 +64,17 @@ public ChatCompletionResponse generateChatCompletion(String content) {
.header(HEADER_X_NCP_CLOVASTUDIO_API_KEY, apiKey)
.header(HEADER_X_NCP_API_GW_KEY, apiGwKey)
.header(HEADER_X_NCP_CLOVASTUDIO_REQUEST_ID, requestId)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.body(requestBody)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, (request, response) -> {
throw new RestClientException(RestClientUseCase.HYPER_CLOVA, "잘못된 하이퍼클로바 요청", HttpStatus.BAD_REQUEST);
})
.onStatus(HttpStatusCode::is5xxServerError, (request, response) -> {

System.out.println(response.getBody());
System.out.println(response.getHeaders());
throw new RestClientException(RestClientUseCase.HYPER_CLOVA, "하이퍼 클로바 서버 에러", HttpStatus.INTERNAL_SERVER_ERROR);
})
.body(ChatCompletionResponse.class);
.toEntity(ChatCompletionResponse.class)
.getBody();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site.offload.external.hyperclova;

public record Message(String role, String content) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package site.offload.external.hyperclova;

import java.util.List;

public record Result(Message message, String stopReason, int inputLength, int outputLength, List<AiFilter> aiFilter) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package site.offload.external.hyperclova;

public record Status(
String code,
String message
) {
}

0 comments on commit bbaa71b

Please sign in to comment.