diff --git a/advisors/spring-ai-advisors-vector-store/src/test/java/org/springframework/ai/chat/client/advisor/vectorstore/QuestionAnswerAdvisorTests.java b/advisors/spring-ai-advisors-vector-store/src/test/java/org/springframework/ai/chat/client/advisor/vectorstore/QuestionAnswerAdvisorTests.java index ab6d42c52..79f7a9a14 100644 --- a/advisors/spring-ai-advisors-vector-store/src/test/java/org/springframework/ai/chat/client/advisor/vectorstore/QuestionAnswerAdvisorTests.java +++ b/advisors/spring-ai-advisors-vector-store/src/test/java/org/springframework/ai/chat/client/advisor/vectorstore/QuestionAnswerAdvisorTests.java @@ -218,7 +218,7 @@ public class QuestionAnswerAdvisorTests { var qaAdvisor = new QuestionAnswerAdvisor(this.vectorStore, SearchRequest.builder().build()); var userTextTemplate = "Please answer my question {question}"; - var userPromptTemplate = new PromptTemplate(userTextTemplate, Map.of("question", "XYZ")); + var userPromptTemplate = PromptTemplate.builder().template(userTextTemplate).variables(Map.of("question", "XYZ")).build(); var userMessage = userPromptTemplate.createMessage(); // @formatter:off chatClient.prompt(new Prompt(userMessage)) diff --git a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelIT.java b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelIT.java index e404187f6..8d5d7324d 100644 --- a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelIT.java +++ b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelIT.java @@ -154,8 +154,10 @@ class AnthropicChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -172,8 +174,11 @@ class AnthropicChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -192,7 +197,10 @@ class AnthropicChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -212,7 +220,10 @@ class AnthropicChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.streamingChatModel.stream(prompt) diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java index 83713cd4a..1c8fb392d 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java @@ -137,8 +137,10 @@ class AzureOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -156,8 +158,11 @@ class AzureOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -176,7 +181,10 @@ class AzureOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -194,7 +202,10 @@ class AzureOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -214,7 +225,10 @@ class AzureOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModelIT.java b/models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModelIT.java index 86ef360e2..592c27128 100644 --- a/models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModelIT.java +++ b/models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModelIT.java @@ -152,8 +152,10 @@ class BedrockProxyChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -170,8 +172,11 @@ class BedrockProxyChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -190,7 +195,10 @@ class BedrockProxyChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -210,7 +218,10 @@ class BedrockProxyChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.streamingChatModel.stream(prompt) diff --git a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatModelIT.java b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatModelIT.java index 0f493bec7..4445706a8 100644 --- a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatModelIT.java +++ b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatModelIT.java @@ -127,8 +127,10 @@ class MistralAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -145,8 +147,11 @@ class MistralAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -165,7 +170,10 @@ class MistralAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -185,7 +193,10 @@ class MistralAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.streamingChatModel.stream(prompt) diff --git a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatModelIT.java b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatModelIT.java index 276f429a7..09be0f726 100644 --- a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatModelIT.java +++ b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatModelIT.java @@ -163,8 +163,10 @@ class OllamaChatModelIT extends BaseOllamaIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors.", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors.", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -182,7 +184,10 @@ class OllamaChatModelIT extends BaseOllamaIT { Example: R -> Red. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -203,7 +208,10 @@ class OllamaChatModelIT extends BaseOllamaIT { Consider the filmography of Tom Hanks and tell me 5 of his movies. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -221,7 +229,10 @@ class OllamaChatModelIT extends BaseOllamaIT { Consider the filmography of Tom Hanks and tell me 5 of his movies. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java index 241bb8849..35d34163c 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java @@ -246,8 +246,10 @@ public class OpenAiChatModelIT extends AbstractIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -265,8 +267,10 @@ public class OpenAiChatModelIT extends AbstractIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -285,7 +289,10 @@ public class OpenAiChatModelIT extends AbstractIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -302,7 +309,10 @@ public class OpenAiChatModelIT extends AbstractIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -322,7 +332,10 @@ public class OpenAiChatModelIT extends AbstractIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.streamingChatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelTypeReferenceBeanOutputConverterIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelTypeReferenceBeanOutputConverterIT.java index 1831095ab..239b281f3 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelTypeReferenceBeanOutputConverterIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelTypeReferenceBeanOutputConverterIT.java @@ -58,7 +58,10 @@ class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT { Generate the filmography of 5 movies for Tom Hanks and Bill Murray. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -84,7 +87,10 @@ class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT { Generate the filmography of 5 movies for Tom Hanks and Bill Murray. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.streamingChatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DeepSeekWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DeepSeekWithOpenAiChatModelIT.java index ff136aa24..8a84d4803 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DeepSeekWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DeepSeekWithOpenAiChatModelIT.java @@ -148,8 +148,10 @@ class DeepSeekWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -167,8 +169,10 @@ class DeepSeekWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -187,7 +191,10 @@ class DeepSeekWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -206,7 +213,10 @@ class DeepSeekWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -228,7 +238,10 @@ class DeepSeekWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DockerModelRunnerWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DockerModelRunnerWithOpenAiChatModelIT.java index d819b61c4..5533e4185 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DockerModelRunnerWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DockerModelRunnerWithOpenAiChatModelIT.java @@ -163,8 +163,10 @@ class DockerModelRunnerWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -182,8 +184,10 @@ class DockerModelRunnerWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -202,7 +206,10 @@ class DockerModelRunnerWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -220,7 +227,10 @@ class DockerModelRunnerWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -240,7 +250,10 @@ class DockerModelRunnerWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/GroqWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/GroqWithOpenAiChatModelIT.java index 1bb39e97a..f40776ad5 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/GroqWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/GroqWithOpenAiChatModelIT.java @@ -145,8 +145,10 @@ class GroqWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -164,8 +166,10 @@ class GroqWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -184,7 +188,10 @@ class GroqWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -202,7 +209,10 @@ class GroqWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -222,7 +232,10 @@ class GroqWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/MistralWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/MistralWithOpenAiChatModelIT.java index 31898265e..742729461 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/MistralWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/MistralWithOpenAiChatModelIT.java @@ -146,8 +146,10 @@ class MistralWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -165,8 +167,10 @@ class MistralWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -185,7 +189,10 @@ class MistralWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -203,7 +210,10 @@ class MistralWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -223,7 +233,10 @@ class MistralWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/NvidiaWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/NvidiaWithOpenAiChatModelIT.java index 499f6d993..a199c33a1 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/NvidiaWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/NvidiaWithOpenAiChatModelIT.java @@ -141,8 +141,10 @@ class NvidiaWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -160,8 +162,10 @@ class NvidiaWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -180,7 +184,10 @@ class NvidiaWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -198,7 +205,10 @@ class NvidiaWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -218,7 +228,10 @@ class NvidiaWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/OllamaWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/OllamaWithOpenAiChatModelIT.java index 33d278bd1..f146abb4c 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/OllamaWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/OllamaWithOpenAiChatModelIT.java @@ -164,8 +164,10 @@ class OllamaWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -183,8 +185,10 @@ class OllamaWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -203,7 +207,10 @@ class OllamaWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -221,7 +228,10 @@ class OllamaWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -241,7 +251,10 @@ class OllamaWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/PerplexityWithOpenAiChatModelIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/PerplexityWithOpenAiChatModelIT.java index 319eda560..a0c47d193 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/PerplexityWithOpenAiChatModelIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/PerplexityWithOpenAiChatModelIT.java @@ -155,8 +155,10 @@ class PerplexityWithOpenAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -173,8 +175,10 @@ class PerplexityWithOpenAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "numbers from 1 to 9 under the key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "numbers from 1 to 9 under the key name 'numbers'", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -192,7 +196,10 @@ class PerplexityWithOpenAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -209,7 +216,10 @@ class PerplexityWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -228,7 +238,10 @@ class PerplexityWithOpenAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/testutils/AbstractIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/testutils/AbstractIT.java index 90a0de6b6..735335609 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/testutils/AbstractIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/testutils/AbstractIT.java @@ -87,8 +87,10 @@ public abstract class AbstractIT { String answer = response.getResult().getOutput().getText(); logger.info("Question: " + question); logger.info("Answer:" + answer); - PromptTemplate userPromptTemplate = new PromptTemplate(this.userEvaluatorResource, - Map.of("question", question, "answer", answer)); + PromptTemplate userPromptTemplate = PromptTemplate.builder() + .resource(this.userEvaluatorResource) + .variables(Map.of("question", question, "answer", answer)) + .build(); SystemMessage systemMessage; if (factBased) { systemMessage = new SystemMessage(this.qaEvaluatorFactBasedAnswerResource); diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java index 89a8a85d1..b48622a1f 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java @@ -149,8 +149,10 @@ class VertexAiGeminiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors.", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors.", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -167,8 +169,11 @@ class VertexAiGeminiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -188,7 +193,10 @@ class VertexAiGeminiChatModelIT { Remove the ```json outer brackets. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -226,7 +234,10 @@ class VertexAiGeminiChatModelIT { Remove the ```json outer brackets. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = this.chatModel.stream(prompt) diff --git a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java index 34dc56a3a..9667ce88a 100644 --- a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java +++ b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java @@ -127,8 +127,10 @@ class ZhiPuAiChatModelIT { List five {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "ice cream flavors", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "ice cream flavors", "format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage(), ChatOptions.builder().build()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -146,8 +148,11 @@ class ZhiPuAiChatModelIT { Provide me a List of {subject} {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, - Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", + format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage(), ChatOptions.builder().build()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -166,7 +171,10 @@ class ZhiPuAiChatModelIT { Generate the filmography for a random actor. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage(), ChatOptions.builder().build()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -183,7 +191,10 @@ class ZhiPuAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage(), ChatOptions.builder().build()); Generation generation = this.chatModel.call(prompt).getResult(); @@ -203,7 +214,10 @@ class ZhiPuAiChatModelIT { Generate the filmography of 5 movies for Tom Hanks. {format} """; - PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template(template) + .variables(Map.of("format", format)) + .build(); Prompt prompt = new Prompt(promptTemplate.createMessage()); String generationTextFromStream = Objects diff --git a/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTemplateTest.java b/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTemplateTest.java index e486690b6..3dbbef5e1 100644 --- a/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTemplateTest.java +++ b/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTemplateTest.java @@ -72,7 +72,7 @@ public class PromptTemplateTest { Map model = new HashMap<>(); model.put("name", "Alice"); model.put("age", 30); - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); ChatOptions chatOptions = ChatOptions.builder().temperature(0.5).maxTokens(100).build(); Prompt prompt = promptTemplate.create(model, chatOptions); @@ -88,7 +88,7 @@ public class PromptTemplateTest { Map initialModel = new HashMap<>(); initialModel.put("name", "Bob"); initialModel.put("color", "blue"); - PromptTemplate promptTemplate = new PromptTemplate(template, initialModel); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(initialModel).build(); Map overriddenModel = new HashMap<>(); overriddenModel.put("color", "red"); @@ -128,7 +128,7 @@ public class PromptTemplateTest { // Create a simple template with placeholders for keys in the generative String template = "This is a {key1}, it is {key2}, and it costs {key3}"; - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); // The expected result after rendering the template with the generative String expected = "This is a value1, it is true, and it costs 100"; @@ -147,7 +147,7 @@ public class PromptTemplateTest { public void testRenderWithHyphen() { Map model = Map.of("key-1", "value1"); String template = "This is a {key-1}"; - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); String expected = "This is a value1"; String result = promptTemplate.render(); @@ -161,7 +161,7 @@ public class PromptTemplateTest { InputStream inputStream = new ByteArrayInputStream( "key1's value is {key1} and key2's value is {key2}".getBytes(Charset.defaultCharset())); Resource resource = new InputStreamResource(inputStream); - PromptTemplate promptTemplate = new PromptTemplate(resource, model); + PromptTemplate promptTemplate = PromptTemplate.builder().resource(resource).variables(model).build(); String expected = "key1's value is value1 and key2's value is true"; String result = promptTemplate.render(); assertEquals(expected, result); @@ -180,7 +180,7 @@ public class PromptTemplateTest { // Create a simple template with placeholders for keys in the generative String template = "{key1}, {key2}, {key3}"; - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().resource(resource).variables(model).build(); // The expected result after rendering the template with the generative String expected = "value1, true, it costs 100"; @@ -199,7 +199,7 @@ public class PromptTemplateTest { // Create a simple template that includes a key not present in the generative String template = "This is a {key2}!"; - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); // Rendering the template with a missing key should throw an exception assertThrows(IllegalStateException.class, promptTemplate::render); diff --git a/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTests.java b/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTests.java index ebec933d2..c3d33608f 100644 --- a/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTests.java +++ b/spring-ai-client-chat/src/test/java/org/springframework/ai/prompt/PromptTests.java @@ -98,7 +98,7 @@ class PromptTests { Map model = new HashMap<>(); model.put("name", "Alice"); model.put("age", 30); - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); ChatOptions chatOptions = ChatOptions.builder().temperature(0.5).maxTokens(100).build(); Prompt prompt = promptTemplate.create(model, chatOptions); @@ -115,7 +115,7 @@ class PromptTests { Map model = new HashMap<>(); model.put("name", "Alice"); model.put("age", 30); - PromptTemplate promptTemplate = new PromptTemplate(template, model); + PromptTemplate promptTemplate = PromptTemplate.builder().template(template).variables(model).build(); ChatOptions chatOptions = ChatOptions.builder().temperature(0.5).maxTokens(100).build(); Prompt prompt = promptTemplate.create(model, chatOptions); diff --git a/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/PromptTemplate.java b/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/PromptTemplate.java index d98f9d248..6cc10e50d 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/PromptTemplate.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/PromptTemplate.java @@ -52,19 +52,11 @@ public class PromptTemplate implements PromptTemplateActions, PromptTemplateMess private static final TemplateRenderer DEFAULT_TEMPLATE_RENDERER = StTemplateRenderer.builder().build(); /** - * @deprecated will become private in the next release. If you're subclassing this - * class, re-consider using the built-in implementation together with the new - * PromptTemplateRenderer interface, designed to give you more flexibility and control - * over the rendering process. + * If you're subclassing this class, re-consider using the built-in implementation + * together with the new PromptTemplateRenderer interface, designed to give you more + * flexibility and control over the rendering process. */ - @Deprecated - protected String template; - - /** - * @deprecated in favor of {@link TemplateRenderer} - */ - @Deprecated - protected TemplateFormat templateFormat = TemplateFormat.ST; + private String template; private final Map variables = new HashMap<>(); @@ -78,22 +70,6 @@ public class PromptTemplate implements PromptTemplateActions, PromptTemplateMess this(template, new HashMap<>(), DEFAULT_TEMPLATE_RENDERER); } - /** - * @deprecated in favor of {@link PromptTemplate#builder()}. - */ - @Deprecated - public PromptTemplate(String template, Map variables) { - this(template, variables, DEFAULT_TEMPLATE_RENDERER); - } - - /** - * @deprecated in fahvor of {@link PromptTemplate#builder()}. - */ - @Deprecated - public PromptTemplate(Resource resource, Map variables) { - this(resource, variables, DEFAULT_TEMPLATE_RENDERER); - } - PromptTemplate(String template, Map variables, TemplateRenderer renderer) { Assert.hasText(template, "template cannot be null or empty"); Assert.notNull(variables, "variables cannot be null"); @@ -130,14 +106,6 @@ public class PromptTemplate implements PromptTemplateActions, PromptTemplateMess return this.template; } - /** - * @deprecated in favor of {@link TemplateRenderer} - */ - @Deprecated - public TemplateFormat getTemplateFormat() { - return this.templateFormat; - } - // From PromptTemplateStringActions. @Override @@ -233,25 +201,6 @@ public class PromptTemplate implements PromptTemplateActions, PromptTemplateMess return Prompt.builder().content(render(additionalVariables)).chatOptions(modelOptions).build(); } - // Compatibility - - /** - * @deprecated in favor of {@link TemplateRenderer}. - */ - @Deprecated - public Set getInputVariables() { - throw new UnsupportedOperationException( - "The template rendering logic is now provided by PromptTemplateRenderer"); - } - - /** - * @deprecated in favor of {@link TemplateRenderer}. - */ - @Deprecated - protected void validate(Map model) { - throw new UnsupportedOperationException("Validation is now provided by the PromptTemplateRenderer"); - } - public Builder mutate() { return new Builder().template(this.template).variables(this.variables).renderer(this.renderer); } diff --git a/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateTests.java b/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateTests.java index 8712d9855..a58290ffe 100644 --- a/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateTests.java +++ b/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateTests.java @@ -77,7 +77,8 @@ class PromptTemplateTests { void createWithNullVariables() { String template = "Hello!"; Map variables = null; - assertThatThrownBy(() -> new PromptTemplate(template, variables)).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> PromptTemplate.builder().template(template).variables(variables).build()) + .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("variables cannot be null"); } @@ -86,7 +87,8 @@ class PromptTemplateTests { String template = "Hello!"; Map variables = new HashMap<>(); variables.put(null, "value"); - assertThatThrownBy(() -> new PromptTemplate(template, variables)).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> PromptTemplate.builder().template(template).variables(variables).build()) + .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("variables keys cannot be null"); } @@ -107,7 +109,7 @@ class PromptTemplateTests { void renderWithVariables() { Map variables = new HashMap<>(); variables.put("name", "Spring AI"); - PromptTemplate promptTemplate = new PromptTemplate("Hello {name}!", variables); + PromptTemplate promptTemplate = PromptTemplate.builder().template("Hello {name}!").variables(variables).build(); assertThat(promptTemplate.render()).isEqualTo("Hello Spring AI!"); } @@ -115,7 +117,10 @@ class PromptTemplateTests { void renderWithAdditionalVariables() { Map variables = new HashMap<>(); variables.put("greeting", "Hello"); - PromptTemplate promptTemplate = new PromptTemplate("{greeting} {name}!", variables); + PromptTemplate promptTemplate = PromptTemplate.builder() + .template("{greeting} {name}!") + .variables(variables) + .build(); Map additionalVariables = new HashMap<>(); additionalVariables.put("name", "Spring AI"); @@ -162,7 +167,7 @@ class PromptTemplateTests { void createPromptWithVariables() { Map variables = new HashMap<>(); variables.put("name", "Spring AI"); - PromptTemplate promptTemplate = new PromptTemplate("Hello {name}!", variables); + PromptTemplate promptTemplate = PromptTemplate.builder().template("Hello {name}!").variables(variables).build(); Prompt prompt = promptTemplate.create(variables); assertThat(prompt.getContents()).isEqualTo("Hello Spring AI!"); } diff --git a/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BasicEvaluationTest.java b/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BasicEvaluationTest.java index 69e50493c..ee4bc35fd 100644 --- a/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BasicEvaluationTest.java +++ b/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BasicEvaluationTest.java @@ -58,8 +58,10 @@ public class BasicEvaluationTest { assertThat(answer).isNotNull(); logger.info("Question: " + question); logger.info("Answer:" + answer); - PromptTemplate userPromptTemplate = new PromptTemplate(this.userEvaluatorResource, - Map.of("question", question, "answer", answer)); + PromptTemplate userPromptTemplate = PromptTemplate.builder() + .resource(this.userEvaluatorResource) + .variables(Map.of("question", question, "answer", answer)) + .build(); SystemMessage systemMessage; if (factBased) { systemMessage = new SystemMessage(this.qaEvaluatorFactBasedAnswerResource);