diff --git a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/spring/OpenAiChatModelTest.java b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/spring/OpenAiChatModelTest.java index 03b38616f..72ee11c47 100644 --- a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/spring/OpenAiChatModelTest.java +++ b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/spring/OpenAiChatModelTest.java @@ -39,6 +39,7 @@ import org.mockito.Mockito; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.messages.AssistantMessage.ToolCall; @@ -225,8 +226,14 @@ void testChatMemory() throws IOException { val prompt1 = new Prompt("What is the capital of France?"); val prompt2 = new Prompt("And what is the typical food there?"); - cl.prompt(prompt1).call().content(); - cl.prompt(prompt2).call().content(); + cl.prompt(prompt1) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "test-conversation")) + .call() + .content(); + cl.prompt(prompt2) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "test-conversation")) + .call() + .content(); // The response is not important // We just want to verify that the second call remembered the first call try (var requestInputStream = fileLoader.apply("chatMemory.json")) { diff --git a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java index ca16b78a6..2d511f9cf 100644 --- a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java +++ b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java @@ -41,6 +41,7 @@ import org.mockito.Mockito; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.messages.AssistantMessage.ToolCall; @@ -246,8 +247,14 @@ void testChatMemory() throws IOException { val prompt1 = new Prompt("What is the capital of France?", defaultOptions); val prompt2 = new Prompt("And what is the typical food there?", defaultOptions); - cl.prompt(prompt1).call().content(); - cl.prompt(prompt2).call().content(); + cl.prompt(prompt1) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "test-conversation")) + .call() + .content(); + cl.prompt(prompt2) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "test-conversation")) + .call() + .content(); // The response is not important // We just want to verify that the second call remembered the first call try (var requestInputStream = fileLoader.apply("chatMemory.json")) { diff --git a/pom.xml b/pom.xml index 51776df3d..ec32f7a90 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ 13.4.2 2.1.3 3.5.5 - 1.1.5 + 1.1.6 3.8.5 3.2.0 5.23.0 diff --git a/sample-code/spring-app/pom.xml b/sample-code/spring-app/pom.xml index 856941c9a..8bdb09b64 100644 --- a/sample-code/spring-app/pom.xml +++ b/sample-code/spring-app/pom.xml @@ -59,6 +59,12 @@ tomcat-embed-websocket ${apache-tomcat-embed.version} + + + io.modelcontextprotocol.sdk + mcp-core + ${mcp-core.version} + org.junit diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/PromptRegistryController.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/PromptRegistryController.java index a75c5f793..c711be82b 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/PromptRegistryController.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/PromptRegistryController.java @@ -32,6 +32,7 @@ import lombok.val; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.messages.Message; @@ -147,7 +148,11 @@ Generation promptRegistryToSpringAi() { final List messages = SpringAiConverter.promptTemplateToMessages(promptResponse); val prompt = new Prompt(messages); - val response = cl.prompt(prompt).call().chatResponse(); + val response = + cl.prompt(prompt) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .chatResponse(); return response != null ? response.getResult() : null; } diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiAgenticWorkflowService.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiAgenticWorkflowService.java index 35694bd48..9cb0fd3d7 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiAgenticWorkflowService.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiAgenticWorkflowService.java @@ -12,6 +12,7 @@ import lombok.val; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.model.ChatModel; @@ -68,7 +69,12 @@ public ChatResponse runAgent(@Nonnull final String userInput) { // Make a call to the LLM with the new input response = - Objects.requireNonNull(cl.prompt(prompt).call().chatResponse(), "Chat response is null."); + Objects.requireNonNull( + cl.prompt(prompt) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .chatResponse(), + "Chat response is null."); responseText = response.getResult().getOutput().getText(); } diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOpenAiService.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOpenAiService.java index aaf89d798..48796e833 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOpenAiService.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOpenAiService.java @@ -10,6 +10,7 @@ import lombok.val; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.model.ChatModel; @@ -112,8 +113,15 @@ public ChatResponse chatMemory() { val prompt1 = new Prompt("What is the capital of France?"); val prompt2 = new Prompt("And what is the typical food there?"); - cl.prompt(prompt1).call().content(); + cl.prompt(prompt1) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .content(); return Objects.requireNonNull( - cl.prompt(prompt2).call().chatResponse(), "Chat response is null"); + cl.prompt(prompt2) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .chatResponse(), + "Chat response is null"); } } diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java index 6cdfc2e20..207cd6488 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java @@ -23,6 +23,7 @@ import lombok.val; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; +import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; import org.springframework.ai.chat.memory.MessageWindowChatMemory; import org.springframework.ai.chat.messages.SystemMessage; @@ -234,9 +235,16 @@ public ChatResponse chatMemory() { val prompt1 = new Prompt("What is the capital of France?", defaultOptions); val prompt2 = new Prompt("And what is the typical food there?", defaultOptions); - cl.prompt(prompt1).call().content(); + cl.prompt(prompt1) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .content(); return Objects.requireNonNull( - cl.prompt(prompt2).call().chatResponse(), "Chat response is null"); + cl.prompt(prompt2) + .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, "conversation id")) + .call() + .chatResponse(), + "Chat response is null"); } /**