diff --git a/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/openapi/controller/ChatController.java b/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/openapi/controller/ChatController.java index 4cd65580dc..129d233582 100644 --- a/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/openapi/controller/ChatController.java +++ b/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/openapi/controller/ChatController.java @@ -23,12 +23,17 @@ public class ChatController { @Value("${openai.api.url}") private String apiUrl; + /** + * Creates a chat request and sends it to the OpenAI API + * Returns the first message from the API response + * + * @param prompt the prompt to send to the API + * @return first message from the API response + */ @GetMapping("/chat") public String chat(@RequestParam String prompt) { - // create a request ChatRequest request = new ChatRequest(model, prompt); - // call the API ChatResponse response = restTemplate.postForObject( apiUrl, request, @@ -38,7 +43,6 @@ public class ChatController { return "No response"; } - // return the first response return response.getChoices().get(0).getMessage().getContent(); } } \ No newline at end of file