/v1/chat/completions
gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301
/v1/completions
text-davinci-003, text-davinci-002, text-curie-001, text-babbage-001, text-ada-001
/v1/edits
text-davinci-edit-001, code-davinci-edit-001
/v1/audio/transcriptions
whisper-1
/v1/audio/translations
whisper-1
/v1/fine-tunes
davinci, curie, babbage, ada
/v1/embeddings
text-embedding-ada-002, text-search-ada-doc-001
/v1/moderations
text-moderation-stable, text-moderation-latest
모델 종류 정보: https://platform.openai.com/docs/models/gpt-4
GPT-3.5
https://platform.openai.com/docs/api-reference/chat
gpt-3.5-turbo
URL: https://api.openai.com/v1/chat/completions
헤더: "Content-Type: application/json"
헤더: "Authorization: Bearer $OPENAI_API_KEY"
//Request(body)
{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}
//Response
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
:https://platform.openai.com/docs/api-reference/completions
text-davinci-edit-001
URL: https://api.openai.com/v1/edits
헤더: "Content-Type: application/json"
헤더: "Authorization: Bearer $OPENAI_API_KEY"
//Request(body)
{
"model": "text-davinci-edit-001",
"input": "What day of the wek is it?",
"instruction": "Fix the spelling mistakes",
}
//Response
{
"object": "edit",
"created": 1589478378,
"choices": [
{
"text": "What day of the week is it?",
"index": 0,
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 32,
"total_tokens": 57
}
}
RestTemplate를 이용하여 통신
https://velog.io/@seongwon97/Spring-Boot-Rest-Template
public HttpEntity<GptRequestDto> buildHttpEntity(GptRequestDto requestDto) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType(GptConfig.MEDIA_TYPE));
headers.add(GptConfig.AUTHORIZATION, GptConfig.BEARER + gptConfig.getApiKey());
return new HttpEntity<>(requestDto, headers);
}
public GptResponseDto getResponse(HttpEntity<GptRequestDto> chatGptRequestDtoHttpEntity) {
ResponseEntity<GptResponseDto> responseEntity = restTemplate.postForEntity(
GptConfig.CHAT_URL,
chatGptRequestDtoHttpEntity,
GptResponseDto.class);
return responseEntity.getBody();
}
public ResponseDto<AnswerResponseDto> askQuestion(QuestionRequestDto requestDto) {
//모델 종류 설정
GptConfig.setMODEL(GptConfig.CHAT_MODEL);
List<Messages> messages = new ArrayList<>();
messages.add(new Messages(requestDto.getQuestion()+" 어울리는 노래 추천 좀 해줘", "user"));
GptResponseDto gptResponseDto = this.getResponse(this.buildHttpEntity(new GptRequestDto(GptConfig.MODEL, messages)));
List<Choice> choices = gptResponseDto.getChoices();
StringBuilder answer = new StringBuilder();
for (Choice ch : choices) { answer.append(ch.getMessage().getContent());}
return ResponseDto.setSuccess("success", new
}
https://tecoble.techcourse.co.kr/post/2022-10-11-server-sent-events/
https://jsonobject.tistory.com/558