|
@@ -3,6 +3,7 @@ package com.sxtvs.api.chatgpt.controller;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.sxtvs.api.chatgpt.dto.CompletionsParamsDto;
|
|
|
import com.sxtvs.api.chatgpt.dto.CompletionsRequestDto;
|
|
|
+import com.sxtvs.api.chatgpt.dto.CompletionsResponseDto;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.apache.hc.client5.http.fluent.Request;
|
|
|
import org.apache.hc.core5.http.ContentType;
|
|
@@ -19,7 +20,7 @@ public class ChatGptController {
|
|
|
|
|
|
@SneakyThrows
|
|
|
@RequestMapping("completions")
|
|
|
- public String completions(@RequestBody CompletionsRequestDto dto) {
|
|
|
+ public CompletionsResponseDto completions(@RequestBody CompletionsRequestDto dto) {
|
|
|
var paramsDto = new CompletionsParamsDto(dto.getPrompt());
|
|
|
var response = Request.post("https://api.openai.com/v1/completions")
|
|
|
.setHeader("Authorization", "Bearer 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")
|
|
@@ -27,7 +28,9 @@ public class ChatGptController {
|
|
|
.execute()
|
|
|
.returnContent()
|
|
|
.toString();
|
|
|
- return response;
|
|
|
+ var completionsResponseDto = new CompletionsResponseDto();
|
|
|
+ completionsResponseDto.setResult(response);
|
|
|
+ return completionsResponseDto;
|
|
|
}
|
|
|
|
|
|
}
|