diff --git a/01-chat-models/chat-models-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java b/01-chat-models/chat-models-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java index c1ee1b0..671cf31 100644 --- a/01-chat-models/chat-models-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java +++ b/01-chat-models/chat-models-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java @@ -16,7 +16,7 @@ class ChatController { @GetMapping("/ai/chat") String chat(@RequestParam(defaultValue = "What did Gandalf say to the Balrog?") String message) { - return chatClient.generate(message); + return chatClient.call(message); } } diff --git a/01-chat-models/chat-models-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java b/01-chat-models/chat-models-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java index c1ee1b0..671cf31 100644 --- a/01-chat-models/chat-models-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java +++ b/01-chat-models/chat-models-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java @@ -16,7 +16,7 @@ class ChatController { @GetMapping("/ai/chat") String chat(@RequestParam(defaultValue = "What did Gandalf say to the Balrog?") String message) { - return chatClient.generate(message); + return chatClient.call(message); } } diff --git a/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java b/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java index 1fd8433..a781804 100644 --- a/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java +++ b/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java @@ -21,7 +21,7 @@ String chatWithText(@RequestBody String input) { @PostMapping("/ai/chat/prompt") String chatWithPrompt(@RequestBody String input) { - return chatService.chatWithPrompt(input).getGeneration().getContent(); + return chatService.chatWithPrompt(input).getResult().getOutput().getContent(); } @PostMapping("/ai/chat/full") diff --git a/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index b2c6de8..e5fadee 100644 --- a/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-basics-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -2,7 +2,7 @@ import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatResponse; -import org.springframework.ai.prompt.Prompt; +import org.springframework.ai.chat.prompt.Prompt; import org.springframework.stereotype.Service; @Service @@ -15,11 +15,11 @@ class ChatService { } String chatWithText(String message) { - return chatClient.generate(message); + return chatClient.call(message); } ChatResponse chatWithPrompt(String message) { - return chatClient.generate(new Prompt(message)); + return chatClient.call(new Prompt(message)); } } diff --git a/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java b/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java index 1fd8433..a781804 100644 --- a/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java +++ b/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java @@ -21,7 +21,7 @@ String chatWithText(@RequestBody String input) { @PostMapping("/ai/chat/prompt") String chatWithPrompt(@RequestBody String input) { - return chatService.chatWithPrompt(input).getGeneration().getContent(); + return chatService.chatWithPrompt(input).getResult().getOutput().getContent(); } @PostMapping("/ai/chat/full") diff --git a/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java index b2c6de8..e5fadee 100644 --- a/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-basics-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -2,7 +2,7 @@ import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatResponse; -import org.springframework.ai.prompt.Prompt; +import org.springframework.ai.chat.prompt.Prompt; import org.springframework.stereotype.Service; @Service @@ -15,11 +15,11 @@ class ChatService { } String chatWithText(String message) { - return chatClient.generate(message); + return chatClient.call(message); } ChatResponse chatWithPrompt(String message) { - return chatClient.generate(new Prompt(message)); + return chatClient.call(new Prompt(message)); } } diff --git a/02-prompts/prompts-messages-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-messages-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 0e56cd3..b0ec5e9 100644 --- a/02-prompts/prompts-messages-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-messages-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,10 +1,10 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.messages.AssistantMessage; -import org.springframework.ai.prompt.messages.SystemMessage; -import org.springframework.ai.prompt.messages.UserMessage; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.messages.SystemMessage; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.chat.prompt.Prompt; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; @@ -26,8 +26,8 @@ class ChatService { AssistantMessage chatWithSingleMessage(String message) { var userMessage = new UserMessage(message); var prompt = new Prompt(userMessage); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithMultipleMessages(String message) { @@ -38,16 +38,16 @@ AssistantMessage chatWithMultipleMessages(String message) { """); var userMessage = new UserMessage(message); var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithExternalMessage(String message) { var systemMessage = new SystemMessage(systemMessageResource); var userMessage = new UserMessage(message); var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } } diff --git a/02-prompts/prompts-messages-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-messages-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 0e56cd3..b0ec5e9 100644 --- a/02-prompts/prompts-messages-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-messages-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,10 +1,10 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.messages.AssistantMessage; -import org.springframework.ai.prompt.messages.SystemMessage; -import org.springframework.ai.prompt.messages.UserMessage; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.messages.SystemMessage; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.chat.prompt.Prompt; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; @@ -26,8 +26,8 @@ class ChatService { AssistantMessage chatWithSingleMessage(String message) { var userMessage = new UserMessage(message); var prompt = new Prompt(userMessage); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithMultipleMessages(String message) { @@ -38,16 +38,16 @@ AssistantMessage chatWithMultipleMessages(String message) { """); var userMessage = new UserMessage(message); var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithExternalMessage(String message) { var systemMessage = new SystemMessage(systemMessageResource); var userMessage = new UserMessage(message); var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } } diff --git a/02-prompts/prompts-templates-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-templates-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 8a2773d..9d9056c 100644 --- a/02-prompts/prompts-templates-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-templates-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,11 +1,11 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.PromptTemplate; -import org.springframework.ai.prompt.SystemPromptTemplate; -import org.springframework.ai.prompt.messages.AssistantMessage; -import org.springframework.ai.prompt.messages.UserMessage; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.PromptTemplate; +import org.springframework.ai.chat.prompt.SystemPromptTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; @@ -35,8 +35,8 @@ AssistantMessage chatWithUserMessageTemplate(MusicQuestion question) { var userMessage = userPromptTemplate.createMessage(model); var prompt = new Prompt(userMessage); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithSystemMessageTemplate(String message) { @@ -50,8 +50,8 @@ AssistantMessage chatWithSystemMessageTemplate(String message) { var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithSystemMessageTemplateExternal(String message) { @@ -63,8 +63,8 @@ AssistantMessage chatWithSystemMessageTemplateExternal(String message) { var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } private String randomGreeting() { diff --git a/02-prompts/prompts-templates-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/02-prompts/prompts-templates-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 8a2773d..9d9056c 100644 --- a/02-prompts/prompts-templates-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/02-prompts/prompts-templates-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,11 +1,11 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.PromptTemplate; -import org.springframework.ai.prompt.SystemPromptTemplate; -import org.springframework.ai.prompt.messages.AssistantMessage; -import org.springframework.ai.prompt.messages.UserMessage; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.PromptTemplate; +import org.springframework.ai.chat.prompt.SystemPromptTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; @@ -35,8 +35,8 @@ AssistantMessage chatWithUserMessageTemplate(MusicQuestion question) { var userMessage = userPromptTemplate.createMessage(model); var prompt = new Prompt(userMessage); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithSystemMessageTemplate(String message) { @@ -50,8 +50,8 @@ AssistantMessage chatWithSystemMessageTemplate(String message) { var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } AssistantMessage chatWithSystemMessageTemplateExternal(String message) { @@ -63,8 +63,8 @@ AssistantMessage chatWithSystemMessageTemplateExternal(String message) { var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } private String randomGreeting() { diff --git a/03-output-parsers/output-parsers-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/03-output-parsers/output-parsers-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 0b1d7bf..52bcb1d 100644 --- a/03-output-parsers/output-parsers-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/03-output-parsers/output-parsers-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,10 +1,10 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.prompt.PromptTemplate; import org.springframework.ai.parser.BeanOutputParser; import org.springframework.ai.parser.ListOutputParser; import org.springframework.ai.parser.MapOutputParser; -import org.springframework.ai.prompt.PromptTemplate; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.stereotype.Service; @@ -31,8 +31,8 @@ ArtistInfo chatWithBeanOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } Map chatWithMapOutput(MusicQuestion question) { @@ -46,8 +46,8 @@ Map chatWithMapOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } List chatWithListOutput(MusicQuestion question) { @@ -61,8 +61,8 @@ List chatWithListOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } } diff --git a/03-output-parsers/output-parsers-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/03-output-parsers/output-parsers-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 0b1d7bf..52bcb1d 100644 --- a/03-output-parsers/output-parsers-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/03-output-parsers/output-parsers-openai/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,10 +1,10 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.prompt.PromptTemplate; import org.springframework.ai.parser.BeanOutputParser; import org.springframework.ai.parser.ListOutputParser; import org.springframework.ai.parser.MapOutputParser; -import org.springframework.ai.prompt.PromptTemplate; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.stereotype.Service; @@ -31,8 +31,8 @@ ArtistInfo chatWithBeanOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } Map chatWithMapOutput(MusicQuestion question) { @@ -46,8 +46,8 @@ Map chatWithMapOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } List chatWithListOutput(MusicQuestion question) { @@ -61,8 +61,8 @@ List chatWithListOutput(MusicQuestion question) { Map model = Map.of("instrument", question.instrument(), "genre", question.genre(), "format", outputParser.getFormat()); var prompt = userPromptTemplate.create(model); - var chatResponse = chatClient.generate(prompt); - return outputParser.parse(chatResponse.getGeneration().getContent()); + var chatResponse = chatClient.call(prompt); + return outputParser.parse(chatResponse.getResult().getOutput().getContent()); } } diff --git a/05-document-readers/document-readers-json-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/05-document-readers/document-readers-json-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 955cbfe..a86b2b3 100644 --- a/05-document-readers/document-readers-json-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/05-document-readers/document-readers-json-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,11 +1,11 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.SystemPromptTemplate; import org.springframework.ai.document.Document; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.SystemPromptTemplate; -import org.springframework.ai.prompt.messages.AssistantMessage; -import org.springframework.ai.prompt.messages.UserMessage; import org.springframework.ai.vectorstore.SearchRequest; import org.springframework.ai.vectorstore.SimpleVectorStore; import org.springframework.stereotype.Service; @@ -38,7 +38,7 @@ AssistantMessage chatWithDocument(String message) { """); List similarDocuments = vectorStore.similaritySearch(SearchRequest.query(message).withTopK(2)); - String documents = similarDocuments.stream().map(Document::getContent).collect(Collectors.joining("\n")); + String documents = similarDocuments.stream().map(Document::getContent).collect(Collectors.joining(System.lineSeparator())); Map model = Map.of("documents", documents); var systemMessage = systemPromptTemplate.createMessage(model); @@ -47,8 +47,8 @@ AssistantMessage chatWithDocument(String message) { var prompt = new Prompt(List.of(systemMessage, userMessage)); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } } diff --git a/05-document-readers/document-readers-text-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java b/05-document-readers/document-readers-text-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java index 4f5b16c..ae54894 100644 --- a/05-document-readers/document-readers-text-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java +++ b/05-document-readers/document-readers-text-ollama/src/main/java/com/thomasvitale/ai/spring/ChatService.java @@ -1,10 +1,10 @@ package com.thomasvitale.ai.spring; import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.messages.AssistantMessage; +import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.PromptTemplate; import org.springframework.ai.document.Document; -import org.springframework.ai.prompt.Prompt; -import org.springframework.ai.prompt.PromptTemplate; -import org.springframework.ai.prompt.messages.AssistantMessage; import org.springframework.ai.vectorstore.SearchRequest; import org.springframework.ai.vectorstore.SimpleVectorStore; import org.springframework.stereotype.Service; @@ -39,15 +39,15 @@ Given the context information and no prior knowledge, answer the question (QUEST """); List similarDocuments = vectorStore.similaritySearch(SearchRequest.query(message).withTopK(2)); - String documents = similarDocuments.stream().map(Document::getContent).collect(Collectors.joining("\n")); + String documents = similarDocuments.stream().map(Document::getContent).collect(Collectors.joining(System.lineSeparator())); Map model = Map.of("documents", documents, "question", message); var userMessage = promptTemplate.createMessage(model); var prompt = new Prompt(userMessage); - var chatResponse = chatClient.generate(prompt); - return new AssistantMessage(chatResponse.getGeneration().getContent(), chatResponse.getGeneration().getProperties()); + var chatResponse = chatClient.call(prompt); + return chatResponse.getResult().getOutput(); } }