diff --git a/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatOptions.java b/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatOptions.java index 7cd7bdb23..025fae9c5 100644 --- a/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatOptions.java +++ b/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatOptions.java @@ -51,11 +51,11 @@ public class AnthropicChatOptions implements ChatOptions, FunctionCallingOptions private @JsonProperty("top_k") Integer topK; /** - * Tool Function Callbacks to register with the ChatClient. For Prompt + * Tool Function Callbacks to register with the ModelCall. For Prompt * Options the functionCallbacks are automatically enabled for the duration of the * prompt execution. For Default Options the functionCallbacks are registered but * disabled by default. Use the enableFunctions to set the functions from the registry - * to be used by the ChatClient chat completion requests. + * to be used by the ModelCall chat completion requests. */ @NestedConfigurationProperty @JsonIgnore diff --git a/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatClient.java b/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicModelCall.java similarity index 95% rename from models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatClient.java rename to models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicModelCall.java index 0f9bcbf44..02f48720a 100644 --- a/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatClient.java +++ b/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicModelCall.java @@ -26,6 +26,7 @@ import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.ai.chat.ModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.anthropic.api.AnthropicApi; @@ -38,7 +39,6 @@ import org.springframework.ai.anthropic.api.AnthropicApi.Role; import org.springframework.ai.anthropic.api.AnthropicApi.StreamResponse; import org.springframework.ai.anthropic.api.AnthropicApi.Usage; import org.springframework.ai.anthropic.metadata.AnthropicChatResponseMetadata; -import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -56,16 +56,16 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** - * The {@link ChatClient} implementation for the Anthropic service. + * The {@link ModelCall} implementation for the Anthropic service. * * @author Christian Tzolov * @since 1.0.0 */ -public class AnthropicChatClient extends +public class AnthropicModelCall extends AbstractFunctionCallSupport> - implements ChatClient, StreamingChatClient { + implements ModelCall, StreamingChatClient { - private static final Logger logger = LoggerFactory.getLogger(AnthropicChatClient.class); + private static final Logger logger = LoggerFactory.getLogger(AnthropicModelCall.class); public static final String DEFAULT_MODEL_NAME = AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue(); @@ -89,10 +89,10 @@ public class AnthropicChatClient extends public final RetryTemplate retryTemplate; /** - * Construct a new {@link AnthropicChatClient} instance. + * Construct a new {@link AnthropicModelCall} instance. * @param anthropicApi the lower-level API for the Anthropic service. */ - public AnthropicChatClient(AnthropicApi anthropicApi) { + public AnthropicModelCall(AnthropicApi anthropicApi) { this(anthropicApi, AnthropicChatOptions.builder() .withModel(DEFAULT_MODEL_NAME) @@ -102,34 +102,34 @@ public class AnthropicChatClient extends } /** - * Construct a new {@link AnthropicChatClient} instance. + * Construct a new {@link AnthropicModelCall} instance. * @param anthropicApi the lower-level API for the Anthropic service. * @param defaultOptions the default options used for the chat completion requests. */ - public AnthropicChatClient(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions) { + public AnthropicModelCall(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions) { this(anthropicApi, defaultOptions, RetryUtils.DEFAULT_RETRY_TEMPLATE); } /** - * Construct a new {@link AnthropicChatClient} instance. + * Construct a new {@link AnthropicModelCall} instance. * @param anthropicApi the lower-level API for the Anthropic service. * @param defaultOptions the default options used for the chat completion requests. * @param retryTemplate the retry template used to retry the Anthropic API calls. */ - public AnthropicChatClient(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, + public AnthropicModelCall(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, RetryTemplate retryTemplate) { this(anthropicApi, defaultOptions, retryTemplate, null); } /** - * Construct a new {@link AnthropicChatClient} instance. + * Construct a new {@link AnthropicModelCall} instance. * @param anthropicApi the lower-level API for the Anthropic service. * @param defaultOptions the default options used for the chat completion requests. * @param retryTemplate the retry template used to retry the Anthropic API calls. * @param functionCallbackContext the function callback context used to store the * state of the function calls. */ - public AnthropicChatClient(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, + public AnthropicModelCall(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext) { super(functionCallbackContext); diff --git a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatClientIT.java b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicModelCallIT.java similarity index 93% rename from models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatClientIT.java rename to models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicModelCallIT.java index ce5b45d37..60e663143 100644 --- a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatClientIT.java +++ b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicModelCallIT.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import org.springframework.ai.anthropic.api.AnthropicApi; import org.springframework.ai.anthropic.api.tool.MockWeatherService; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -56,12 +56,12 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = AnthropicTestConfiguration.class, properties = "spring.ai.retry.on-http-codes=429") @EnabledIfEnvironmentVariable(named = "ANTHROPIC_API_KEY", matches = ".+") -class AnthropicChatClientIT { +class AnthropicModelCallIT { - private static final Logger logger = LoggerFactory.getLogger(AnthropicChatClientIT.class); + private static final Logger logger = LoggerFactory.getLogger(AnthropicModelCallIT.class); @Autowired - protected ChatClient chatClient; + protected ModelCall modelCall; @Autowired protected StreamingChatClient streamingChatClient; @@ -76,7 +76,7 @@ class AnthropicChatClientIT { SystemPromptTemplate systemPromptTemplate = new SystemPromptTemplate(systemResource); Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", "Bob", "voice", "pirate")); Prompt prompt = new Prompt(List.of(userMessage, systemMessage)); - ChatResponse response = chatClient.call(prompt); + ChatResponse response = modelCall.call(prompt); assertThat(response.getResults()).hasSize(1); assertThat(response.getMetadata().getUsage().getGenerationTokens()).isGreaterThan(0); assertThat(response.getMetadata().getUsage().getPromptTokens()).isGreaterThan(0); @@ -102,7 +102,7 @@ class AnthropicChatClientIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "ice cream flavors", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = this.chatClient.call(prompt).getResult(); + Generation generation = this.modelCall.call(prompt).getResult(); List list = listOutputConverter.convert(generation.getOutput().getContent()); assertThat(list).hasSize(5); @@ -120,7 +120,7 @@ class AnthropicChatClientIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); Map result = mapOutputConverter.convert(generation.getOutput().getContent()); assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); @@ -142,7 +142,7 @@ class AnthropicChatClientIT { """; PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); ActorsFilmsRecord actorsFilms = beanOutputConverter.convert(generation.getOutput().getContent()); logger.info("" + actorsFilms); @@ -187,7 +187,7 @@ class AnthropicChatClientIT { var userMessage = new UserMessage("Explain what do you see on this picture?", List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData))); - var response = chatClient.call(new Prompt(List.of(userMessage))); + var response = modelCall.call(new Prompt(List.of(userMessage))); logger.info(response.getResult().getOutput().getContent()); assertThat(response.getResult().getOutput().getContent()).contains("bananas", "apple", "basket"); @@ -209,7 +209,7 @@ class AnthropicChatClientIT { .build())) .build(); - ChatResponse response = chatClient.call(new Prompt(messages, promptOptions)); + ChatResponse response = modelCall.call(new Prompt(messages, promptOptions)); logger.info("Response: {}", response); diff --git a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicTestConfiguration.java b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicTestConfiguration.java index 649fbef1a..7b7923daf 100644 --- a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicTestConfiguration.java +++ b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicTestConfiguration.java @@ -38,8 +38,8 @@ public class AnthropicTestConfiguration { } @Bean - public AnthropicChatClient openAiChatClient(AnthropicApi api) { - AnthropicChatClient anthropicChatClient = new AnthropicChatClient(api); + public AnthropicModelCall openAiChatClient(AnthropicApi api) { + AnthropicModelCall anthropicChatClient = new AnthropicModelCall(api); return anthropicChatClient; } diff --git a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/ChatCompletionRequestTests.java b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/ChatCompletionRequestTests.java index bc777a846..3bf6eaae3 100644 --- a/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/ChatCompletionRequestTests.java +++ b/models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/ChatCompletionRequestTests.java @@ -30,7 +30,7 @@ public class ChatCompletionRequestTests { @Test public void createRequestWithChatOptions() { - var client = new AnthropicChatClient(new AnthropicApi("TEST"), + var client = new AnthropicModelCall(new AnthropicApi("TEST"), AnthropicChatOptions.builder().withModel("DEFAULT_MODEL").withTemperature(66.6f).build()); var request = client.createRequest(new Prompt("Test message content"), false); diff --git a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatOptions.java b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatOptions.java index 681285ecc..c477e3ce6 100644 --- a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatOptions.java +++ b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatOptions.java @@ -127,11 +127,11 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio private String deploymentName; /** - * OpenAI Tool Function Callbacks to register with the ChatClient. For Prompt Options + * OpenAI Tool Function Callbacks to register with the ModelCall. For Prompt Options * the functionCallbacks are automatically enabled for the duration of the prompt * execution. For Default Options the functionCallbacks are registered but disabled by * default. Use the enableFunctions to set the functions from the registry to be used - * by the ChatClient chat completion requests. + * by the ModelCall chat completion requests. */ @NestedConfigurationProperty @JsonIgnore diff --git a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiModelCall.java similarity index 97% rename from models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java rename to models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiModelCall.java index a49a42ff5..5eb8ed2de 100644 --- a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java +++ b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiModelCall.java @@ -38,7 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.azure.openai.metadata.AzureOpenAiChatResponseMetadata; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -63,7 +63,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; /** - * {@link ChatClient} implementation for {@literal Microsoft Azure AI} backed by + * {@link ModelCall} implementation for {@literal Microsoft Azure AI} backed by * {@link OpenAIClient}. * * @author Mark Pollack @@ -71,12 +71,12 @@ import java.util.concurrent.atomic.AtomicBoolean; * @author John Blum * @author Christian Tzolov * @author Grogdunn - * @see ChatClient + * @see ModelCall * @see com.azure.ai.openai.OpenAIClient */ -public class AzureOpenAiChatClient +public class AzureOpenAiModelCall extends AbstractFunctionCallSupport - implements ChatClient, StreamingChatClient { + implements ModelCall, StreamingChatClient { private static final String DEFAULT_DEPLOYMENT_NAME = "gpt-35-turbo"; @@ -94,7 +94,7 @@ public class AzureOpenAiChatClient */ private final OpenAIClient openAIClient; - public AzureOpenAiChatClient(OpenAIClient microsoftOpenAiClient) { + public AzureOpenAiModelCall(OpenAIClient microsoftOpenAiClient) { this(microsoftOpenAiClient, AzureOpenAiChatOptions.builder() .withDeploymentName(DEFAULT_DEPLOYMENT_NAME) @@ -102,11 +102,11 @@ public class AzureOpenAiChatClient .build()); } - public AzureOpenAiChatClient(OpenAIClient microsoftOpenAiClient, AzureOpenAiChatOptions options) { + public AzureOpenAiModelCall(OpenAIClient microsoftOpenAiClient, AzureOpenAiChatOptions options) { this(microsoftOpenAiClient, options, null); } - public AzureOpenAiChatClient(OpenAIClient microsoftOpenAiClient, AzureOpenAiChatOptions options, + public AzureOpenAiModelCall(OpenAIClient microsoftOpenAiClient, AzureOpenAiChatOptions options, FunctionCallbackContext functionCallbackContext) { super(functionCallbackContext); Assert.notNull(microsoftOpenAiClient, "com.azure.ai.openai.OpenAIClient must not be null"); @@ -117,10 +117,10 @@ public class AzureOpenAiChatClient /** * @deprecated since 0.8.0, use - * {@link #AzureOpenAiChatClient(OpenAIClient, AzureOpenAiChatOptions)} instead. + * {@link #AzureOpenAiModelCall(OpenAIClient, AzureOpenAiChatOptions)} instead. */ @Deprecated(forRemoval = true, since = "0.8.0") - public AzureOpenAiChatClient withDefaultOptions(AzureOpenAiChatOptions defaultOptions) { + public AzureOpenAiModelCall withDefaultOptions(AzureOpenAiChatOptions defaultOptions) { Assert.notNull(defaultOptions, "DefaultOptions must not be null"); this.defaultOptions = defaultOptions; return this; diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureChatCompletionsOptionsTests.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureChatCompletionsOptionsTests.java index 1e0ba2939..abe5c81c5 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureChatCompletionsOptionsTests.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureChatCompletionsOptionsTests.java @@ -53,7 +53,7 @@ public class AzureChatCompletionsOptionsTests { .withUser("user") .build(); - var client = new AzureOpenAiChatClient(mockClient, defaultOptions); + var client = new AzureOpenAiModelCall(mockClient, defaultOptions); var requestOptions = client.toAzureChatCompletionsOptions(new Prompt("Test message content")); diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatClientIT.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiModelCallIT.java similarity index 96% rename from models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatClientIT.java rename to models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiModelCallIT.java index 253e13d57..aa66a3266 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatClientIT.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiModelCallIT.java @@ -46,13 +46,13 @@ import org.springframework.core.convert.support.DefaultConversionService; import static org.assertj.core.api.Assertions.assertThat; -@SpringBootTest(classes = AzureOpenAiChatClientIT.TestConfiguration.class) +@SpringBootTest(classes = AzureOpenAiModelCallIT.TestConfiguration.class) @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+") @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+") -class AzureOpenAiChatClientIT { +class AzureOpenAiModelCallIT { @Autowired - private AzureOpenAiChatClient chatClient; + private AzureOpenAiModelCall chatClient; record ActorsFilms(String actor, List movies) { } @@ -194,8 +194,8 @@ class AzureOpenAiChatClientIT { } @Bean - public AzureOpenAiChatClient azureOpenAiChatClient(OpenAIClient openAIClient) { - return new AzureOpenAiChatClient(openAIClient, + public AzureOpenAiModelCall azureOpenAiChatClient(OpenAIClient openAIClient) { + return new AzureOpenAiModelCall(openAIClient, AzureOpenAiChatOptions.builder().withDeploymentName("gpt-35-turbo").withMaxTokens(200).build()); } diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/MockAzureOpenAiTestConfiguration.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/MockAzureOpenAiTestConfiguration.java index f5e7b438a..3f848c095 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/MockAzureOpenAiTestConfiguration.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/MockAzureOpenAiTestConfiguration.java @@ -59,8 +59,8 @@ public class MockAzureOpenAiTestConfiguration { } @Bean - AzureOpenAiChatClient azureOpenAiChatClient(OpenAIClient microsoftAzureOpenAiClient) { - return new AzureOpenAiChatClient(microsoftAzureOpenAiClient); + AzureOpenAiModelCall azureOpenAiChatClient(OpenAIClient microsoftAzureOpenAiClient) { + return new AzureOpenAiModelCall(microsoftAzureOpenAiClient); } } diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatClientFunctionCallIT.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiModelCallFunctionCallIT.java similarity index 92% rename from models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatClientFunctionCallIT.java rename to models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiModelCallFunctionCallIT.java index 08c81ebd1..a5f81ee31 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatClientFunctionCallIT.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiModelCallFunctionCallIT.java @@ -29,7 +29,7 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.AzureOpenAiChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -46,18 +46,18 @@ import reactor.core.publisher.Flux; import static org.assertj.core.api.Assertions.assertThat; -@SpringBootTest(classes = AzureOpenAiChatClientFunctionCallIT.TestConfiguration.class) +@SpringBootTest(classes = AzureOpenAiModelCallFunctionCallIT.TestConfiguration.class) @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+") @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+") -class AzureOpenAiChatClientFunctionCallIT { +class AzureOpenAiModelCallFunctionCallIT { - private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatClientFunctionCallIT.class); + private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiModelCallFunctionCallIT.class); @Autowired private String selectedModel; @Autowired - private AzureOpenAiChatClient chatClient; + private AzureOpenAiModelCall chatClient; @Test void functionCallTest() { @@ -129,8 +129,8 @@ class AzureOpenAiChatClientFunctionCallIT { } @Bean - public AzureOpenAiChatClient azureOpenAiChatClient(OpenAIClient openAIClient, String selectedModel) { - return new AzureOpenAiChatClient(openAIClient, + public AzureOpenAiModelCall azureOpenAiChatClient(OpenAIClient openAIClient, String selectedModel) { + return new AzureOpenAiModelCall(openAIClient, AzureOpenAiChatOptions.builder().withDeploymentName(selectedModel).withMaxTokens(500).build()); } diff --git a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiChatClientMetadataTests.java b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiModelCallMetadataTests.java similarity index 96% rename from models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiChatClientMetadataTests.java rename to models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiModelCallMetadataTests.java index cc938c9b9..821c33a62 100644 --- a/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiChatClientMetadataTests.java +++ b/models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/metadata/AzureOpenAiModelCallMetadataTests.java @@ -23,7 +23,7 @@ import com.azure.ai.openai.models.ContentFilterResultsForChoice; import com.azure.ai.openai.models.ContentFilterSeverity; import org.junit.jupiter.api.Test; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.MockAzureOpenAiTestConfiguration; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -55,7 +55,7 @@ import org.springframework.web.context.request.WebRequest; import static org.assertj.core.api.Assertions.assertThat; /** - * Unit Tests for {@link AzureOpenAiChatClient} asserting AI metadata. + * Unit Tests for {@link AzureOpenAiModelCall} asserting AI metadata. * * @author John Blum * @author Christian Tzolov @@ -63,12 +63,12 @@ import static org.assertj.core.api.Assertions.assertThat; */ @SpringBootTest @ActiveProfiles("spring-ai-azure-openai-mocks") -@ContextConfiguration(classes = AzureOpenAiChatClientMetadataTests.TestConfiguration.class) +@ContextConfiguration(classes = AzureOpenAiModelCallMetadataTests.TestConfiguration.class) @SuppressWarnings("unused") -class AzureOpenAiChatClientMetadataTests { +class AzureOpenAiModelCallMetadataTests { @Autowired - private AzureOpenAiChatClient aiClient; + private AzureOpenAiModelCall aiClient; @Test void azureOpenAiMetadataCapturedDuringGeneration() { diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCall.java similarity index 90% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCall.java index 26b887344..6623bf53e 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCall.java @@ -17,7 +17,7 @@ package org.springframework.ai.bedrock.anthropic; import java.util.List; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.metadata.ChatGenerationMetadata; @@ -33,19 +33,19 @@ import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.ModelOptionsUtils; /** - * Java {@link ChatClient} and {@link StreamingChatClient} for the Bedrock Anthropic chat + * Java {@link ModelCall} and {@link StreamingChatClient} for the Bedrock Anthropic chat * generative. * * @author Christian Tzolov * @since 0.8.0 */ -public class BedrockAnthropicChatClient implements ChatClient, StreamingChatClient { +public class BedrockAnthropicModelCall implements ModelCall, StreamingChatClient { private final AnthropicChatBedrockApi anthropicChatApi; private final AnthropicChatOptions defaultOptions; - public BedrockAnthropicChatClient(AnthropicChatBedrockApi chatApi) { + public BedrockAnthropicModelCall(AnthropicChatBedrockApi chatApi) { this(chatApi, AnthropicChatOptions.builder() .withTemperature(0.8f) @@ -55,7 +55,7 @@ public class BedrockAnthropicChatClient implements ChatClient, StreamingChatClie .build()); } - public BedrockAnthropicChatClient(AnthropicChatBedrockApi chatApi, AnthropicChatOptions options) { + public BedrockAnthropicModelCall(AnthropicChatBedrockApi chatApi, AnthropicChatOptions options) { this.anthropicChatApi = chatApi; this.defaultOptions = options; } diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCall.java similarity index 94% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCall.java index 12dba850c..0a3eada5c 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCall.java @@ -22,7 +22,7 @@ import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.An import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.MediaContent; import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.ChatCompletionMessage; import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.ChatCompletionMessage.Role; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -43,20 +43,20 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** - * Java {@link ChatClient} and {@link StreamingChatClient} for the Bedrock Anthropic chat + * Java {@link ModelCall} and {@link StreamingChatClient} for the Bedrock Anthropic chat * generative. * * @author Ben Middleton * @author Christian Tzolov * @since 1.0.0 */ -public class BedrockAnthropic3ChatClient implements ChatClient, StreamingChatClient { +public class BedrockAnthropic3ModelCall implements ModelCall, StreamingChatClient { private final Anthropic3ChatBedrockApi anthropicChatApi; private final Anthropic3ChatOptions defaultOptions; - public BedrockAnthropic3ChatClient(Anthropic3ChatBedrockApi chatApi) { + public BedrockAnthropic3ModelCall(Anthropic3ChatBedrockApi chatApi) { this(chatApi, Anthropic3ChatOptions.builder() .withTemperature(0.8f) @@ -66,7 +66,7 @@ public class BedrockAnthropic3ChatClient implements ChatClient, StreamingChatCli .build()); } - public BedrockAnthropic3ChatClient(Anthropic3ChatBedrockApi chatApi, Anthropic3ChatOptions options) { + public BedrockAnthropic3ModelCall(Anthropic3ChatBedrockApi chatApi, Anthropic3ChatOptions options) { this.anthropicChatApi = chatApi; this.defaultOptions = options; } diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCall.java similarity index 93% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCall.java index 3ff2b2cee..f5190a6b7 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCall.java @@ -24,7 +24,7 @@ import org.springframework.ai.bedrock.MessageToPromptConverter; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatRequest; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatResponse; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -39,17 +39,17 @@ import org.springframework.util.Assert; * @author Christian Tzolov * @since 0.8.0 */ -public class BedrockCohereChatClient implements ChatClient, StreamingChatClient { +public class BedrockCohereModelCall implements ModelCall, StreamingChatClient { private final CohereChatBedrockApi chatApi; private final BedrockCohereChatOptions defaultOptions; - public BedrockCohereChatClient(CohereChatBedrockApi chatApi) { + public BedrockCohereModelCall(CohereChatBedrockApi chatApi) { this(chatApi, BedrockCohereChatOptions.builder().build()); } - public BedrockCohereChatClient(CohereChatBedrockApi chatApi, BedrockCohereChatOptions options) { + public BedrockCohereModelCall(CohereChatBedrockApi chatApi, BedrockCohereChatOptions options) { Assert.notNull(chatApi, "CohereChatBedrockApi must not be null"); Assert.notNull(options, "BedrockCohereChatOptions must not be null"); diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCall.java similarity index 88% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCall.java index 7a11a2524..ee86bad89 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCall.java @@ -19,7 +19,7 @@ package org.springframework.ai.bedrock.jurassic2; import org.springframework.ai.bedrock.MessageToPromptConverter; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatRequest; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.metadata.ChatGenerationMetadata; @@ -29,19 +29,18 @@ import org.springframework.ai.model.ModelOptionsUtils; import org.springframework.util.Assert; /** - * Java {@link ChatClient} for the Bedrock Jurassic2 chat generative model. + * Java {@link ModelCall} for the Bedrock Jurassic2 chat generative model. * * @author Ahmed Yousri * @since 1.0.0 */ -public class BedrockAi21Jurassic2ChatClient implements ChatClient { +public class BedrockAi21Jurassic2ModelCall implements ModelCall { private final Ai21Jurassic2ChatBedrockApi chatApi; private final BedrockAi21Jurassic2ChatOptions defaultOptions; - public BedrockAi21Jurassic2ChatClient(Ai21Jurassic2ChatBedrockApi chatApi, - BedrockAi21Jurassic2ChatOptions options) { + public BedrockAi21Jurassic2ModelCall(Ai21Jurassic2ChatBedrockApi chatApi, BedrockAi21Jurassic2ChatOptions options) { Assert.notNull(chatApi, "Ai21Jurassic2ChatBedrockApi must not be null"); Assert.notNull(options, "BedrockAi21Jurassic2ChatOptions must not be null"); @@ -49,7 +48,7 @@ public class BedrockAi21Jurassic2ChatClient implements ChatClient { this.defaultOptions = options; } - public BedrockAi21Jurassic2ChatClient(Ai21Jurassic2ChatBedrockApi chatApi) { + public BedrockAi21Jurassic2ModelCall(Ai21Jurassic2ChatBedrockApi chatApi) { this(chatApi, BedrockAi21Jurassic2ChatOptions.builder() .withTemperature(0.8f) @@ -114,8 +113,8 @@ public class BedrockAi21Jurassic2ChatClient implements ChatClient { return this; } - public BedrockAi21Jurassic2ChatClient build() { - return new BedrockAi21Jurassic2ChatClient(chatApi, + public BedrockAi21Jurassic2ModelCall build() { + return new BedrockAi21Jurassic2ModelCall(chatApi, options != null ? options : BedrockAi21Jurassic2ChatOptions.builder().build()); } diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCall.java similarity index 91% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCall.java index c1be58e5a..b1780f4ed 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCall.java @@ -23,7 +23,7 @@ import org.springframework.ai.bedrock.MessageToPromptConverter; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi.LlamaChatRequest; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi.LlamaChatResponse; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -35,25 +35,25 @@ import org.springframework.ai.model.ModelOptionsUtils; import org.springframework.util.Assert; /** - * Java {@link ChatClient} and {@link StreamingChatClient} for the Bedrock Llama chat + * Java {@link ModelCall} and {@link StreamingChatClient} for the Bedrock Llama chat * generative. * * @author Christian Tzolov * @author Wei Jiang * @since 0.8.0 */ -public class BedrockLlamaChatClient implements ChatClient, StreamingChatClient { +public class BedrockLlamaModelCall implements ModelCall, StreamingChatClient { private final LlamaChatBedrockApi chatApi; private final BedrockLlamaChatOptions defaultOptions; - public BedrockLlamaChatClient(LlamaChatBedrockApi chatApi) { + public BedrockLlamaModelCall(LlamaChatBedrockApi chatApi) { this(chatApi, BedrockLlamaChatOptions.builder().withTemperature(0.8f).withTopP(0.9f).withMaxGenLen(100).build()); } - public BedrockLlamaChatClient(LlamaChatBedrockApi chatApi, BedrockLlamaChatOptions options) { + public BedrockLlamaModelCall(LlamaChatBedrockApi chatApi, BedrockLlamaChatOptions options) { Assert.notNull(chatApi, "LlamaChatBedrockApi must not be null"); Assert.notNull(options, "BedrockLlamaChatOptions must not be null"); diff --git a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClient.java b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCall.java similarity index 94% rename from models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClient.java rename to models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCall.java index e77d8277c..0ce4c27e4 100644 --- a/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClient.java +++ b/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCall.java @@ -24,7 +24,7 @@ import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatRequest; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponse; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponseChunk; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -39,17 +39,17 @@ import org.springframework.util.Assert; * @author Christian Tzolov * @since 0.8.0 */ -public class BedrockTitanChatClient implements ChatClient, StreamingChatClient { +public class BedrockTitanModelCall implements ModelCall, StreamingChatClient { private final TitanChatBedrockApi chatApi; private final BedrockTitanChatOptions defaultOptions; - public BedrockTitanChatClient(TitanChatBedrockApi chatApi) { + public BedrockTitanModelCall(TitanChatBedrockApi chatApi) { this(chatApi, BedrockTitanChatOptions.builder().withTemperature(0.8f).build()); } - public BedrockTitanChatClient(TitanChatBedrockApi chatApi, BedrockTitanChatOptions defaultOptions) { + public BedrockTitanModelCall(TitanChatBedrockApi chatApi, BedrockTitanChatOptions defaultOptions) { Assert.notNull(chatApi, "ChatApi must not be null"); Assert.notNull(defaultOptions, "DefaultOptions must not be null"); this.chatApi = chatApi; diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicCreateRequestTests.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicCreateRequestTests.java index 928e183ad..82a0e0a98 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicCreateRequestTests.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicCreateRequestTests.java @@ -38,7 +38,7 @@ public class BedrockAnthropicCreateRequestTests { @Test public void createRequestWithChatOptions() { - var client = new BedrockAnthropicChatClient(anthropicChatApi, + var client = new BedrockAnthropicModelCall(anthropicChatApi, AnthropicChatOptions.builder() .withTemperature(66.6f) .withTopK(66) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCallIT.java similarity index 96% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCallIT.java index 43eb7e776..00f1aace1 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicModelCallIT.java @@ -55,12 +55,12 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockAnthropicChatClientIT { +class BedrockAnthropicModelCallIT { - private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropicChatClientIT.class); + private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropicModelCallIT.class); @Autowired - private BedrockAnthropicChatClient client; + private BedrockAnthropicModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -209,8 +209,8 @@ class BedrockAnthropicChatClientIT { } @Bean - public BedrockAnthropicChatClient anthropicChatClient(AnthropicChatBedrockApi anthropicApi) { - return new BedrockAnthropicChatClient(anthropicApi); + public BedrockAnthropicModelCall anthropicChatClient(AnthropicChatBedrockApi anthropicApi) { + return new BedrockAnthropicModelCall(anthropicApi); } } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3CreateRequestTests.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3CreateRequestTests.java index 480f914c3..038a63a59 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3CreateRequestTests.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3CreateRequestTests.java @@ -37,7 +37,7 @@ public class BedrockAnthropic3CreateRequestTests { @Test public void createRequestWithChatOptions() { - var client = new BedrockAnthropic3ChatClient(anthropicChatApi, + var client = new BedrockAnthropic3ModelCall(anthropicChatApi, Anthropic3ChatOptions.builder() .withTemperature(66.6f) .withTopK(66) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCallIT.java similarity index 96% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCallIT.java index 9568f4f69..1ea86afb9 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ModelCallIT.java @@ -59,12 +59,12 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockAnthropic3ChatClientIT { +class BedrockAnthropic3ModelCallIT { - private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropic3ChatClientIT.class); + private static final Logger logger = LoggerFactory.getLogger(BedrockAnthropic3ModelCallIT.class); @Autowired - private BedrockAnthropic3ChatClient client; + private BedrockAnthropic3ModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -228,8 +228,8 @@ class BedrockAnthropic3ChatClientIT { } @Bean - public BedrockAnthropic3ChatClient anthropicChatClient(Anthropic3ChatBedrockApi anthropicApi) { - return new BedrockAnthropic3ChatClient(anthropicApi); + public BedrockAnthropic3ModelCall anthropicChatClient(Anthropic3ChatBedrockApi anthropicApi) { + return new BedrockAnthropic3ModelCall(anthropicApi); } } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatCreateRequestTests.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatCreateRequestTests.java index 661c19e32..8b0ef7293 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatCreateRequestTests.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatCreateRequestTests.java @@ -45,7 +45,7 @@ public class BedrockCohereChatCreateRequestTests { @Test public void createRequestWithChatOptions() { - var client = new BedrockCohereChatClient(chatApi, + var client = new BedrockCohereModelCall(chatApi, BedrockCohereChatOptions.builder() .withTemperature(66.6f) .withTopK(66) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCallIT.java similarity index 97% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCallIT.java index 567926810..f189b2769 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/BedrockCohereModelCallIT.java @@ -54,10 +54,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockCohereChatClientIT { +class BedrockCohereModelCallIT { @Autowired - private BedrockCohereChatClient client; + private BedrockCohereModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -205,8 +205,8 @@ class BedrockCohereChatClientIT { } @Bean - public BedrockCohereChatClient cohereChatClient(CohereChatBedrockApi cohereApi) { - return new BedrockCohereChatClient(cohereApi); + public BedrockCohereModelCall cohereChatClient(CohereChatBedrockApi cohereApi) { + return new BedrockCohereModelCall(cohereApi); } } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCallIT.java similarity index 96% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCallIT.java index f6614b852..27bdf75b2 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ModelCallIT.java @@ -49,10 +49,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockAi21Jurassic2ChatClientIT { +class BedrockAi21Jurassic2ModelCallIT { @Autowired - private BedrockAi21Jurassic2ChatClient client; + private BedrockAi21Jurassic2ModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -152,9 +152,9 @@ class BedrockAi21Jurassic2ChatClientIT { } @Bean - public BedrockAi21Jurassic2ChatClient bedrockAi21Jurassic2ChatClient( + public BedrockAi21Jurassic2ModelCall bedrockAi21Jurassic2ChatClient( Ai21Jurassic2ChatBedrockApi jurassic2ChatBedrockApi) { - return new BedrockAi21Jurassic2ChatClient(jurassic2ChatBedrockApi, + return new BedrockAi21Jurassic2ModelCall(jurassic2ChatBedrockApi, BedrockAi21Jurassic2ChatOptions.builder() .withTemperature(0.5f) .withMaxTokens(100) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaCreateRequestTests.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaCreateRequestTests.java index 77018af9e..0bc14ab7d 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaCreateRequestTests.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaCreateRequestTests.java @@ -45,7 +45,7 @@ public class BedrockLlamaCreateRequestTests { @Test public void createRequestWithChatOptions() { - var client = new BedrockLlamaChatClient(api, + var client = new BedrockLlamaModelCall(api, BedrockLlamaChatOptions.builder().withTemperature(66.6f).withMaxGenLen(666).withTopP(0.66f).build()); var request = client.createRequest(new Prompt("Test message content")); diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCallIT.java similarity index 97% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCallIT.java index 3ecaf8650..95bafb7a7 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/llama/BedrockLlamaModelCallIT.java @@ -54,10 +54,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockLlamaChatClientIT { +class BedrockLlamaModelCallIT { @Autowired - private BedrockLlamaChatClient client; + private BedrockLlamaModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -206,8 +206,8 @@ class BedrockLlamaChatClientIT { } @Bean - public BedrockLlamaChatClient llamaChatClient(LlamaChatBedrockApi llamaApi) { - return new BedrockLlamaChatClient(llamaApi, + public BedrockLlamaModelCall llamaChatClient(LlamaChatBedrockApi llamaApi) { + return new BedrockLlamaModelCall(llamaApi, BedrockLlamaChatOptions.builder().withTemperature(0.5f).withMaxGenLen(100).withTopP(0.9f).build()); } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatCreateRequestTests.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatCreateRequestTests.java index 5f8065bc3..d488d124a 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatCreateRequestTests.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatCreateRequestTests.java @@ -41,7 +41,7 @@ public class BedrockTitanChatCreateRequestTests { @Test public void createRequestWithChatOptions() { - var client = new BedrockTitanChatClient(api, + var client = new BedrockTitanModelCall(api, BedrockTitanChatOptions.builder() .withTemperature(66.6f) .withTopP(0.66f) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClientIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCallIT.java similarity index 97% rename from models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClientIT.java rename to models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCallIT.java index 3f6b611c9..0351de783 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClientIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/BedrockTitanModelCallIT.java @@ -55,10 +55,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") -class BedrockTitanChatClientIT { +class BedrockTitanModelCallIT { @Autowired - private BedrockTitanChatClient client; + private BedrockTitanModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -211,8 +211,8 @@ class BedrockTitanChatClientIT { } @Bean - public BedrockTitanChatClient titanChatClient(TitanChatBedrockApi titanApi) { - return new BedrockTitanChatClient(titanApi); + public BedrockTitanModelCall titanChatClient(TitanChatBedrockApi titanApi) { + return new BedrockTitanModelCall(titanApi); } } diff --git a/models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceChatClient.java b/models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceModelCall.java similarity index 91% rename from models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceChatClient.java rename to models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceModelCall.java index 65b6ecdc9..ef68dd604 100644 --- a/models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceChatClient.java +++ b/models/spring-ai-huggingface/src/main/java/org/springframework/ai/huggingface/HuggingfaceModelCall.java @@ -22,7 +22,7 @@ import java.util.Map; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.huggingface.api.TextGenerationInferenceApi; @@ -34,12 +34,12 @@ import org.springframework.ai.huggingface.model.GenerateResponse; import org.springframework.ai.chat.prompt.Prompt; /** - * An implementation of {@link ChatClient} that interfaces with HuggingFace Inference + * An implementation of {@link ModelCall} that interfaces with HuggingFace Inference * Endpoints for text generation. * * @author Mark Pollack */ -public class HuggingfaceChatClient implements ChatClient { +public class HuggingfaceModelCall implements ModelCall { /** * Token required for authenticating with the HuggingFace Inference API. @@ -68,11 +68,11 @@ public class HuggingfaceChatClient implements ChatClient { private int maxNewTokens = 1000; /** - * Constructs a new HuggingfaceChatClient with the specified API token and base path. + * Constructs a new HuggingfaceModelCall with the specified API token and base path. * @param apiToken The API token for HuggingFace. * @param basePath The base path for API requests. */ - public HuggingfaceChatClient(final String apiToken, String basePath) { + public HuggingfaceModelCall(final String apiToken, String basePath) { this.apiToken = apiToken; this.apiClient.setBasePath(basePath); this.apiClient.addDefaultHeader("Authorization", "Bearer " + this.apiToken); diff --git a/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/HuggingfaceTestConfiguration.java b/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/HuggingfaceTestConfiguration.java index e4adf3bb8..8ceee3d74 100644 --- a/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/HuggingfaceTestConfiguration.java +++ b/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/HuggingfaceTestConfiguration.java @@ -23,7 +23,7 @@ import org.springframework.util.StringUtils; public class HuggingfaceTestConfiguration { @Bean - public HuggingfaceChatClient huggingfaceChatClient() { + public HuggingfaceModelCall huggingfaceChatClient() { String apiKey = System.getenv("HUGGINGFACE_API_KEY"); if (!StringUtils.hasText(apiKey)) { throw new IllegalArgumentException( @@ -31,7 +31,7 @@ public class HuggingfaceTestConfiguration { } // Created aws-mistral-7b-instruct-v0-1-805 via // https://ui.endpoints.huggingface.co/ - HuggingfaceChatClient huggingfaceChatClient = new HuggingfaceChatClient(apiKey, + HuggingfaceModelCall huggingfaceChatClient = new HuggingfaceModelCall(apiKey, "https://f6hg7b3cvlmntp5i.us-east-1.aws.endpoints.huggingface.cloud"); return huggingfaceChatClient; } diff --git a/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/client/ClientIT.java b/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/client/ClientIT.java index f21c7b9ab..24d528056 100644 --- a/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/client/ClientIT.java +++ b/models/spring-ai-huggingface/src/test/java/org/springframework/ai/huggingface/client/ClientIT.java @@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.springframework.ai.chat.ChatResponse; -import org.springframework.ai.huggingface.HuggingfaceChatClient; +import org.springframework.ai.huggingface.HuggingfaceModelCall; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ClientIT { @Autowired - protected HuggingfaceChatClient huggingfaceChatClient; + protected HuggingfaceModelCall huggingfaceChatClient; @Test void helloWorldCompletion() { diff --git a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java index 86c0bda36..d16f3daee 100644 --- a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java +++ b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java @@ -101,11 +101,11 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions private @JsonProperty("tool_choice") ToolChoice toolChoice; /** - * MistralAI Tool Function Callbacks to register with the ChatClient. For Prompt + * MistralAI Tool Function Callbacks to register with the ModelCall. For Prompt * Options the functionCallbacks are automatically enabled for the duration of the * prompt execution. For Default Options the functionCallbacks are registered but * disabled by default. Use the enableFunctions to set the functions from the registry - * to be used by the ChatClient chat completion requests. + * to be used by the ModelCall chat completion requests. */ @NestedConfigurationProperty @JsonIgnore diff --git a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiModelCall.java similarity index 96% rename from models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java rename to models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiModelCall.java index 17b7f8d93..12c03b5df 100644 --- a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java +++ b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiModelCall.java @@ -17,7 +17,7 @@ package org.springframework.ai.mistralai; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -55,9 +55,9 @@ import java.util.concurrent.ConcurrentHashMap; * @author Grogdunn * @since 0.8.1 */ -public class MistralAiChatClient extends +public class MistralAiModelCall extends AbstractFunctionCallSupport> - implements ChatClient, StreamingChatClient { + implements ModelCall, StreamingChatClient { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -73,7 +73,7 @@ public class MistralAiChatClient extends private final RetryTemplate retryTemplate; - public MistralAiChatClient(MistralAiApi mistralAiApi) { + public MistralAiModelCall(MistralAiApi mistralAiApi) { this(mistralAiApi, MistralAiChatOptions.builder() .withTemperature(0.7f) @@ -83,11 +83,11 @@ public class MistralAiChatClient extends .build()); } - public MistralAiChatClient(MistralAiApi mistralAiApi, MistralAiChatOptions options) { + public MistralAiModelCall(MistralAiApi mistralAiApi, MistralAiChatOptions options) { this(mistralAiApi, options, null, RetryUtils.DEFAULT_RETRY_TEMPLATE); } - public MistralAiChatClient(MistralAiApi mistralAiApi, MistralAiChatOptions options, + public MistralAiModelCall(MistralAiApi mistralAiApi, MistralAiChatOptions options, FunctionCallbackContext functionCallbackContext, RetryTemplate retryTemplate) { super(functionCallbackContext); Assert.notNull(mistralAiApi, "MistralAiApi must not be null"); diff --git a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatCompletionRequestTest.java b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatCompletionRequestTest.java index 57135164b..dcb23bf5b 100644 --- a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatCompletionRequestTest.java +++ b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatCompletionRequestTest.java @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; @EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+") public class MistralAiChatCompletionRequestTest { - MistralAiChatClient chatClient = new MistralAiChatClient(new MistralAiApi("test")); + MistralAiModelCall chatClient = new MistralAiModelCall(new MistralAiApi("test")); @Test void chatCompletionDefaultRequestTest() { diff --git a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatClientIT.java b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiModelCallIT.java similarity index 94% rename from models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatClientIT.java rename to models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiModelCallIT.java index 87e6acbdb..6918ad211 100644 --- a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatClientIT.java +++ b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiModelCallIT.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -56,12 +56,12 @@ import static org.assertj.core.api.Assertions.assertThat; */ @SpringBootTest(classes = MistralAiTestConfiguration.class) @EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+") -class MistralAiChatClientIT { +class MistralAiModelCallIT { - private static final Logger logger = LoggerFactory.getLogger(MistralAiChatClientIT.class); + private static final Logger logger = LoggerFactory.getLogger(MistralAiModelCallIT.class); @Autowired - protected ChatClient chatClient; + protected ModelCall modelCall; @Autowired protected StreamingChatClient streamingChatClient; @@ -90,7 +90,7 @@ class MistralAiChatClientIT { // NOTE: Mistral expects the system message to be before the user message or will // fail with 400 error. Prompt prompt = new Prompt(List.of(systemMessage, userMessage)); - ChatResponse response = chatClient.call(prompt); + ChatResponse response = modelCall.call(prompt); assertThat(response.getResults()).hasSize(1); assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard"); } @@ -108,7 +108,7 @@ class MistralAiChatClientIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "ice cream flavors", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = this.chatClient.call(prompt).getResult(); + Generation generation = this.modelCall.call(prompt).getResult(); List list = outputConverter.convert(generation.getOutput().getContent()); assertThat(list).hasSize(5); @@ -126,7 +126,7 @@ class MistralAiChatClientIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); Map result = outputConverter.convert(generation.getOutput().getContent()); assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); @@ -148,7 +148,7 @@ class MistralAiChatClientIT { """; PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent()); logger.info("" + actorsFilms); @@ -201,7 +201,7 @@ class MistralAiChatClientIT { .build())) .build(); - ChatResponse response = chatClient.call(new Prompt(messages, promptOptions)); + ChatResponse response = modelCall.call(new Prompt(messages, promptOptions)); logger.info("Response: {}", response); diff --git a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiRetryTests.java b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiRetryTests.java index 1ca349d21..bf5338fa2 100644 --- a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiRetryTests.java +++ b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiRetryTests.java @@ -82,7 +82,7 @@ public class MistralAiRetryTests { private @Mock MistralAiApi mistralAiApi; - private MistralAiChatClient chatClient; + private MistralAiModelCall chatClient; private MistralAiEmbeddingClient embeddingClient; @@ -92,7 +92,7 @@ public class MistralAiRetryTests { retryListener = new TestRetryListener(); retryTemplate.registerListener(retryListener); - chatClient = new MistralAiChatClient(mistralAiApi, + chatClient = new MistralAiModelCall(mistralAiApi, MistralAiChatOptions.builder() .withTemperature(0.7f) .withTopP(1f) diff --git a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiTestConfiguration.java b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiTestConfiguration.java index 7952571d6..0f1da4cc2 100644 --- a/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiTestConfiguration.java +++ b/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiTestConfiguration.java @@ -41,8 +41,8 @@ public class MistralAiTestConfiguration { } @Bean - public MistralAiChatClient mistralAiChatClient(MistralAiApi mistralAiApi) { - return new MistralAiChatClient(mistralAiApi, + public MistralAiModelCall mistralAiChatClient(MistralAiApi mistralAiApi) { + return new MistralAiModelCall(mistralAiApi, MistralAiChatOptions.builder().withModel(MistralAiApi.ChatModel.MIXTRAL.getValue()).build()); } diff --git a/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java b/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaModelCall.java similarity index 93% rename from models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java rename to models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaModelCall.java index 273d98866..68af0f7a6 100644 --- a/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java +++ b/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaModelCall.java @@ -18,10 +18,10 @@ package org.springframework.ai.ollama; import java.util.Base64; import java.util.List; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.ollama.metadata.OllamaChatResponseMetadata; import reactor.core.publisher.Flux; -import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -39,7 +39,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** - * {@link ChatClient} implementation for {@literal Ollama}. + * {@link ModelCall} implementation for {@literal Ollama}. * * Ollama allows developers to run large language models and generate embeddings locally. * It supports open-source models available on [Ollama AI @@ -52,7 +52,7 @@ import org.springframework.util.StringUtils; * @author Christian Tzolov * @since 0.8.0 */ -public class OllamaChatClient implements ChatClient, StreamingChatClient { +public class OllamaModelCall implements ModelCall, StreamingChatClient { /** * Low-level Ollama API library. @@ -64,11 +64,11 @@ public class OllamaChatClient implements ChatClient, StreamingChatClient { */ private OllamaOptions defaultOptions; - public OllamaChatClient(OllamaApi chatApi) { + public OllamaModelCall(OllamaApi chatApi) { this(chatApi, OllamaOptions.create().withModel(OllamaOptions.DEFAULT_MODEL)); } - public OllamaChatClient(OllamaApi chatApi, OllamaOptions defaultOptions) { + public OllamaModelCall(OllamaApi chatApi, OllamaOptions defaultOptions) { Assert.notNull(chatApi, "OllamaApi must not be null"); Assert.notNull(defaultOptions, "DefaultOptions must not be null"); this.chatApi = chatApi; @@ -79,7 +79,7 @@ public class OllamaChatClient implements ChatClient, StreamingChatClient { * @deprecated Use {@link OllamaOptions#setModel} instead. */ @Deprecated - public OllamaChatClient withModel(String model) { + public OllamaModelCall withModel(String model) { this.defaultOptions.setModel(model); return this; } @@ -88,7 +88,7 @@ public class OllamaChatClient implements ChatClient, StreamingChatClient { * @deprecated Use {@link OllamaOptions} constructor instead. */ @Deprecated - public OllamaChatClient withDefaultOptions(OllamaOptions options) { + public OllamaModelCall withDefaultOptions(OllamaOptions options) { this.defaultOptions = options; return this; } diff --git a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatRequestTests.java b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatRequestTests.java index f78b8f2fc..31ee6f9b2 100644 --- a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatRequestTests.java +++ b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatRequestTests.java @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class OllamaChatRequestTests { - OllamaChatClient client = new OllamaChatClient(new OllamaApi(), + OllamaModelCall client = new OllamaModelCall(new OllamaApi(), new OllamaOptions().withModel("MODEL_NAME").withTopK(99).withTemperature(66.6f).withNumGPU(1)); @Test @@ -105,7 +105,7 @@ public class OllamaChatRequestTests { @Test public void createRequestWithDefaultOptionsModelOverride() { - OllamaChatClient client2 = new OllamaChatClient(new OllamaApi(), + OllamaModelCall client2 = new OllamaModelCall(new OllamaApi(), new OllamaOptions().withModel("DEFAULT_OPTIONS_MODEL")); var request = client2.ollamaChatRequest(new Prompt("Test message content"), true); diff --git a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientIT.java b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallIT.java similarity index 96% rename from models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientIT.java rename to models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallIT.java index 6f4254fa4..c7bc4702e 100644 --- a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientIT.java +++ b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallIT.java @@ -56,11 +56,11 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @Testcontainers @Disabled("For manual smoke testing only.") -class OllamaChatClientIT { +class OllamaModelCallIT { private static String MODEL = "mistral"; - private static final Log logger = LogFactory.getLog(OllamaChatClientIT.class); + private static final Log logger = LogFactory.getLog(OllamaModelCallIT.class); @Container static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32"); @@ -77,7 +77,7 @@ class OllamaChatClientIT { } @Autowired - private OllamaChatClient client; + private OllamaModelCall client; @Test void roleTest() { @@ -219,8 +219,8 @@ class OllamaChatClientIT { } @Bean - public OllamaChatClient ollamaChat(OllamaApi ollamaApi) { - return new OllamaChatClient(ollamaApi, OllamaOptions.create().withModel(MODEL).withTemperature(0.9f)); + public OllamaModelCall ollamaChat(OllamaApi ollamaApi) { + return new OllamaModelCall(ollamaApi, OllamaOptions.create().withModel(MODEL).withTemperature(0.9f)); } } diff --git a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientMultimodalIT.java b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallMultimodalIT.java similarity index 90% rename from models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientMultimodalIT.java rename to models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallMultimodalIT.java index 8599cfe9e..7ba575eae 100644 --- a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatClientMultimodalIT.java +++ b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaModelCallMultimodalIT.java @@ -44,11 +44,11 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @Testcontainers @Disabled("For manual smoke testing only.") -class OllamaChatClientMultimodalIT { +class OllamaModelCallMultimodalIT { private static String MODEL = "llava"; - private static final Log logger = LogFactory.getLog(OllamaChatClientIT.class); + private static final Log logger = LogFactory.getLog(OllamaModelCallIT.class); @Container static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32"); @@ -65,7 +65,7 @@ class OllamaChatClientMultimodalIT { } @Autowired - private OllamaChatClient client; + private OllamaModelCall client; @Test void multiModalityTest() throws IOException { @@ -90,8 +90,8 @@ class OllamaChatClientMultimodalIT { } @Bean - public OllamaChatClient ollamaChat(OllamaApi ollamaApi) { - return new OllamaChatClient(ollamaApi, OllamaOptions.create().withModel(MODEL).withTemperature(0.9f)); + public OllamaModelCall ollamaChat(OllamaApi ollamaApi) { + return new OllamaModelCall(ollamaApi, OllamaOptions.create().withModel(MODEL).withTemperature(0.9f)); } } diff --git a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java index d45d4db18..8447f7410 100644 --- a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java +++ b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java @@ -134,10 +134,10 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions { private @JsonProperty("user") String user; /** - * OpenAI Tool Function Callbacks to register with the ChatClient. + * OpenAI Tool Function Callbacks to register with the ModelCall. * For Prompt Options the functionCallbacks are automatically enabled for the duration of the prompt execution. * For Default Options the functionCallbacks are registered but disabled by default. Use the enableFunctions to set the functions - * from the registry to be used by the ChatClient chat completion requests. + * from the registry to be used by the ModelCall chat completion requests. */ @NestedConfigurationProperty @JsonIgnore diff --git a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatClient.java b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiModelCall.java similarity index 95% rename from models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatClient.java rename to models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiModelCall.java index 6ec6904db..d290b2c8a 100644 --- a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatClient.java +++ b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiModelCall.java @@ -17,7 +17,7 @@ package org.springframework.ai.openai; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -58,7 +58,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** - * {@link ChatClient} and {@link StreamingChatClient} implementation for {@literal OpenAI} + * {@link ModelCall} and {@link StreamingChatClient} implementation for {@literal OpenAI} * backed by {@link OpenAiApi}. * * @author Mark Pollack @@ -68,15 +68,15 @@ import java.util.concurrent.ConcurrentHashMap; * @author Josh Long * @author Jemin Huh * @author Grogdunn - * @see ChatClient + * @see ModelCall * @see StreamingChatClient * @see OpenAiApi */ -public class OpenAiChatClient extends +public class OpenAiModelCall extends AbstractFunctionCallSupport> - implements ChatClient, StreamingChatClient { + implements ModelCall, StreamingChatClient { - private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClient.class); + private static final Logger logger = LoggerFactory.getLogger(OpenAiModelCall.class); /** * The default options used for the chat completion requests. @@ -94,35 +94,35 @@ public class OpenAiChatClient extends private final OpenAiApi openAiApi; /** - * Creates an instance of the OpenAiChatClient. + * Creates an instance of the OpenAiModelCall. * @param openAiApi The OpenAiApi instance to be used for interacting with the OpenAI * Chat API. * @throws IllegalArgumentException if openAiApi is null */ - public OpenAiChatClient(OpenAiApi openAiApi) { + public OpenAiModelCall(OpenAiApi openAiApi) { this(openAiApi, OpenAiChatOptions.builder().withModel(OpenAiApi.DEFAULT_CHAT_MODEL).withTemperature(0.7f).build()); } /** - * Initializes an instance of the OpenAiChatClient. + * Initializes an instance of the OpenAiModelCall. * @param openAiApi The OpenAiApi instance to be used for interacting with the OpenAI * Chat API. * @param options The OpenAiChatOptions to configure the chat client. */ - public OpenAiChatClient(OpenAiApi openAiApi, OpenAiChatOptions options) { + public OpenAiModelCall(OpenAiApi openAiApi, OpenAiChatOptions options) { this(openAiApi, options, null, RetryUtils.DEFAULT_RETRY_TEMPLATE); } /** - * Initializes a new instance of the OpenAiChatClient. + * Initializes a new instance of the OpenAiModelCall. * @param openAiApi The OpenAiApi instance to be used for interacting with the OpenAI * Chat API. * @param options The OpenAiChatOptions to configure the chat client. * @param functionCallbackContext The function callback context. * @param retryTemplate The retry template. */ - public OpenAiChatClient(OpenAiApi openAiApi, OpenAiChatOptions options, + public OpenAiModelCall(OpenAiApi openAiApi, OpenAiChatOptions options, FunctionCallbackContext functionCallbackContext, RetryTemplate retryTemplate) { super(functionCallbackContext); Assert.notNull(openAiApi, "OpenAiApi must not be null"); diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/ChatCompletionRequestTests.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/ChatCompletionRequestTests.java index 300cdfafb..9ec6ed08f 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/ChatCompletionRequestTests.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/ChatCompletionRequestTests.java @@ -34,7 +34,7 @@ public class ChatCompletionRequestTests { @Test public void createRequestWithChatOptions() { - var client = new OpenAiChatClient(new OpenAiApi("TEST"), + var client = new OpenAiModelCall(new OpenAiApi("TEST"), OpenAiChatOptions.builder().withModel("DEFAULT_MODEL").withTemperature(66.6f).build()); var request = client.createRequest(new Prompt("Test message content"), false); @@ -60,7 +60,7 @@ public class ChatCompletionRequestTests { final String TOOL_FUNCTION_NAME = "CurrentWeather"; - var client = new OpenAiChatClient(new OpenAiApi("TEST"), + var client = new OpenAiModelCall(new OpenAiApi("TEST"), OpenAiChatOptions.builder().withModel("DEFAULT_MODEL").build()); var request = client.createRequest(new Prompt("Test message content", @@ -90,7 +90,7 @@ public class ChatCompletionRequestTests { final String TOOL_FUNCTION_NAME = "CurrentWeather"; - var client = new OpenAiChatClient(new OpenAiApi("TEST"), + var client = new OpenAiModelCall(new OpenAiApi("TEST"), OpenAiChatOptions.builder() .withModel("DEFAULT_MODEL") .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService()) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/OpenAiTestConfiguration.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/OpenAiTestConfiguration.java index 3a235cf7a..a5df19a45 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/OpenAiTestConfiguration.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/OpenAiTestConfiguration.java @@ -51,8 +51,8 @@ public class OpenAiTestConfiguration { } @Bean - public OpenAiChatClient openAiChatClient(OpenAiApi api) { - OpenAiChatClient openAiChatClient = new OpenAiChatClient(api); + public OpenAiModelCall openAiChatClient(OpenAiApi api) { + OpenAiModelCall openAiChatClient = new OpenAiModelCall(api); return openAiChatClient; } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/acme/AcmeIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/acme/AcmeIT.java index e38595b90..51bdbf08f 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/acme/AcmeIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/acme/AcmeIT.java @@ -26,8 +26,8 @@ import org.slf4j.LoggerFactory; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.document.Document; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiTestConfiguration; -import org.springframework.ai.openai.OpenAiChatClient; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.testutils.AbstractIT; import org.springframework.ai.chat.prompt.Prompt; @@ -61,7 +61,7 @@ public class AcmeIT extends AbstractIT { private OpenAiEmbeddingClient embeddingClient; @Autowired - private OpenAiChatClient chatClient; + private OpenAiModelCall chatClient; @Test void beanTest() { diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientWithChatResponseMetadataTests.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientWithChatResponseMetadataTests.java index b1ef5e43b..fb410fdb0 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientWithChatResponseMetadataTests.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientWithChatResponseMetadataTests.java @@ -27,7 +27,7 @@ import org.springframework.ai.chat.metadata.PromptMetadata; import org.springframework.ai.chat.metadata.RateLimit; import org.springframework.ai.chat.metadata.Usage; import org.springframework.ai.openai.api.OpenAiApi; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.metadata.support.OpenAiApiResponseHeaders; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.beans.factory.annotation.Autowired; @@ -57,7 +57,7 @@ public class OpenAiChatClientWithChatResponseMetadataTests { private static String TEST_API_KEY = "sk-1234567890"; @Autowired - private OpenAiChatClient openAiChatClient; + private OpenAiModelCall openAiChatClient; @Autowired private MockRestServiceServer server; @@ -171,8 +171,8 @@ public class OpenAiChatClientWithChatResponseMetadataTests { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClient2IT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCall2IT.java similarity index 91% rename from models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClient2IT.java rename to models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCall2IT.java index fc5904be1..bce2b2a89 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClient2IT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCall2IT.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest; @@ -41,14 +41,14 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Tzolov */ -@SpringBootTest(classes = OpenAiChatClient2IT.Config.class) +@SpringBootTest(classes = OpenAiModelCall2IT.Config.class) @EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+") -public class OpenAiChatClient2IT { +public class OpenAiModelCall2IT { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private OpenAiChatClient openAiChatClient; + private OpenAiModelCall openAiChatClient; @Test void responseFormatTest() throws JsonMappingException, JsonProcessingException { @@ -99,8 +99,8 @@ public class OpenAiChatClient2IT { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallIT.java similarity index 95% rename from models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientIT.java rename to models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallIT.java index 56ac4da9f..5a89b378d 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallIT.java @@ -60,9 +60,9 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = OpenAiTestConfiguration.class) @EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+") -class OpenAiChatClientIT extends AbstractIT { +class OpenAiModelCallIT extends AbstractIT { - private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClientIT.class); + private static final Logger logger = LoggerFactory.getLogger(OpenAiModelCallIT.class); @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -74,7 +74,7 @@ class OpenAiChatClientIT extends AbstractIT { SystemPromptTemplate systemPromptTemplate = new SystemPromptTemplate(systemResource); Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", "Bob", "voice", "pirate")); Prompt prompt = new Prompt(List.of(userMessage, systemMessage)); - ChatResponse response = chatClient.call(prompt); + ChatResponse response = modelCall.call(prompt); assertThat(response.getResults()).hasSize(1); assertThat(response.getResults().get(0).getOutput().getContent()).contains("Blackbeard"); // needs fine tuning... evaluateQuestionAndAnswer(request, response, false); @@ -93,7 +93,7 @@ class OpenAiChatClientIT extends AbstractIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "ice cream flavors", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = this.chatClient.call(prompt).getResult(); + Generation generation = this.modelCall.call(prompt).getResult(); List list = outputConverter.convert(generation.getOutput().getContent()); assertThat(list).hasSize(5); @@ -112,7 +112,7 @@ class OpenAiChatClientIT extends AbstractIT { PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); Map result = outputConverter.convert(generation.getOutput().getContent()); assertThat(result.get("numbers")).isEqualTo(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); @@ -131,7 +131,7 @@ class OpenAiChatClientIT extends AbstractIT { """; PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); ActorsFilms actorsFilms = outputConverter.convert(generation.getOutput().getContent()); } @@ -151,7 +151,7 @@ class OpenAiChatClientIT extends AbstractIT { """; PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); ActorsFilmsRecord actorsFilms = outputConverter.convert(generation.getOutput().getContent()); logger.info("" + actorsFilms); @@ -204,7 +204,7 @@ class OpenAiChatClientIT extends AbstractIT { .build())) .build(); - ChatResponse response = chatClient.call(new Prompt(messages, promptOptions)); + ChatResponse response = modelCall.call(new Prompt(messages, promptOptions)); logger.info("Response: {}", response); @@ -255,7 +255,7 @@ class OpenAiChatClientIT extends AbstractIT { var userMessage = new UserMessage("Explain what do you see on this picture?", List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData))); - var response = chatClient + var response = modelCall .call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build())); logger.info(response.getResult().getOutput().getContent()); @@ -271,7 +271,7 @@ class OpenAiChatClientIT extends AbstractIT { .of(new Media(MimeTypeUtils.IMAGE_PNG, new URL("https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/_images/multimodal.test.png")))); - ChatResponse response = chatClient + ChatResponse response = modelCall .call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().withModel(modelName).build())); logger.info(response.getResult().getOutput().getContent()); diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientTypeReferenceBeanOutputConverterIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallTypeReferenceBeanOutputConverterIT.java similarity index 94% rename from models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientTypeReferenceBeanOutputConverterIT.java rename to models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallTypeReferenceBeanOutputConverterIT.java index 4626af1fa..c83ef6d58 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatClientTypeReferenceBeanOutputConverterIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiModelCallTypeReferenceBeanOutputConverterIT.java @@ -39,10 +39,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = OpenAiTestConfiguration.class) @EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+") -class OpenAiChatClientTypeReferenceBeanOutputConverterIT extends AbstractIT { +class OpenAiModelCallTypeReferenceBeanOutputConverterIT extends AbstractIT { private static final Logger logger = LoggerFactory - .getLogger(OpenAiChatClientTypeReferenceBeanOutputConverterIT.class); + .getLogger(OpenAiModelCallTypeReferenceBeanOutputConverterIT.class); record ActorsFilmsRecord(String actor, List movies) { } @@ -61,7 +61,7 @@ class OpenAiChatClientTypeReferenceBeanOutputConverterIT extends AbstractIT { """; PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); Prompt prompt = new Prompt(promptTemplate.createMessage()); - Generation generation = chatClient.call(prompt).getResult(); + Generation generation = modelCall.call(prompt).getResult(); List actorsFilms = outputConverter.convert(generation.getOutput().getContent()); logger.info("" + actorsFilms); diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiRetryTests.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiRetryTests.java index dcf0f303f..d83407762 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiRetryTests.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiRetryTests.java @@ -31,7 +31,7 @@ import org.springframework.ai.image.ImageMessage; import org.springframework.ai.image.ImagePrompt; import org.springframework.ai.openai.OpenAiAudioTranscriptionClient; import org.springframework.ai.openai.OpenAiAudioTranscriptionOptions; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.OpenAiEmbeddingOptions; @@ -107,7 +107,7 @@ public class OpenAiRetryTests { private @Mock OpenAiImageApi openAiImageApi; - private OpenAiChatClient chatClient; + private OpenAiModelCall chatClient; private OpenAiEmbeddingClient embeddingClient; @@ -121,7 +121,7 @@ public class OpenAiRetryTests { retryListener = new TestRetryListener(); retryTemplate.registerListener(retryListener); - chatClient = new OpenAiChatClient(openAiApi, OpenAiChatOptions.builder().build(), null, retryTemplate); + chatClient = new OpenAiModelCall(openAiApi, OpenAiChatOptions.builder().build(), null, retryTemplate); embeddingClient = new OpenAiEmbeddingClient(openAiApi, MetadataMode.EMBED, OpenAiEmbeddingOptions.builder().build(), retryTemplate); audioTranscriptionClient = new OpenAiAudioTranscriptionClient(openAiAudioApi, diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryLongTermSystemPromptIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryLongTermSystemPromptIT.java index 4516e08ae..03c6d9af2 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryLongTermSystemPromptIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryLongTermSystemPromptIT.java @@ -36,7 +36,7 @@ import org.springframework.ai.chat.memory.SystemPromptChatMemoryAugmentor; import org.springframework.ai.embedding.EmbeddingClient; import org.springframework.ai.evaluation.BaseMemoryTest; import org.springframework.ai.evaluation.RelevancyEvaluator; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.tokenizer.JTokkitTokenCountEstimator; @@ -75,8 +75,8 @@ public class ChatMemoryLongTermSystemPromptIT extends BaseMemoryTest { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } @Bean @@ -98,7 +98,7 @@ public class ChatMemoryLongTermSystemPromptIT extends BaseMemoryTest { } @Bean - public ChatService memoryChatService(OpenAiChatClient chatClient, VectorStore vectorStore, + public ChatService memoryChatService(OpenAiModelCall chatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator) { return PromptTransformingChatService.builder(chatClient) @@ -110,7 +110,7 @@ public class ChatMemoryLongTermSystemPromptIT extends BaseMemoryTest { } @Bean - public StreamingChatService memoryStreamingChatService(OpenAiChatClient streamingChatClient, + public StreamingChatService memoryStreamingChatService(OpenAiModelCall streamingChatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator) { return StreamingPromptTransformingChatService.builder(streamingChatClient) @@ -122,7 +122,7 @@ public class ChatMemoryLongTermSystemPromptIT extends BaseMemoryTest { } @Bean - public RelevancyEvaluator relevancyEvaluator(OpenAiChatClient chatClient) { + public RelevancyEvaluator relevancyEvaluator(OpenAiModelCall chatClient) { return new RelevancyEvaluator(chatClient); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermMessageListIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermMessageListIT.java index d26f6c563..01e838262 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermMessageListIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermMessageListIT.java @@ -31,7 +31,7 @@ import org.springframework.ai.chat.memory.LastMaxTokenSizeContentTransformer; import org.springframework.ai.chat.memory.MessageChatMemoryAugmentor; import org.springframework.ai.evaluation.BaseMemoryTest; import org.springframework.ai.evaluation.RelevancyEvaluator; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.tokenizer.JTokkitTokenCountEstimator; import org.springframework.ai.tokenizer.TokenCountEstimator; @@ -59,8 +59,8 @@ public class ChatMemoryShortTermMessageListIT extends BaseMemoryTest { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } @Bean @@ -74,7 +74,7 @@ public class ChatMemoryShortTermMessageListIT extends BaseMemoryTest { } @Bean - public ChatService memoryChatService(OpenAiChatClient chatClient, ChatMemory chatHistory, + public ChatService memoryChatService(OpenAiModelCall chatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return PromptTransformingChatService.builder(chatClient) @@ -86,7 +86,7 @@ public class ChatMemoryShortTermMessageListIT extends BaseMemoryTest { } @Bean - public StreamingChatService memoryStreamingChatService(OpenAiChatClient streamingChatClient, + public StreamingChatService memoryStreamingChatService(OpenAiModelCall streamingChatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return StreamingPromptTransformingChatService.builder(streamingChatClient) @@ -98,7 +98,7 @@ public class ChatMemoryShortTermMessageListIT extends BaseMemoryTest { } @Bean - public RelevancyEvaluator relevancyEvaluator(OpenAiChatClient chatClient) { + public RelevancyEvaluator relevancyEvaluator(OpenAiModelCall chatClient) { return new RelevancyEvaluator(chatClient); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermSystemPromptIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermSystemPromptIT.java index 7ca4c795b..e1290f6d2 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermSystemPromptIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/ChatMemoryShortTermSystemPromptIT.java @@ -32,7 +32,7 @@ import org.springframework.ai.chat.memory.LastMaxTokenSizeContentTransformer; import org.springframework.ai.chat.memory.SystemPromptChatMemoryAugmentor; import org.springframework.ai.evaluation.BaseMemoryTest; import org.springframework.ai.evaluation.RelevancyEvaluator; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.tokenizer.JTokkitTokenCountEstimator; import org.springframework.ai.tokenizer.TokenCountEstimator; @@ -60,8 +60,8 @@ public class ChatMemoryShortTermSystemPromptIT extends BaseMemoryTest { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } @Bean @@ -75,7 +75,7 @@ public class ChatMemoryShortTermSystemPromptIT extends BaseMemoryTest { } @Bean - public ChatService memoryChatService(OpenAiChatClient chatClient, ChatMemory chatHistory, + public ChatService memoryChatService(OpenAiModelCall chatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return PromptTransformingChatService.builder(chatClient) @@ -87,7 +87,7 @@ public class ChatMemoryShortTermSystemPromptIT extends BaseMemoryTest { } @Bean - public StreamingChatService memoryStreamingChatService(OpenAiChatClient streamingChatClient, + public StreamingChatService memoryStreamingChatService(OpenAiModelCall streamingChatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return StreamingPromptTransformingChatService.builder(streamingChatClient) @@ -99,7 +99,7 @@ public class ChatMemoryShortTermSystemPromptIT extends BaseMemoryTest { } @Bean - public RelevancyEvaluator relevancyEvaluator(OpenAiChatClient chatClient) { + public RelevancyEvaluator relevancyEvaluator(OpenAiModelCall chatClient) { return new RelevancyEvaluator(chatClient); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/LongShortTermChatMemoryWithRagIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/LongShortTermChatMemoryWithRagIT.java index c2739a018..0acb5a90d 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/LongShortTermChatMemoryWithRagIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/LongShortTermChatMemoryWithRagIT.java @@ -30,6 +30,7 @@ import org.springframework.ai.chat.prompt.transformer.ChatServiceContext; import org.springframework.ai.chat.service.ChatService; import org.springframework.ai.chat.service.PromptTransformingChatService; import org.springframework.ai.openai.OpenAiChatOptions; +import org.springframework.ai.openai.OpenAiModelCall; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.qdrant.QdrantContainer; @@ -50,10 +51,8 @@ import org.springframework.ai.chat.prompt.transformer.VectorStoreRetriever; import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentTransformer; import org.springframework.ai.embedding.EmbeddingClient; -import org.springframework.ai.evaluation.EvaluationRequest; import org.springframework.ai.evaluation.EvaluationResponse; import org.springframework.ai.evaluation.RelevancyEvaluator; -import org.springframework.ai.openai.OpenAiChatClient; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.reader.JsonReader; @@ -164,8 +163,8 @@ public class LongShortTermChatMemoryWithRagIT { } @Bean - public OpenAiChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } @Bean @@ -187,7 +186,7 @@ public class LongShortTermChatMemoryWithRagIT { } @Bean - public ChatService memoryChatService(OpenAiChatClient chatClient, VectorStore vectorStore, + public ChatService memoryChatService(OpenAiModelCall chatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator, ChatMemory chatHistory) { return PromptTransformingChatService.builder(chatClient) @@ -224,7 +223,7 @@ public class LongShortTermChatMemoryWithRagIT { } // @Bean - // public StreamingChatService memoryStreamingChatAgent(OpenAiChatClient + // public StreamingChatService memoryStreamingChatAgent(OpenAiModelCall // streamingChatClient, // VectorStore vectorStore, TokenCountEstimator tokenCountEstimator, ChatHistory // chatHistory) { @@ -241,7 +240,7 @@ public class LongShortTermChatMemoryWithRagIT { // } @Bean - public RelevancyEvaluator relevancyEvaluator(OpenAiChatClient chatClient) { + public RelevancyEvaluator relevancyEvaluator(OpenAiModelCall chatClient) { // Use GPT 4 as a better model for determining relevancy. gpt 3.5 makes basic // mistakes OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder() diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/OpenAiPromptTransformingChatServiceIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/OpenAiPromptTransformingChatServiceIT.java index a5f1ed415..80074e07a 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/OpenAiPromptTransformingChatServiceIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/service/OpenAiPromptTransformingChatServiceIT.java @@ -23,6 +23,7 @@ import io.qdrant.client.QdrantClient; import io.qdrant.client.QdrantGrpcClient; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.service.ChatService; import org.springframework.ai.chat.prompt.transformer.TransformerContentType; import org.springframework.ai.document.Document; @@ -31,7 +32,6 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.qdrant.QdrantContainer; -import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.service.PromptTransformingChatService; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; @@ -39,10 +39,9 @@ import org.springframework.ai.chat.prompt.transformer.ChatServiceContext; import org.springframework.ai.chat.prompt.transformer.QuestionContextAugmentor; import org.springframework.ai.chat.prompt.transformer.VectorStoreRetriever; import org.springframework.ai.embedding.EmbeddingClient; -import org.springframework.ai.evaluation.EvaluationRequest; import org.springframework.ai.evaluation.EvaluationResponse; import org.springframework.ai.evaluation.RelevancyEvaluator; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.reader.JsonReader; @@ -72,7 +71,7 @@ public class OpenAiPromptTransformingChatServiceIT { @Container static QdrantContainer qdrantContainer = new QdrantContainer("qdrant/qdrant:v1.9.2"); - private final ChatClient chatClient; + private final ModelCall modelCall; private final VectorStore vectorStore; @@ -82,9 +81,9 @@ public class OpenAiPromptTransformingChatServiceIT { private ChatService chatService; @Autowired - public OpenAiPromptTransformingChatServiceIT(ChatClient chatClient, ChatService chatService, + public OpenAiPromptTransformingChatServiceIT(ModelCall modelCall, ChatService chatService, VectorStore vectorStore) { - this.chatClient = chatClient; + this.modelCall = modelCall; this.chatService = chatService; this.vectorStore = vectorStore; } @@ -103,7 +102,7 @@ public class OpenAiPromptTransformingChatServiceIT { OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder() .withModel(GPT_4_TURBO_PREVIEW.getValue()) .build(); - var relevancyEvaluator = new RelevancyEvaluator(this.chatClient, openAiChatOptions); + var relevancyEvaluator = new RelevancyEvaluator(this.modelCall, openAiChatOptions); EvaluationResponse evaluationResponse = relevancyEvaluator.evaluate(chatServiceResponse.toEvaluationRequest()); assertTrue(evaluationResponse.isPass(), "Response is not relevant to the question"); @@ -146,8 +145,8 @@ public class OpenAiPromptTransformingChatServiceIT { } @Bean - public ChatClient openAiClient(OpenAiApi openAiApi) { - return new OpenAiChatClient(openAiApi); + public ModelCall openAiClient(OpenAiApi openAiApi) { + return new OpenAiModelCall(openAiApi); } @Bean @@ -164,8 +163,8 @@ public class OpenAiPromptTransformingChatServiceIT { } @Bean - public ChatService chatService(ChatClient chatClient, VectorStore vectorStore) { - return PromptTransformingChatService.builder(chatClient) + public ChatService chatService(ModelCall modelCall, VectorStore vectorStore) { + return PromptTransformingChatService.builder(modelCall) .withRetrievers(List.of(new VectorStoreRetriever(vectorStore, SearchRequest.defaults()))) .withAugmentors(List.of(new QuestionContextAugmentor())) .build(); 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 89155e9e8..2538f2133 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 @@ -21,7 +21,7 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.StreamingChatClient; import org.springframework.ai.chat.prompt.Prompt; @@ -43,7 +43,7 @@ public abstract class AbstractIT { private static final Logger logger = LoggerFactory.getLogger(AbstractIT.class); @Autowired - protected ChatClient chatClient; + protected ModelCall modelCall; @Autowired protected StreamingChatClient streamingChatClient; @@ -85,12 +85,12 @@ public abstract class AbstractIT { } Message userMessage = userPromptTemplate.createMessage(); Prompt prompt = new Prompt(List.of(userMessage, systemMessage)); - String yesOrNo = chatClient.call(prompt).getResult().getOutput().getContent(); + String yesOrNo = modelCall.call(prompt).getResult().getOutput().getContent(); logger.info("Is Answer related to question: " + yesOrNo); if (yesOrNo.equalsIgnoreCase("no")) { SystemMessage notRelatedSystemMessage = new SystemMessage(qaEvaluatorNotRelatedResource); prompt = new Prompt(List.of(userMessage, notRelatedSystemMessage)); - String reasonForFailure = chatClient.call(prompt).getResult().getOutput().getContent(); + String reasonForFailure = modelCall.call(prompt).getResult().getOutput().getContent(); fail(reasonForFailure); } else { diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/transformer/MetadataTransformerIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/transformer/MetadataTransformerIT.java index d13c06612..363534368 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/transformer/MetadataTransformerIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/transformer/MetadataTransformerIT.java @@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test; import org.springframework.ai.document.DefaultContentFormatter; import org.springframework.ai.document.Document; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.api.OpenAiApi; -import org.springframework.ai.openai.OpenAiChatClient; import org.springframework.ai.transformer.ContentFormatTransformer; import org.springframework.ai.transformer.KeywordMetadataEnricher; import org.springframework.ai.transformer.SummaryMetadataEnricher; @@ -163,18 +163,18 @@ public class MetadataTransformerIT { } @Bean - public OpenAiChatClient openAiChatClient(OpenAiApi openAiApi) { - OpenAiChatClient openAiChatClient = new OpenAiChatClient(openAiApi); + public OpenAiModelCall openAiChatClient(OpenAiApi openAiApi) { + OpenAiModelCall openAiChatClient = new OpenAiModelCall(openAiApi); return openAiChatClient; } @Bean - public KeywordMetadataEnricher keywordMetadata(OpenAiChatClient aiClient) { + public KeywordMetadataEnricher keywordMetadata(OpenAiModelCall aiClient) { return new KeywordMetadataEnricher(aiClient, 5); } @Bean - public SummaryMetadataEnricher summaryMetadata(OpenAiChatClient aiClient) { + public SummaryMetadataEnricher summaryMetadata(OpenAiModelCall aiClient) { return new SummaryMetadataEnricher(aiClient, List.of(SummaryType.PREVIOUS, SummaryType.CURRENT, SummaryType.NEXT)); } diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java index 311ff16af..b583c31db 100644 --- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java +++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.model.function.FunctionCallback; import org.springframework.ai.model.function.FunctionCallingOptions; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient.ChatModel; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall.ChatModel; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.util.Assert; @@ -78,10 +78,10 @@ public class VertexAiGeminiChatOptions implements FunctionCallingOptions, ChatOp private @JsonProperty("modelName") String model; /** - * Tool Function Callbacks to register with the ChatClient. + * Tool Function Callbacks to register with the ModelCall. * For Prompt Options the functionCallbacks are automatically enabled for the duration of the prompt execution. * For Default Options the functionCallbacks are registered but disabled by default. Use the enableFunctions to set the functions - * from the registry to be used by the ChatClient chat completion requests. + * from the registry to be used by the ModelCall chat completion requests. */ @NestedConfigurationProperty @JsonIgnore diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCall.java similarity index 96% rename from models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java rename to models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCall.java index e30df03ce..336135fc4 100644 --- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java +++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCall.java @@ -32,7 +32,7 @@ import com.google.cloud.vertexai.generativeai.PartMaker; import com.google.cloud.vertexai.generativeai.ResponseStream; import com.google.protobuf.Struct; import com.google.protobuf.util.JsonFormat; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -65,9 +65,9 @@ import java.util.stream.Collectors; * @author Grogdunn * @since 0.8.1 */ -public class VertexAiGeminiChatClient - extends AbstractFunctionCallSupport - implements ChatClient, StreamingChatClient, DisposableBean { +public class VertexAiGeminiModelCall + extends AbstractFunctionCallSupport + implements ModelCall, StreamingChatClient, DisposableBean { private final static boolean IS_RUNTIME_CALL = true; @@ -117,7 +117,7 @@ public class VertexAiGeminiChatClient } - public VertexAiGeminiChatClient(VertexAI vertexAI) { + public VertexAiGeminiModelCall(VertexAI vertexAI) { this(vertexAI, VertexAiGeminiChatOptions.builder() .withModel(ChatModel.GEMINI_PRO_VISION) @@ -125,11 +125,11 @@ public class VertexAiGeminiChatClient .build()); } - public VertexAiGeminiChatClient(VertexAI vertexAI, VertexAiGeminiChatOptions options) { + public VertexAiGeminiModelCall(VertexAI vertexAI, VertexAiGeminiChatOptions options) { this(vertexAI, options, null); } - public VertexAiGeminiChatClient(VertexAI vertexAI, VertexAiGeminiChatOptions options, + public VertexAiGeminiModelCall(VertexAI vertexAI, VertexAiGeminiChatOptions options, FunctionCallbackContext functionCallbackContext) { super(functionCallbackContext); diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHints.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHints.java index 8911288fa..d24088278 100644 --- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHints.java +++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHints.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.vertexai.gemini.aot; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; @@ -34,7 +34,7 @@ public class VertexAiGeminiRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { var mcs = MemberCategory.values(); - for (var tr : findJsonAnnotatedClassesInPackage(VertexAiGeminiChatClient.class)) + for (var tr : findJsonAnnotatedClassesInPackage(VertexAiGeminiModelCall.class)) hints.reflection().registerType(tr, mcs); } diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClientIT.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCallIT.java similarity index 97% rename from models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClientIT.java rename to models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCallIT.java index 58f687eb4..d72285581 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClientIT.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiModelCallIT.java @@ -53,10 +53,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_PROJECT_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*") -class VertexAiGeminiChatClientIT { +class VertexAiGeminiModelCallIT { @Autowired - private VertexAiGeminiChatClient client; + private VertexAiGeminiModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -231,10 +231,10 @@ class VertexAiGeminiChatClientIT { } @Bean - public VertexAiGeminiChatClient vertexAiEmbedding(VertexAI vertexAi) { - return new VertexAiGeminiChatClient(vertexAi, + public VertexAiGeminiModelCall vertexAiEmbedding(VertexAI vertexAi) { + return new VertexAiGeminiModelCall(vertexAi, VertexAiGeminiChatOptions.builder() - .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_VISION) + .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_VISION) .build()); } diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHintsTests.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHintsTests.java index 2e3f12f12..1ac4f9599 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHintsTests.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/aot/VertexAiGeminiRuntimeHintsTests.java @@ -19,7 +19,7 @@ import java.util.Set; import org.junit.jupiter.api.Test; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; @@ -38,7 +38,7 @@ class VertexAiGeminiRuntimeHintsTests { RuntimeHints runtimeHints = new RuntimeHints(); VertexAiGeminiRuntimeHints vertexAiGeminiRuntimeHints = new VertexAiGeminiRuntimeHints(); vertexAiGeminiRuntimeHints.registerHints(runtimeHints, null); - Set jsonAnnotatedClasses = findJsonAnnotatedClassesInPackage(VertexAiGeminiChatClient.class); + Set jsonAnnotatedClasses = findJsonAnnotatedClassesInPackage(VertexAiGeminiModelCall.class); for (TypeReference jsonAnnotatedClass : jsonAnnotatedClasses) { assertThat(runtimeHints).matches(reflection().onType(jsonAnnotatedClass)); } diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiModelCallFunctionCallingIT.java similarity index 91% rename from models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java rename to models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiModelCallFunctionCallingIT.java index 11b852222..1f87569c5 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiModelCallFunctionCallingIT.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.chat.ChatResponse; @@ -38,7 +39,6 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.function.FunctionCallbackWrapper; import org.springframework.ai.model.function.FunctionCallbackWrapper.Builder.SchemaType; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; @@ -50,12 +50,12 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_PROJECT_ID", matches = ".*") @EnabledIfEnvironmentVariable(named = "VERTEX_AI_GEMINI_LOCATION", matches = ".*") -public class VertexAiGeminiChatClientFunctionCallingIT { +public class VertexAiGeminiModelCallFunctionCallingIT { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private VertexAiGeminiChatClient vertexGeminiClient; + private VertexAiGeminiModelCall vertexGeminiClient; @AfterEach public void afterEach() { @@ -98,8 +98,8 @@ public class VertexAiGeminiChatClientFunctionCallingIT { """; var promptOptions = VertexAiGeminiChatOptions.builder() - .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO) - // .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO) + .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO) + // .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_1_5_PRO) .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService()) .withName("get_current_weather") .withDescription("Get the current weather in a given location") @@ -126,8 +126,8 @@ public class VertexAiGeminiChatClientFunctionCallingIT { List messages = new ArrayList<>(List.of(userMessage)); var promptOptions = VertexAiGeminiChatOptions.builder() - // .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO) - .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) + // .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_1_5_PRO) + .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO.getValue()) .withFunctionCallbacks(List.of( FunctionCallbackWrapper.builder(new MockWeatherService()) .withSchemaType(SchemaType.OPEN_API_SCHEMA) @@ -168,7 +168,7 @@ public class VertexAiGeminiChatClientFunctionCallingIT { List messages = new ArrayList<>(List.of(userMessage)); var promptOptions = VertexAiGeminiChatOptions.builder() - .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO) + .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO) .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService()) .withSchemaType(SchemaType.OPEN_API_SCHEMA) .withName("getCurrentWeather") @@ -224,10 +224,10 @@ public class VertexAiGeminiChatClientFunctionCallingIT { } @Bean - public VertexAiGeminiChatClient vertexAiEmbedding(VertexAI vertexAi) { - return new VertexAiGeminiChatClient(vertexAi, + public VertexAiGeminiModelCall vertexAiEmbedding(VertexAI vertexAi) { + return new VertexAiGeminiModelCall(vertexAi, VertexAiGeminiChatOptions.builder() - .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO) + .withModel(VertexAiGeminiModelCall.ChatModel.GEMINI_PRO) .withTemperature(0.9f) .build()); } diff --git a/models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatClient.java b/models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ModelCall.java similarity index 93% rename from models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatClient.java rename to models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ModelCall.java index 671097615..e5b472c1c 100644 --- a/models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatClient.java +++ b/models/spring-ai-vertex-ai-palm2/src/main/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ModelCall.java @@ -18,7 +18,7 @@ package org.springframework.ai.vertexai.palm2; import java.util.List; import java.util.stream.Collectors; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -35,18 +35,18 @@ import org.springframework.util.CollectionUtils; /** * @author Christian Tzolov */ -public class VertexAiPaLm2ChatClient implements ChatClient { +public class VertexAiPaLm2ModelCall implements ModelCall { private final VertexAiPaLm2Api vertexAiApi; private final VertexAiPaLm2ChatOptions defaultOptions; - public VertexAiPaLm2ChatClient(VertexAiPaLm2Api vertexAiApi) { + public VertexAiPaLm2ModelCall(VertexAiPaLm2Api vertexAiApi) { this(vertexAiApi, VertexAiPaLm2ChatOptions.builder().withTemperature(0.7f).withCandidateCount(1).withTopK(20).build()); } - public VertexAiPaLm2ChatClient(VertexAiPaLm2Api vertexAiApi, VertexAiPaLm2ChatOptions defaultOptions) { + public VertexAiPaLm2ModelCall(VertexAiPaLm2Api vertexAiApi, VertexAiPaLm2ChatOptions defaultOptions) { Assert.notNull(defaultOptions, "Default options must not be null!"); Assert.notNull(vertexAiApi, "VertexAiPaLm2Api must not be null!"); diff --git a/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatGenerationClientIT.java b/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatGenerationClientIT.java index 5fd43b0d5..f0a5c9a27 100644 --- a/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatGenerationClientIT.java +++ b/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatGenerationClientIT.java @@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; class VertexAiPaLm2ChatGenerationClientIT { @Autowired - private VertexAiPaLm2ChatClient client; + private VertexAiPaLm2ModelCall client; @Value("classpath:/prompts/system-message.st") private Resource systemResource; @@ -136,8 +136,8 @@ class VertexAiPaLm2ChatGenerationClientIT { } @Bean - public VertexAiPaLm2ChatClient vertexAiEmbedding(VertexAiPaLm2Api vertexAiApi) { - return new VertexAiPaLm2ChatClient(vertexAiApi); + public VertexAiPaLm2ModelCall vertexAiEmbedding(VertexAiPaLm2Api vertexAiApi) { + return new VertexAiPaLm2ModelCall(vertexAiApi); } } diff --git a/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatRequestTests.java b/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatRequestTests.java index 6c5478f67..549a05833 100644 --- a/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatRequestTests.java +++ b/models/spring-ai-vertex-ai-palm2/src/test/java/org/springframework/ai/vertexai/palm2/VertexAiPaLm2ChatRequestTests.java @@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class VertexAiPaLm2ChatRequestTests { - VertexAiPaLm2ChatClient client = new VertexAiPaLm2ChatClient(new VertexAiPaLm2Api("bla")); + VertexAiPaLm2ModelCall client = new VertexAiPaLm2ModelCall(new VertexAiPaLm2Api("bla")); @Test public void createRequestWithDefaultOptions() { diff --git a/models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiChatClient.java b/models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiModelCall.java similarity index 93% rename from models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiChatClient.java rename to models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiModelCall.java index b4f5c14ff..496cb4220 100644 --- a/models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiChatClient.java +++ b/models/spring-ai-watsonx-ai/src/main/java/org/springframework/ai/watsonx/WatsonxAiModelCall.java @@ -18,9 +18,9 @@ package org.springframework.ai.watsonx; import java.util.List; import java.util.Map; +import org.springframework.ai.chat.ModelCall; import reactor.core.publisher.Flux; -import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -35,7 +35,7 @@ import org.springframework.ai.watsonx.utils.MessageToPromptConverter; import org.springframework.util.Assert; /** - * {@link ChatClient} implementation for {@literal watsonx.ai}. + * {@link ModelCall} implementation for {@literal watsonx.ai}. * * watsonx.ai allows developers to use large language models within a SaaS service. It * supports multiple open-source models as well as IBM created models @@ -48,13 +48,13 @@ import org.springframework.util.Assert; * @author Christian Tzolov * @since 1.0.0 */ -public class WatsonxAiChatClient implements ChatClient, StreamingChatClient { +public class WatsonxAiModelCall implements ModelCall, StreamingChatClient { private final WatsonxAiApi watsonxAiApi; private final WatsonxAiChatOptions defaultOptions; - public WatsonxAiChatClient(WatsonxAiApi watsonxAiApi) { + public WatsonxAiModelCall(WatsonxAiApi watsonxAiApi) { this(watsonxAiApi, WatsonxAiChatOptions.builder() .withTemperature(0.7f) @@ -68,7 +68,7 @@ public class WatsonxAiChatClient implements ChatClient, StreamingChatClient { .build()); } - public WatsonxAiChatClient(WatsonxAiApi watsonxAiApi, WatsonxAiChatOptions defaultOptions) { + public WatsonxAiModelCall(WatsonxAiApi watsonxAiApi, WatsonxAiChatOptions defaultOptions) { Assert.notNull(watsonxAiApi, "watsonxAiApi cannot be null"); Assert.notNull(defaultOptions, "defaultOptions cannot be null"); this.watsonxAiApi = watsonxAiApi; diff --git a/models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiChatClientTest.java b/models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiModelCallTest.java similarity index 97% rename from models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiChatClientTest.java rename to models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiModelCallTest.java index c74afa427..c9c320c6d 100644 --- a/models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiChatClientTest.java +++ b/models/spring-ai-watsonx-ai/src/test/java/org/springframework/ai/watsonx/WatsonxAiModelCallTest.java @@ -46,9 +46,9 @@ import static org.mockito.Mockito.when; * @author Pablo Sanchidrian Herrera * @author John Jairo Moreno Rojas */ -public class WatsonxAiChatClientTest { +public class WatsonxAiModelCallTest { - WatsonxAiChatClient chatClient = new WatsonxAiChatClient(mock(WatsonxAiApi.class)); + WatsonxAiModelCall chatClient = new WatsonxAiModelCall(mock(WatsonxAiApi.class)); @Test public void testCreateRequestWithNoModelId() { @@ -157,7 +157,7 @@ public class WatsonxAiChatClientTest { @Test public void testCallMethod() { WatsonxAiApi mockChatApi = mock(WatsonxAiApi.class); - WatsonxAiChatClient client = new WatsonxAiChatClient(mockChatApi); + WatsonxAiModelCall client = new WatsonxAiModelCall(mockChatApi); Prompt prompt = new Prompt(List.of(new SystemMessage("Your prompt here")), WatsonxAiChatOptions.builder().withModel("google/flan-ul2").build()); @@ -186,7 +186,7 @@ public class WatsonxAiChatClientTest { @Test public void testStreamMethod() { WatsonxAiApi mockChatApi = mock(WatsonxAiApi.class); - WatsonxAiChatClient client = new WatsonxAiChatClient(mockChatApi); + WatsonxAiModelCall client = new WatsonxAiModelCall(mockChatApi); Prompt prompt = new Prompt(List.of(new SystemMessage("Your prompt here")), WatsonxAiChatOptions.builder().withModel("google/flan-ul2").build()); diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatClient.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatClient.java index cff4f8674..56e87b805 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatClient.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatClient.java @@ -15,30 +15,426 @@ */ package org.springframework.ai.chat; -import org.springframework.ai.chat.prompt.Prompt; - -import java.util.Arrays; - +import org.springframework.ai.chat.messages.Media; import org.springframework.ai.chat.messages.Message; +import org.springframework.ai.chat.messages.SystemMessage; import org.springframework.ai.chat.messages.UserMessage; -import org.springframework.ai.model.ModelClient; +import org.springframework.ai.chat.prompt.ChatOptions; +import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.PromptTemplate; +import org.springframework.ai.converter.BeanOutputConverter; +import org.springframework.ai.model.function.FunctionCallback; +import org.springframework.ai.model.function.FunctionCallbackWrapper; +import org.springframework.ai.model.function.FunctionCallingOptionsBuilder; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.Resource; +import org.springframework.util.Assert; +import org.springframework.util.MimeType; +import org.springframework.util.StringUtils; +import reactor.core.publisher.Flux; -@FunctionalInterface -public interface ChatClient extends ModelClient { +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.*; +import java.util.function.Consumer; - default String call(String message) { - Prompt prompt = new Prompt(new UserMessage(message)); - Generation generation = call(prompt).getResult(); - return (generation != null) ? generation.getOutput().getContent() : ""; +// todo support plugging in a outputConverter at runtime +// todo figure out stream and list methods + +/* + * @author Mark Pollack + * @author Christian Tzolov + * @author Josh Long + * @author Arjen Poutsma + */ +public interface ChatClient { + + static ChatClientBuilder builder(ModelCall connector) { + return new ChatClientBuilder(connector); } - default String call(Message... messages) { - Prompt prompt = new Prompt(Arrays.asList(messages)); - Generation generation = call(prompt).getResult(); - return (generation != null) ? generation.getOutput().getContent() : ""; - } - - @Override ChatResponse call(Prompt prompt); + ChatClientRequest call(); + + interface PromptSpec { + + T text(String text); + + T text(Resource text, Charset charset); + + T text(Resource text); + + T params(Map p); + + T param(String k, String v); + + } + + abstract class AbstractPromptSpec> implements PromptSpec { + + private String text = ""; + + private final Map params = new HashMap<>(); + + @Override + public T text(String text) { + this.text = text; + return self(); + } + + @Override + public T text(Resource text, Charset charset) { + try { + this.text(text.getContentAsString(charset)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return self(); + } + + @Override + public T text(Resource text) { + this.text(text, Charset.defaultCharset()); + return self(); + } + + @Override + public T param(String k, String v) { + this.params.put(k, v); + return self(); + } + + @Override + public T params(Map p) { + this.params.putAll(p); + return self(); + } + + protected abstract T self(); + + protected String text() { + return this.text; + } + + protected Map params() { + return this.params; + } + + } + + class UserSpec extends AbstractPromptSpec implements PromptSpec { + + private final List media = new ArrayList<>(); + + public UserSpec media(Media... media) { + this.media.addAll(Arrays.asList(media)); + return self(); + } + + public UserSpec media(MimeType mimeType, URL url) { + this.media.add(new Media(mimeType, url)); + return self(); + } + + public UserSpec media(MimeType mimeType, Resource resource) { + this.media.add(new Media(mimeType, resource)); + return self(); + } + + protected List media() { + return this.media; + } + + @Override + protected UserSpec self() { + return this; + } + + } + + class SystemSpec extends AbstractPromptSpec implements PromptSpec { + + @Override + protected SystemSpec self() { + return this; + } + + } + + class ChatClientRequest { + + private final ModelCall connector; + + private String userText = ""; + + private String systemText = ""; + + private ChatOptions chatOptions; + + private final List media = new ArrayList<>(); + + private final Set functionNames = new HashSet<>(); + + private final List functionCallbacks = new ArrayList<>(); + + private final Map userParams = new HashMap<>(); + + private final List messages = new ArrayList<>(); + + private final Map systemParams = new HashMap<>(); + + public ChatClientRequest(ModelCall connector, String userText, String systemText, List functionNames, + List media, ChatOptions chatOptions) { + this.userText = userText; + this.systemText = systemText; + this.connector = connector; + this.functionNames.addAll(functionNames); + this.media.addAll(media); + this.chatOptions = chatOptions; + } + + public ChatClientRequest messages(Message... messages) { + this.messages.addAll(List.of(messages)); + return this; + } + + public ChatClientRequest options(T options) { + this.chatOptions = options; + return this; + } + + public ChatClientRequest function(String name, String description, + java.util.function.Function function) { + var fcw = FunctionCallbackWrapper.builder(function) + .withDescription(description) + .withName(name) + .withResponseConverter(Object::toString) + .build(); + this.functionCallbacks.add(fcw); + return this; + } + + public ChatClientRequest functions(String... functions) { + this.functionNames.addAll(List.of(functions)); + return this; + } + + public ChatClientRequest system(Consumer consumer) { + var ss = new SystemSpec(); + consumer.accept(ss); + this.systemText = ss.text(); + this.systemParams.putAll(ss.params()); + return this; + } + + public ChatClientRequest user(Consumer consumer) { + var us = new UserSpec(); + consumer.accept(us); + this.userText = us.text(); + this.userParams.putAll(us.params()); + this.media.addAll(us.media()); + return this; + } + + public static class ChatResponseSpec { + + private final ChatClientRequest request; + + private final ModelCall modelCall; + + public ChatResponseSpec(ModelCall modelCall, ChatClientRequest request) { + this.modelCall = modelCall; + this.request = request; + } + + public T single(ParameterizedTypeReference t) { + return doSingleWithBeanOutputConverter(new BeanOutputConverter(new ParameterizedTypeReference<>() { + })); + } + + private T doSingleWithBeanOutputConverter(BeanOutputConverter boc) { + var processedUserText = this.request.userText + System.lineSeparator() + System.lineSeparator() + + boc.getFormat(); + var chatResponse = doGetChatResponse(processedUserText); + var stringResponse = chatResponse.getResult().getOutput().getContent(); + return boc.convert(stringResponse); + } + + public T single(Class clzz) { + Assert.notNull(clzz, "the class must be non-null"); + var boc = new BeanOutputConverter(clzz); + return doSingleWithBeanOutputConverter(boc); + } + + private ChatResponse doGetChatResponse(String processedUserText) { + + var messages = new ArrayList(); + var textsAreValid = (StringUtils.hasText(processedUserText) + || StringUtils.hasText(this.request.systemText)); + var messagesAreValid = !this.request.messages.isEmpty(); + + Assert.state(!(messagesAreValid && textsAreValid), "you must specify either " + Message.class.getName() + + " instances or user/system texts, but not both"); + + if (textsAreValid) { + + var userMessage = new UserMessage( + new PromptTemplate(processedUserText, this.request.userParams).render(), + this.request.media); + + var systemMessage = new SystemMessage( + new PromptTemplate(this.request.systemText, this.request.systemParams).render()); + + messages.add(systemMessage); + messages.add(userMessage); + + } + else { + messages.addAll(this.request.messages); + } + if (this.request.chatOptions instanceof FunctionCallingOptionsBuilder.PortableFunctionCallingOptions functionCallingOptions) { + if (!this.request.functionNames.isEmpty()) { + functionCallingOptions.setFunctions(this.request.functionNames); + } + if (!this.request.functionCallbacks.isEmpty()) { + functionCallingOptions.setFunctionCallbacks(this.request.functionCallbacks); + } + } + var prompt = new Prompt(messages, this.request.chatOptions); + return this.modelCall.call(prompt); + } + + public ChatResponse chatResponse() { + return doGetChatResponse(this.request.userText); + } + + public Flux stream(Class t) { + notSupported(); + return null; + } + + public Flux stream(ParameterizedTypeReference t) { + notSupported(); + return Flux.empty(); + } + + public String content() { + return doGetChatResponse(this.request.userText).getResult().getOutput().getContent(); + } + + public Collection list(Class clzz) { + // todo move to the new ParameterizedTypeReference ready + // BeanOutputConverter + notSupported(); + return null; + } + + public Collection list(ParameterizedTypeReference> ptr) { + notSupported(); + return List.of(); + } + + private static void notSupported() { + throw new RuntimeException("this operation is not supported"); + } + + } + + public ChatResponseSpec chat() { + return new ChatResponseSpec(this.connector, this); + } + + } + + class ChatClientBuilder { + + private final ModelCall modelCall; + + private final List defaultMedia = new ArrayList<>(); + + private final List defaultFunctionsNames = new ArrayList<>(); + + private final List defaultFunctionCallbacks = new ArrayList<>(); + + private String defaultSystem; + + private String defaultUser; + + ChatClientBuilder(ModelCall modelCall) { + Assert.notNull(modelCall, "the " + ModelCall.class.getName() + " must be non-null"); + this.modelCall = modelCall; + } + + public ChatClient build() { + return new DefaultChatClient(this.modelCall, this.defaultSystem, this.defaultUser, + this.defaultFunctionsNames, this.defaultMedia); + } + + public ChatClientBuilder defaultSystem(Resource resource) { + return this.defaultSystem(resource, Charset.defaultCharset()); + } + + public ChatClientBuilder defaultSystem(Resource resource, Charset charset) { + try { + this.defaultSystem = resource.getContentAsString(charset); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return this; + } + + public ChatClientBuilder defaultSystem(String systemText) { + this.defaultSystem = systemText; + return this; + } + + public ChatClientBuilder defaultFunctions(String... functionNames) { + this.defaultFunctionsNames.addAll(List.of(functionNames)); + return this; + } + + public ChatClientBuilder defaultFunctions(List functions) { + this.defaultFunctionCallbacks.addAll(functions); + return this; + } + + public ChatClientBuilder defaultUser(Resource userText) { + return this.defaultUser(userText, Charset.defaultCharset()); + } + + public ChatClientBuilder defaultUser(Resource userText, Charset charset) { + try { + this.defaultUser = userText.getContentAsString(charset); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return this; + } + + public ChatClientBuilder defaultUser(String userText) { + this.defaultUser = userText; + return this; + } + + } + + @Deprecated(since = "1.0.0 M1", forRemoval = true) + default String call(String message) { + var prompt = new Prompt(new UserMessage(message)); + var generation = call(prompt).getResult(); + return (generation != null) ? generation.getOutput().getContent() : ""; + } + + @Deprecated(since = "1.0.0 M1", forRemoval = true) + default String call(Message... messages) { + var prompt = new Prompt(Arrays.asList(messages)); + var generation = call(prompt).getResult(); + return (generation != null) ? generation.getOutput().getContent() : ""; + } + } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/DefaultChatClient.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/DefaultChatClient.java new file mode 100644 index 000000000..698049ecb --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/DefaultChatClient.java @@ -0,0 +1,51 @@ +package org.springframework.ai.chat; + +import org.springframework.ai.chat.messages.Media; +import org.springframework.ai.chat.prompt.Prompt; + +import java.util.List; + +/** + * @author Mark Pollack + * @author Christian Tzolov + * @author Josh Long + * @author Arjen Poutsma + */ +class DefaultChatClient implements ChatClient { + + private final ModelCall modelCall; + + private final String userText, systemText; + + private final List functionNames; + + private final List media; + + public DefaultChatClient(ModelCall modelCall, String defaultSystemPrompt, String defaultUserPrompt, + List defaultFunctions, List defaultMedia) { + this.modelCall = modelCall; + this.userText = defaultUserPrompt; + this.systemText = defaultSystemPrompt; + this.functionNames = defaultFunctions; + this.media = defaultMedia; + + } + + @Override + public ChatClientRequest call() { + return new ChatClientRequest(this.modelCall, this.userText, this.systemText, this.functionNames, this.media, + null); + } + + /** + * use the new fluid DSL starting in {@link #call()} + * @param prompt the {@link Prompt prompt} object + * @return a {@link ChatResponse chat response} + */ + @Deprecated(forRemoval = true, since = "1.0.0 M1") + @Override + public ChatResponse call(Prompt prompt) { + return this.modelCall.call(prompt); + } + +} \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/ModelCall.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/ModelCall.java new file mode 100644 index 000000000..d8186bf1e --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/ModelCall.java @@ -0,0 +1,44 @@ +/* + * Copyright 2023 - 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.ai.chat; + +import org.springframework.ai.chat.prompt.Prompt; + +import java.util.Arrays; + +import org.springframework.ai.chat.messages.Message; +import org.springframework.ai.chat.messages.UserMessage; +import org.springframework.ai.model.ModelClient; + +@FunctionalInterface +public interface ModelCall extends ModelClient { + + default String call(String message) { + Prompt prompt = new Prompt(new UserMessage(message)); + Generation generation = call(prompt).getResult(); + return (generation != null) ? generation.getOutput().getContent() : ""; + } + + default String call(Message... messages) { + Prompt prompt = new Prompt(Arrays.asList(messages)); + Generation generation = call(prompt).getResult(); + return (generation != null) ? generation.getOutput().getContent() : ""; + } + + @Override + ChatResponse call(Prompt prompt); + +} diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/service/PromptTransformingChatService.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/service/PromptTransformingChatService.java index 761ae5f42..f7c1eb716 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/service/PromptTransformingChatService.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/service/PromptTransformingChatService.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.chat.service; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.prompt.transformer.ChatServiceContext; import org.springframework.ai.chat.prompt.transformer.PromptTransformer; @@ -35,7 +35,7 @@ import java.util.Objects; */ public class PromptTransformingChatService implements ChatService { - private ChatClient chatClient; + private ModelCall modelCall; private List retrievers; @@ -45,19 +45,19 @@ public class PromptTransformingChatService implements ChatService { private List chatServiceListeners; - public PromptTransformingChatService(ChatClient chatClient, List retrievers, + public PromptTransformingChatService(ModelCall modelCall, List retrievers, List documentPostProcessors, List augmentors, List chatServiceListeners) { - Objects.requireNonNull(chatClient, "chatClient must not be null"); - this.chatClient = chatClient; + Objects.requireNonNull(modelCall, "modelCall must not be null"); + this.modelCall = modelCall; this.retrievers = retrievers; this.documentPostProcessors = documentPostProcessors; this.augmentors = augmentors; this.chatServiceListeners = chatServiceListeners; } - public static Builder builder(ChatClient chatClient) { - return new Builder().withChatClient(chatClient); + public static Builder builder(ModelCall modelCall) { + return new Builder().withChatClient(modelCall); } @Override @@ -86,7 +86,7 @@ public class PromptTransformingChatService implements ChatService { } // Perform generation - ChatResponse chatResponse = this.chatClient.call(chatServiceContext.getPrompt()); + ChatResponse chatResponse = this.modelCall.call(chatServiceContext.getPrompt()); // Invoke Listeners onComplete ChatServiceResponse chatServiceResponse = new ChatServiceResponse(chatServiceContext, chatResponse); @@ -98,7 +98,7 @@ public class PromptTransformingChatService implements ChatService { public static class Builder { - private ChatClient chatClient; + private ModelCall modelCall; private List retrievers = new ArrayList<>(); @@ -108,8 +108,8 @@ public class PromptTransformingChatService implements ChatService { private List chatServiceListeners = new ArrayList<>(); - public Builder withChatClient(ChatClient chatClient) { - this.chatClient = chatClient; + public Builder withChatClient(ModelCall modelCall) { + this.modelCall = modelCall; return this; } @@ -134,7 +134,7 @@ public class PromptTransformingChatService implements ChatService { } public PromptTransformingChatService build() { - return new PromptTransformingChatService(chatClient, retrievers, documentPostProcessors, augmentors, + return new PromptTransformingChatService(modelCall, retrievers, documentPostProcessors, augmentors, chatServiceListeners); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/evaluation/RelevancyEvaluator.java b/spring-ai-core/src/main/java/org/springframework/ai/evaluation/RelevancyEvaluator.java index 8afc9dcff..f9f7fa91f 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/evaluation/RelevancyEvaluator.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/evaluation/RelevancyEvaluator.java @@ -1,6 +1,6 @@ package org.springframework.ai.evaluation; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.Message; import org.springframework.ai.chat.messages.MessageType; @@ -31,14 +31,14 @@ public class RelevancyEvaluator implements Evaluator { private final ChatOptions chatOptions; - private ChatClient chatClient; + private ModelCall modelCall; - public RelevancyEvaluator(ChatClient chatClient) { - this(chatClient, ChatOptionsBuilder.builder().build()); + public RelevancyEvaluator(ModelCall modelCall) { + this(modelCall, ChatOptionsBuilder.builder().build()); } - public RelevancyEvaluator(ChatClient chatClient, ChatOptions chatOptions) { - this.chatClient = chatClient; + public RelevancyEvaluator(ModelCall modelCall, ChatOptions chatOptions) { + this.modelCall = modelCall; this.chatOptions = chatOptions; } @@ -52,7 +52,7 @@ public class RelevancyEvaluator implements Evaluator { Message message = promptTemplate .createMessage(Map.of("query", query, "response", response, "context", context)); - ChatResponse chatResponse = this.chatClient.call(new Prompt(message, this.chatOptions)); + ChatResponse chatResponse = this.modelCall.call(new Prompt(message, this.chatOptions)); var evaluationResponse = chatResponse.getResult().getOutput().getContent(); boolean passing = false; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java index f4cdd4ef8..2f7f59fa1 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java @@ -54,7 +54,7 @@ abstract class AbstractFunctionCallback implements Function, Functio /** * Constructs a new {@link AbstractFunctionCallback} with the given name, description, * input type and default object mapper. - * @param name Function name. Should be unique within the ChatClient's function + * @param name Function name. Should be unique within the ModelCall's function * registry. * @param description Function description. Used as a "system prompt" by the model to * decide if the function should be called. diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java index 146b35c47..7d65ea39c 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java @@ -24,32 +24,32 @@ import java.util.Set; public interface FunctionCallingOptions { /** - * Function Callbacks to be registered with the ChatClient. For Prompt Options the + * Function Callbacks to be registered with the ModelCall. For Prompt Options the * functionCallbacks are automatically enabled for the duration of the prompt * execution. For Default Options the FunctionCallbacks are registered but disabled by * default. You have to use "functions" property to list the function names from the - * ChatClient registry to be used in the chat completion requests. - * @return Return the Function Callbacks to be registered with the ChatClient. + * ModelCall registry to be used in the chat completion requests. + * @return Return the Function Callbacks to be registered with the ModelCall. */ List getFunctionCallbacks(); /** - * Set the Function Callbacks to be registered with the ChatClient. + * Set the Function Callbacks to be registered with the ModelCall. * @param functionCallbacks the Function Callbacks to be registered with the - * ChatClient. + * ModelCall. */ void setFunctionCallbacks(List functionCallbacks); /** - * @return List of function names from the ChatClient registry to be used in the next + * @return List of function names from the ModelCall registry to be used in the next * chat completion requests. */ Set getFunctions(); /** - * Set the list of function names from the ChatClient registry to be used in the next + * Set the list of function names from the ModelCall registry to be used in the next * chat completion requests. - * @param functions the list of function names from the ChatClient registry to be used + * @param functions the list of function names from the ModelCall registry to be used * in the next chat completion requests. */ void setFunctions(Set functions); diff --git a/spring-ai-core/src/main/java/org/springframework/ai/transformer/KeywordMetadataEnricher.java b/spring-ai-core/src/main/java/org/springframework/ai/transformer/KeywordMetadataEnricher.java index 67807e419..10bdbf0e7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/transformer/KeywordMetadataEnricher.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/transformer/KeywordMetadataEnricher.java @@ -18,7 +18,7 @@ package org.springframework.ai.transformer; import java.util.List; import java.util.Map; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentTransformer; import org.springframework.ai.chat.prompt.Prompt; @@ -43,18 +43,18 @@ public class KeywordMetadataEnricher implements DocumentTransformer { /** * Model predictor */ - private final ChatClient chatClient; + private final ModelCall modelCall; /** * The number of keywords to extract. */ private final int keywordCount; - public KeywordMetadataEnricher(ChatClient chatClient, int keywordCount) { - Assert.notNull(chatClient, "ChatClient must not be null"); + public KeywordMetadataEnricher(ModelCall modelCall, int keywordCount) { + Assert.notNull(modelCall, "ModelCall must not be null"); Assert.isTrue(keywordCount >= 1, "Document count must be >= 1"); - this.chatClient = chatClient; + this.modelCall = modelCall; this.keywordCount = keywordCount; } @@ -64,7 +64,7 @@ public class KeywordMetadataEnricher implements DocumentTransformer { var template = new PromptTemplate(String.format(KEYWORDS_TEMPLATE, keywordCount)); Prompt prompt = template.create(Map.of(CONTEXT_STR_PLACEHOLDER, document.getContent())); - String keywords = this.chatClient.call(prompt).getResult().getOutput().getContent(); + String keywords = this.modelCall.call(prompt).getResult().getOutput().getContent(); document.getMetadata().putAll(Map.of(EXCERPT_KEYWORDS_METADATA_KEY, keywords)); } return documents; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/transformer/SummaryMetadataEnricher.java b/spring-ai-core/src/main/java/org/springframework/ai/transformer/SummaryMetadataEnricher.java index e882ac497..10f4b171f 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/transformer/SummaryMetadataEnricher.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/transformer/SummaryMetadataEnricher.java @@ -20,7 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentTransformer; import org.springframework.ai.document.MetadataMode; @@ -62,7 +62,7 @@ public class SummaryMetadataEnricher implements DocumentTransformer { /** * AI client. */ - private final ChatClient chatClient; + private final ModelCall modelCall; /** * Number of documents from front to use for title extraction. @@ -76,16 +76,16 @@ public class SummaryMetadataEnricher implements DocumentTransformer { */ private final String summaryTemplate; - public SummaryMetadataEnricher(ChatClient chatClient, List summaryTypes) { - this(chatClient, summaryTypes, DEFAULT_SUMMARY_EXTRACT_TEMPLATE, MetadataMode.ALL); + public SummaryMetadataEnricher(ModelCall modelCall, List summaryTypes) { + this(modelCall, summaryTypes, DEFAULT_SUMMARY_EXTRACT_TEMPLATE, MetadataMode.ALL); } - public SummaryMetadataEnricher(ChatClient chatClient, List summaryTypes, String summaryTemplate, + public SummaryMetadataEnricher(ModelCall modelCall, List summaryTypes, String summaryTemplate, MetadataMode metadataMode) { - Assert.notNull(chatClient, "ChatClient must not be null"); + Assert.notNull(modelCall, "ModelCall must not be null"); Assert.hasText(summaryTemplate, "Summary template must not be empty"); - this.chatClient = chatClient; + this.modelCall = modelCall; this.summaryTypes = CollectionUtils.isEmpty(summaryTypes) ? List.of(SummaryType.CURRENT) : summaryTypes; this.metadataMode = metadataMode; this.summaryTemplate = summaryTemplate; @@ -101,7 +101,7 @@ public class SummaryMetadataEnricher implements DocumentTransformer { Prompt prompt = new PromptTemplate(this.summaryTemplate) .create(Map.of(CONTEXT_STR_PLACEHOLDER, documentContext)); - documentSummaries.add(this.chatClient.call(prompt).getResult().getOutput().getContent()); + documentSummaries.add(this.modelCall.call(prompt).getResult().getOutput().getContent()); } for (int i = 0; i < documentSummaries.size(); i++) { diff --git a/spring-ai-core/src/test/java/org/springframework/ai/chat/ChatClientTests.java b/spring-ai-core/src/test/java/org/springframework/ai/chat/ModelCallTests.java similarity index 96% rename from spring-ai-core/src/test/java/org/springframework/ai/chat/ChatClientTests.java rename to spring-ai-core/src/test/java/org/springframework/ai/chat/ModelCallTests.java index 28e4a528c..a036a7de6 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/chat/ChatClientTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/chat/ModelCallTests.java @@ -34,12 +34,12 @@ import org.springframework.ai.chat.messages.AssistantMessage; import org.springframework.ai.chat.prompt.Prompt; /** - * Unit Tests for {@link ChatClient}. + * Unit Tests for {@link ModelCall}. * * @author John Blum * @since 0.2.0 */ -class ChatClientTests { +class ModelCallTests { @Test void generateWithStringCallsGenerateWithPromptAndReturnsResponseCorrectly() { @@ -47,7 +47,7 @@ class ChatClientTests { String userMessage = "Zero Wing"; String responseMessage = "All your bases are belong to us"; - ChatClient mockClient = Mockito.mock(ChatClient.class); + ModelCall mockClient = Mockito.mock(ModelCall.class); AssistantMessage mockAssistantMessage = Mockito.mock(AssistantMessage.class); when(mockAssistantMessage.getContent()).thenReturn(responseMessage); diff --git a/spring-ai-core/src/test/java/org/springframework/ai/chat/memory/ChatMemoryTests.java b/spring-ai-core/src/test/java/org/springframework/ai/chat/memory/ChatMemoryTests.java index 741fd5341..f76584040 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/chat/memory/ChatMemoryTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/chat/memory/ChatMemoryTests.java @@ -25,7 +25,7 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.StreamingChatClient; @@ -48,7 +48,7 @@ import static org.mockito.Mockito.when; public class ChatMemoryTests { @Mock - ChatClient chatClient; + ModelCall modelCall; @Mock StreamingChatClient streamingChatClient; @@ -61,7 +61,7 @@ public class ChatMemoryTests { ChatMemory chatHistory = new InMemoryChatMemory(); - PromptTransformingChatService chatService = PromptTransformingChatService.builder(chatClient) + PromptTransformingChatService chatService = PromptTransformingChatService.builder(modelCall) .withRetrievers(List.of(ChatMemoryRetriever.builder().withChatHistory(chatHistory).build())) .withContentPostProcessors( List.of(new LastMaxTokenSizeContentTransformer(new JTokkitTokenCountEstimator(), 10))) @@ -77,7 +77,7 @@ public class ChatMemoryTests { ChatMemory chatHistory = new InMemoryChatMemory(); - PromptTransformingChatService chatService = PromptTransformingChatService.builder(chatClient) + PromptTransformingChatService chatService = PromptTransformingChatService.builder(modelCall) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withContentPostProcessors( List.of(new LastMaxTokenSizeContentTransformer(new JTokkitTokenCountEstimator(), 10))) @@ -90,7 +90,7 @@ public class ChatMemoryTests { public void chatClientUserMessages(PromptTransformingChatService chatService, ChatMemory chatHistory) { - when(chatClient.call(promptCaptor.capture())) + when(modelCall.call(promptCaptor.capture())) .thenReturn(new ChatResponse(List.of(new Generation("assistant:1")))) .thenReturn(new ChatResponse(List.of(new Generation("assistant:2")))) .thenReturn(new ChatResponse(List.of(new Generation("assistant:3")))); diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc index 3bdb84e10..b27482eed 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc @@ -2,7 +2,7 @@ link:https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html[Amazon Bedrock] is a managed service that provides foundation models from various AI providers, available through a unified API. -Spring AI supports https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[all the Chat and Embedding AI models] available through Amazon Bedrock by implementing the Spring interfaces `ChatClient`, `StreamingChatClient`, and `EmbeddingClient`. +Spring AI supports https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[all the Chat and Embedding AI models] available through Amazon Bedrock by implementing the Spring interfaces `ModelCall`, `StreamingChatClient`, and `EmbeddingClient`. Additionally, Spring AI provides Spring Auto-Configurations and Boot Starters for all clients, making it easy to bootstrap and configure for the Bedrock models. diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc index def68f7c2..c336fd72c 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc @@ -132,7 +132,7 @@ TIP: In addition to the model specific https://github.com/spring-projects/spring == Function Calling -You can register custom Java functions with the `AnthropicChatClient` and have the Anthropic Claude model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `AnthropicModelCall` and have the Anthropic Claude model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This is a powerful technique to connect the LLM capabilities with external tools and APIs. Read more about xref:api/chat/functions/anthropic-chat-functions.adoc[Anthropic Function Calling]. @@ -194,7 +194,7 @@ spring.ai.anthropic.chat.options.max-tokens=450 TIP: replace the `api-key` with your Anthropic credentials. -This will create a `AnthropicChatClient` implementation that you can inject into your class. +This will create a `AnthropicModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -224,7 +224,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatClient.java[AnthropicChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Anthropic service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatClient.java[AnthropicChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Anthropic service. Add the `spring-ai-anthropic` dependency to your project's Maven `pom.xml` file: @@ -247,7 +247,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -Next, create a `AnthropicChatClient` and use it for text generations: +Next, create a `AnthropicModelCall` and use it for text generations: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/azure-openai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/azure-openai-chat.adoc index 759aca404..3f3385241 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/azure-openai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/azure-openai-chat.adoc @@ -88,7 +88,7 @@ The prefix `spring.ai.azure.openai` is the property prefix to configure the conn | spring.ai.azure.openai.endpoint | The endpoint from the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | - |==== -The prefix `spring.ai.azure.openai.chat` is the property prefix that configures the `ChatClient` implementation for Azure OpenAI. +The prefix `spring.ai.azure.openai.chat` is the property prefix that configures the `ModelCall` implementation for Azure OpenAI. [cols="3,5,3"] |==== @@ -157,7 +157,7 @@ spring.ai.azure.openai.chat.options.temperature=0.7 TIP: replace the `api-key` and `endpoint` with your Azure OpenAI credentials. -This will create a `AzureOpenAiChatClient` implementation that you can inject into your class. +This will create a `AzureOpenAiModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. @@ -188,7 +188,7 @@ public class ChatController { == Manual Configuration -The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java[AzureOpenAiChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the link:https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Azure OpenAI Java Client]. +The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java[AzureOpenAiChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the link:https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Azure OpenAI Java Client]. To enable it, add the `spring-ai-azure-openai` dependency to your project's Maven `pom.xml` file: [source, xml] @@ -210,9 +210,9 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -TIP: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiChatClient`. For more information about the `AzureOpenAiChatClient` refer to the link:../chat/azure-openai-chat.html[Azure OpenAI Chat] section. +TIP: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiModelCall`. For more information about the `AzureOpenAiModelCall` refer to the link:../chat/azure-openai-chat.html[Azure OpenAI Chat] section. -Next, create an `AzureOpenAiChatClient` instance and use it to generate text responses: +Next, create an `AzureOpenAiModelCall` instance and use it to generate text responses: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic.adoc index d6fc03d60..2f4417da9 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic.adoc @@ -138,7 +138,7 @@ spring.ai.bedrock.anthropic.chat.options.top-k=15 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockAnthropicChatClient` implementation that you can inject into your class. +This will create a `BedrockAnthropicModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -168,7 +168,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java[BedrockAnthropicChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java[BedrockAnthropicChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic3.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic3.adoc index 3b4cd66af..2cb6e5b32 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic3.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-anthropic3.adoc @@ -179,7 +179,7 @@ spring.ai.bedrock.anthropic3.chat.options.top-k=15 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockAnthropicChatClient` implementation that you can inject into your class. +This will create a `BedrockAnthropicModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -209,7 +209,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClient.java[BedrockAnthropic3ChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatClient.java[BedrockAnthropic3ChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-cohere.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-cohere.adoc index 8133f3bc2..2f4b35ff4 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-cohere.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-cohere.adoc @@ -130,7 +130,7 @@ spring.ai.bedrock.cohere.chat.options.temperature=0.8 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockCohereChatClient` implementation that you can inject into your class. +This will create a `BedrockCohereModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -160,7 +160,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClient.java[BedrockCohereChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Bedrock Cohere service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/cohere/BedrockCohereChatClient.java[BedrockCohereChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Bedrock Cohere service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-jurassic2.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-jurassic2.adoc index cf7a083de..d29140537 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-jurassic2.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-jurassic2.adoc @@ -123,7 +123,7 @@ spring.ai.bedrock.jurassic2.chat.options.temperature=0.8 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockAi21Jurassic2ChatClient` implementation that you can inject into your class. +This will create a `BedrockAi21Jurassic2ModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -148,7 +148,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClient.java[BedrockAi21Jurassic2ChatClient] implements the `ChatClient` uses the <> to connect to the Bedrock Jurassic-2 service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatClient.java[BedrockAi21Jurassic2ChatClient] implements the `ModelCall` uses the <> to connect to the Bedrock Jurassic-2 service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-llama.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-llama.adoc index 435b71e47..05913fc28 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-llama.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-llama.adoc @@ -128,7 +128,7 @@ spring.ai.bedrock.llama.chat.options.temperature=0.8 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockLlamaChatClient` implementation that you can inject into your class. +This will create a `BedrockLlamaModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -158,7 +158,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClient.java[BedrockLlamaChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/llama/BedrockLlamaChatClient.java[BedrockLlamaChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Bedrock Anthropic service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-titan.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-titan.adoc index 38978fcfc..16a12e00c 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-titan.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/bedrock/bedrock-titan.adoc @@ -126,7 +126,7 @@ spring.ai.bedrock.titan.chat.options.temperature=0.8 TIP: replace the `regions`, `access-key` and `secret-key` with your AWS credentials. -This will create a `BedrockTitanChatClient` implementation that you can inject into your class. +This will create a `BedrockTitanModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -156,7 +156,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClient.java[BedrockTitanChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Bedrock Titanic service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanChatClient.java[BedrockTitanChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Bedrock Titanic service. Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/anthropic-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/anthropic-chat-functions.adoc index 3b4d9fcee..644531a5e 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/anthropic-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/anthropic-chat-functions.adoc @@ -1,6 +1,6 @@ = Anthropic Function Calling -You can register custom Java functions with the `AnthropicChatClient` and have the Anthropic models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `AnthropicModelCall` and have the Anthropic models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This allows you to connect the LLM capabilities with external tools and APIs. The `claude-3-opus`, `claude-3-sonnet` and `claude-3-haiku` link:https://docs.anthropic.com/claude/docs/tool-use#tool-use-best-practices-and-limitations[models are trained to detect when a function should be called] and to respond with JSON that adheres to the function signature. @@ -15,7 +15,7 @@ The `description` helps the model to understand when to call the function. As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results. -Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`. +Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ModelCall`. Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code. The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions. @@ -70,7 +70,7 @@ We start with describing the most POJO friendly options. In this approach you define `@Beans` in your application context as you would any other Spring managed object. -Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. +Internally, Spring AI `ModelCall` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. The name of the `@Bean` is passed as a `ChatOption`. @@ -136,7 +136,7 @@ static class Config { } ---- -It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `AnthropicChatClient`. +It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `AnthropicModelCall`. It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model. NOTE: By default, the response converter does a JSON serialization of the Response object. @@ -159,7 +159,7 @@ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), logger.info("Response: {}", response); ---- -// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling. +// NOTE: You can can have multiple functions registered in your `ModelCall` but only those enabled in the prompt request will be considered for the function calling. Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and produce the final response. @@ -187,5 +187,5 @@ NOTE: The in-prompt registered functions are enabled by default for the duration This approach allows to dynamically chose different functions to be called based on the user input. -The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `AnthropicChatClient` and use it in a prompt request. +The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `AnthropicModelCall` and use it in a prompt request. diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc index 755355a98..618c8e503 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc @@ -2,7 +2,7 @@ Function calling lets developers create a description of a function in their code, then pass that description to a language model in a request. The response from the model includes the name of a function that matches the description and the arguments to call it with. -You can register custom Java functions with the `AzureOpenAiChatClient` and have the model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `AzureOpenAiModelCall` and have the model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This allows you to connect the LLM capabilities with external tools and APIs. The Azure models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature. @@ -16,7 +16,7 @@ In general, the custom functions need to provide a function `name`, `description As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results. -Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`. +Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ModelCall`. Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code. The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions. @@ -70,7 +70,7 @@ We start with describing the most POJO friendly options. In this approach you define `@Beans` in your application context as you would any other Spring managed object. -Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. +Internally, Spring AI `ModelCall` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. The name of the `@Bean` is passed as a `ChatOption`. @@ -156,7 +156,7 @@ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), logger.info("Response: {}", response); ---- -// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling. +// NOTE: You can can have multiple functions registered in your `ModelCall` but only those enabled in the prompt request will be considered for the function calling. Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and the final response will be something like this: @@ -194,5 +194,5 @@ NOTE: The in-prompt registered functions are enabled by default for the duration This approach allows to dynamically chose different functions to be called based on the user input. -The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `AzureOpenAiChatClient` and use it in a prompt request. +The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `AzureOpenAiModelCall` and use it in a prompt request. diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/mistralai-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/mistralai-chat-functions.adoc index eb1184795..ad52c5a7d 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/mistralai-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/mistralai-chat-functions.adoc @@ -1,6 +1,6 @@ = Mistral AI Function Calling -You can register custom Java functions with the `MistralAiChatClient` and have the Mistral AI models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `MistralAiModelCall` and have the Mistral AI models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This allows you to connect the LLM capabilities with external tools and APIs. The `open-mixtral-8x22b`, `mistral_small_latest`, and `mistral_large_latest` models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature. @@ -15,7 +15,7 @@ The `description` helps the model to understand when to call the function. As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results. -Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`. +Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ModelCall`. Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code. The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions. @@ -70,7 +70,7 @@ We start with describing the most POJO friendly options. In this approach you define `@Beans` in your application context as you would any other Spring managed object. -Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. +Internally, Spring AI `ModelCall` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. The name of the `@Bean` is passed as a `ChatOption`. @@ -139,7 +139,7 @@ static class Config { } ---- -It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `MistralAiChatClient`. +It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `MistralAiModelCall`. It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model. NOTE: By default, the response converter does a JSON serialization of the Response object. @@ -162,7 +162,7 @@ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), logger.info("Response: {}", response); ---- -// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling. +// NOTE: You can can have multiple functions registered in your `ModelCall` but only those enabled in the prompt request will be considered for the function calling. Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and produce the final response. @@ -190,7 +190,7 @@ NOTE: The in-prompt registered functions are enabled by default for the duration This approach allows to dynamically chose different functions to be called based on the user input. -The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java[PaymentStatusPromptIT.java] integration test provides a complete example of how to register a function with the `MistralAiChatClient` and use it in a prompt request. +The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java[PaymentStatusPromptIT.java] integration test provides a complete example of how to register a function with the `MistralAiModelCall` and use it in a prompt request. == Appendices diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/openai-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/openai-chat-functions.adoc index 0d85e488c..f02ce8b48 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/openai-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/openai-chat-functions.adoc @@ -1,6 +1,6 @@ = Function Calling -You can register custom Java functions with the `OpenAiChatClient` and have the OpenAI model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `OpenAiModelCall` and have the OpenAI model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This allows you to connect the LLM capabilities with external tools and APIs. The OpenAI models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature. @@ -11,12 +11,12 @@ In general, the custom functions need to provide a function `name`, `descriptio As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results. -Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`. +Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ModelCall`. Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code. The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions. -// Additionally, the Auto-Configuration provides a way to auto-register any Function beans definition as function calling candidates in the `ChatClient`. +// Additionally, the Auto-Configuration provides a way to auto-register any Function beans definition as function calling candidates in the `ModelCall`. == How it works @@ -71,7 +71,7 @@ We start with describing the most POJO friendly options. In this approach you define `@Beans` in your application context as you would any other Spring managed object. -Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. +Internally, Spring AI `ModelCall` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. The name of the `@Bean` is passed as a `ChatOption`. @@ -136,7 +136,7 @@ static class Config { } ---- -It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `OpenAiChatClient`. +It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `OpenAiModelCall`. It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model. NOTE: By default, the response converter does a JSON serialization of the Response object. @@ -159,7 +159,7 @@ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), logger.info("Response: {}", response); ---- -// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling. +// NOTE: You can can have multiple functions registered in your `ModelCall` but only those enabled in the prompt request will be considered for the function calling. Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and the final response will be something like this: @@ -197,11 +197,11 @@ NOTE: The in-prompt registered functions are enabled by default for the duration This approach allows to dynamically chose different functions to be called based on the user input. -The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java[FunctionCallbackInPromptIT.java] integration test provides a complete example of how to register a function with the `OpenAiChatClient` and use it in a prompt request. +The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java[FunctionCallbackInPromptIT.java] integration test provides a complete example of how to register a function with the `OpenAiModelCall` and use it in a prompt request. // // === Register Functions with Default Options // -// You can programmatically register functions with the `OpenAiChatClient` using the `OpenAiChatOptions#withFunctionCallbacks`: +// You can programmatically register functions with the `OpenAiModelCall` using the `OpenAiChatOptions#withFunctionCallbacks`: // // [source,java] // ---- @@ -215,7 +215,7 @@ The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot // new MockWeatherService()))) // function code // .build(); // -// OpenAiChatClient chatClient = new OpenAiChatClient(openaiApi, defaultOptions); +// OpenAiModelCall chatClient = new OpenAiModelCall(openaiApi, defaultOptions); // // UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); // @@ -223,7 +223,7 @@ The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot // OpenAiChatOptions.builder().withFunction("CurrentWeather").build())); // Enable the function // ---- // -// NOTE: Functions are registered when OpenAiChatClient is created, by you must enable in the Prompt the functions to be used in the request. +// NOTE: Functions are registered when OpenAiModelCall is created, by you must enable in the Prompt the functions to be used in the request. == Appendices: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/vertexai-gemini-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/vertexai-gemini-chat-functions.adoc index a464ccf51..e6291ccf7 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/vertexai-gemini-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/vertexai-gemini-chat-functions.adoc @@ -6,7 +6,7 @@ The parallel function calling is gone as well. Function calling lets developers create a description of a function in their code, then pass that description to a language model in a request. The response from the model includes the name of a function that matches the description and the arguments to call it with. -You can register custom Java functions with the `VertexAiGeminiChatClient` and have the Gemini Pro model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. +You can register custom Java functions with the `VertexAiGeminiModelCall` and have the Gemini Pro model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions. This allows you to connect the LLM capabilities with external tools and APIs. The VertexAI Gemini Pro model is trained to detect when a function should be called and to respond with JSON that adheres to the function signature. @@ -18,12 +18,12 @@ In general, the custom functions need to provide a function `name`, `description As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results. -Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`. +Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ModelCall`. Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code. The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions. -// Additionally, the Auto-Configuration provides a way to auto-register any Function beans definition as function calling candidates in the `ChatClient`. +// Additionally, the Auto-Configuration provides a way to auto-register any Function beans definition as function calling candidates in the `ModelCall`. == How it works @@ -74,7 +74,7 @@ We start with describing the most POJO friendly options. In this approach you define `@Beans` in your application context as you would any other Spring managed object. -Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. +Internally, Spring AI `ModelCall` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model. The name of the `@Bean` is passed as a `ChatOption`. @@ -139,7 +139,7 @@ static class Config { } ---- -It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `VertexAiGeminiChatClient`. +It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `VertexAiGeminiModelCall`. It also provides a description (2) and sets the Schema type to Open API type (3). NOTE: The default response converter does a JSON serialization of the Response object. @@ -162,7 +162,7 @@ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), logger.info("Response: {}", response); ---- -// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling. +// NOTE: You can can have multiple functions registered in your `ModelCall` but only those enabled in the prompt request will be considered for the function calling. Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and the final response will be something like this: @@ -201,5 +201,5 @@ NOTE: The in-prompt registered functions are enabled by default for the duration This approach allows to dynamically chose different functions to be called based on the user input. -The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/gemini/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `VertexAiGeminiChatClient` and use it in a prompt request. +The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/gemini/tool/FunctionCallWithPromptFunctionIT.java[FunctionCallWithPromptFunctionIT.java] integration test provides a complete example of how to register a function with the `VertexAiGeminiModelCall` and use it in a prompt request. diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/mistralai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/mistralai-chat.adoc index 26fb6afee..fcdfde183 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/mistralai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/mistralai-chat.adoc @@ -103,7 +103,7 @@ The prefix `spring.ai.mistralai.chat` is the property prefix that lets you confi | spring.ai.mistralai.chat.options.functionCallbacks | MistralAI Tool Function Callbacks to register with the ChatClient. | - |==== -NOTE: You can override the common `spring.ai.mistralai.base-url` and `spring.ai.mistralai.api-key` for the `ChatClient` and `EmbeddingClient` implementations. +NOTE: You can override the common `spring.ai.mistralai.base-url` and `spring.ai.mistralai.api-key` for the `ModelCall` and `EmbeddingClient` implementations. The `spring.ai.mistralai.chat.base-url` and `spring.ai.mistralai.chat.api-key` properties if set take precedence over the common properties. This is useful if you want to use different MistralAI accounts for different models and different model endpoints. @@ -153,7 +153,7 @@ spring.ai.mistralai.chat.options.temperature=0.7 TIP: replace the `api-key` with your OpenAI credentials. -This will create a `MistralAiChatClient` implementation that you can inject into your class. +This will create a `MistralAiModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -183,7 +183,7 @@ public class ChatController { == Manual Configuration -The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java[MistralAiChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the MistralAI service. +The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java[MistralAiChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the MistralAI service. Add the `spring-ai-mistral-ai` dependency to your project's Maven `pom.xml` file: @@ -206,7 +206,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -Next, create a `MistralAiChatClient` and use it for text generations: +Next, create a `MistralAiModelCall` and use it for text generations: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc index 0fb32b997..968abca53 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc @@ -1,7 +1,7 @@ = Ollama Chat With https://ollama.ai/[Ollama] you can run various Large Language Models (LLMs) locally and generate text from them. -Spring AI supports the Ollama text generation with `OllamaChatClient`. +Spring AI supports the Ollama text generation with `OllamaModelCall`. == Prerequisites @@ -185,7 +185,7 @@ spring.ai.ollama.chat.options.temperature=0.7 TIP: replace the `base-url` with your Ollama server URL. -This will create a `OllamaChatClient` implementation that you can inject into your class. +This will create a `OllamaModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -216,8 +216,8 @@ public class ChatController { == Manual Configuration -If you don't want to use the Spring Boot auto-configuration, you can manually configure the `OllamaChatClient` in your application. -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java[OllamaChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the Ollama service. +If you don't want to use the Spring Boot auto-configuration, you can manually configure the `OllamaModelCall` in your application. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaChatClient.java[OllamaChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the Ollama service. To use it add the `spring-ai-ollama` dependency to your project's Maven `pom.xml` file: @@ -243,7 +243,7 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man TIP: The `spring-ai-ollama` dependency provides access also to the `OllamaEmbeddingClient`. For more information about the `OllamaEmbeddingClient` refer to the link:../embeddings/ollama-embeddings.html[Ollama Embedding Client] section. -Next, create an `OllamaChatClient` instance and use it to text generations requests: +Next, create an `OllamaModelCall` instance and use it to text generations requests: [source,java] ---- @@ -274,7 +274,7 @@ image::ollama-chat-completion-api.jpg[OllamaApi Chat Completion API Diagram, 800 Here is a simple snippet showing how to use the API programmatically: -NOTE: The `OllamaApi` is low level api and is not recommended for direct use. Use the `OllamaChatClient` instead. +NOTE: The `OllamaApi` is low level api and is not recommended for direct use. Use the `OllamaModelCall` instead. [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc index 440a4a6b6..6567738ad 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc @@ -107,7 +107,7 @@ The prefix `spring.ai.openai.chat` is the property prefix that lets you configur | spring.ai.openai.chat.options.functions | List of functions, identified by their names, to enable for function calling in a single prompt requests. Functions with those names must exist in the functionCallbacks registry. | - |==== -NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatClient` and `EmbeddingClient` implementations. +NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ModelCall` and `EmbeddingClient` implementations. The `spring.ai.openai.chat.base-url` and `spring.ai.openai.chat.api-key` properties if set take precedence over the common properties. This is useful if you want to use different OpenAI accounts for different models and different model endpoints. @@ -209,7 +209,7 @@ spring.ai.openai.chat.options.temperature=0.7 TIP: replace the `api-key` with your OpenAI credentials. -This will create a `OpenAiChatClient` implementation that you can inject into your class. +This will create a `OpenAiModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -239,7 +239,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatClient.java[OpenAiChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the OpenAI service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatClient.java[OpenAiChatClient] implements the `ModelCall` and `StreamingChatClient` and uses the <> to connect to the OpenAI service. Add the `spring-ai-openai` dependency to your project's Maven `pom.xml` file: @@ -262,7 +262,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -Next, create a `OpenAiChatClient` and use it for text generations: +Next, create a `OpenAiModelCall` and use it for text generations: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc index ecf11add0..0694a4060 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc @@ -151,7 +151,7 @@ spring.ai.vertex.ai.gemini.chat.options.temperature=0.5 TIP: replace the `api-key` with your VertexAI credentials. -This will create a `VertexAiGeminiChatClient` implementation that you can inject into your class. +This will create a `VertexAiGeminiModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -181,7 +181,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java[VertexAiGeminiChatClient] implements the `ChatClient` and uses the `VertexAI` to connect to the Vertex AI Gemini service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java[VertexAiGeminiChatClient] implements the `ModelCall` and uses the `VertexAI` to connect to the Vertex AI Gemini service. Add the `spring-ai-vertex-ai-gemini` dependency to your project's Maven `pom.xml` file: @@ -204,7 +204,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -Next, create a `VertexAiGeminiChatClient` and use it for text generations: +Next, create a `VertexAiGeminiModelCall` and use it for text generations: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-palm2-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-palm2-chat.adoc index 045df41e2..f576bca15 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-palm2-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-palm2-chat.adoc @@ -114,7 +114,7 @@ spring.ai.vertex.ai.chat.options.temperature=0.5 TIP: replace the `api-key` with your VertexAI credentials. -This will create a `VertexAiPaLm2ChatClient` implementation that you can inject into your class. +This will create a `VertexAiPaLm2ModelCall` implementation that you can inject into your class. Here is an example of a simple `@Controller` class that uses the chat client for text generations. [source,java] @@ -144,7 +144,7 @@ public class ChatController { == Manual Configuration -The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/vertexai/paml2/VertexAiPaLm2ChatClient.java[VertexAiPaLm2ChatClient] implements the `ChatClient` and uses the <> to connect to the VertexAI service. +The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/vertexai/paml2/VertexAiPaLm2ChatClient.java[VertexAiPaLm2ChatClient] implements the `ModelCall` and uses the <> to connect to the VertexAI service. Add the `spring-ai-vertex-ai-palm2` dependency to your project's Maven `pom.xml` file: @@ -167,7 +167,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -Next, create a `VertexAiPaLm2ChatClient` and use it for text generations: +Next, create a `VertexAiPaLm2ModelCall` and use it for text generations: [source,java] ---- diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/watsonx-ai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/watsonx-ai-chat.adoc index 79ce3d8d9..c099cac36 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/watsonx-ai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/watsonx-ai-chat.adoc @@ -1,7 +1,7 @@ = watsonx.ai Chat With https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/overview-wx.html?context=wx&audience=wdp[watsonx.ai] you can run various Large Language Models (LLMs) locally and generate text from them. -Spring AI supports the watsonx.ai text generation with `WatsonxAiChatClient`. +Spring AI supports the watsonx.ai text generation with `WatsonxAiModelCall`. == Prerequisites diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatclient.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatclient.adoc index 42f7857a5..00aa5757f 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatclient.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatclient.adoc @@ -47,7 +47,7 @@ public interface StreamingChatClient extends StreamingModelClient { == Available Implementations -The `ChatClient` and `StreamingChatClient` implementations are provided for the following Model providers: +The `ModelCall` and `StreamingChatClient` implementations are provided for the following Model providers: image::spring-ai-chat-completions-clients.jpg[align="center", width="800px"] diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/azure-openai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/azure-openai-embeddings.adoc index 402e6f0c2..a59fed53a 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/azure-openai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/azure-openai-embeddings.adoc @@ -155,7 +155,7 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -NOTE: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiEmbeddingClient`. For more information about the `AzureOpenAiChatClient` refer to the link:../embeddings/azure-openai-embeddings.html[Azure OpenAI Embeddings] section. +NOTE: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiEmbeddingClient`. For more information about the `AzureOpenAiModelCall` refer to the link:../embeddings/azure-openai-embeddings.html[Azure OpenAI Embeddings] section. Next, create an `AzureOpenAiEmbeddingClient` instance and use it to compute the similarity between two input texts: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc index 57d8c19db..d593596fc 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc @@ -94,7 +94,7 @@ The prefix `spring.ai.mistralai.embedding` is property prefix that configures th | spring.ai.mistralai.embedding.options.encodingFormat | The format to return the embeddings in. Can be either float or base64. | - |==== -NOTE: You can override the common `spring.ai.mistralai.base-url` and `spring.ai.mistralai.api-key` for the `ChatClient` and `EmbeddingClient` implementations. +NOTE: You can override the common `spring.ai.mistralai.base-url` and `spring.ai.mistralai.api-key` for the `ModelCall` and `EmbeddingClient` implementations. The `spring.ai.mistralai.embedding.base-url` and `spring.ai.mistralai.embedding.api-key` properties if set take precedence over the common properties. Similarly, the `spring.ai.mistralai.embedding.base-url` and `spring.ai.mistralai.embedding.api-key` properties if set take precedence over the common properties. This is useful if you want to use different MistralAI accounts for different models and different model endpoints. @@ -175,8 +175,8 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -NOTE: The `spring-ai-mistral-ai` dependency provides access also to the `MistralAiChatClient`. -For more information about the `MistralAiChatClient` refer to the link:../chat/mistralai-chat.html[MistralAI Chat Client] section. +NOTE: The `spring-ai-mistral-ai` dependency provides access also to the `MistralAiModelCall`. +For more information about the `MistralAiModelCall` refer to the link:../chat/mistralai-chat.html[MistralAI Chat Client] section. Next, create an `MistralAiEmbeddingClient` instance and use it to compute the similarity between two input texts: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/ollama-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/ollama-embeddings.adoc index 386051e71..0a22f9ecd 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/ollama-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/ollama-embeddings.adoc @@ -177,8 +177,8 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -NOTE: The `spring-ai-ollama` dependency provides access also to the `OllamaChatClient`. -For more information about the `OllamaChatClient` refer to the link:../chat/ollama-chat.html[Ollama Chat Client] section. +NOTE: The `spring-ai-ollama` dependency provides access also to the `OllamaModelCall`. +For more information about the `OllamaModelCall` refer to the link:../chat/ollama-chat.html[Ollama Chat Client] section. Next, create an `OllamaEmbeddingClient` instance and use it to compute the similarity between two input texts: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc index 75a0d45f3..6bd0bde34 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc @@ -97,7 +97,7 @@ The prefix `spring.ai.openai.embedding` is property prefix that configures the ` | spring.ai.openai.embedding.options.dimensions | The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models. | - |==== -NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatClient` and `EmbeddingClient` implementations. +NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ModelCall` and `EmbeddingClient` implementations. The `spring.ai.openai.embedding.base-url` and `spring.ai.openai.embedding.api-key` properties if set take precedence over the common properties. Similarly, the `spring.ai.openai.embedding.base-url` and `spring.ai.openai.embedding.api-key` properties if set take precedence over the common properties. This is useful if you want to use different OpenAI accounts for different models and different model endpoints. @@ -178,8 +178,8 @@ dependencies { TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file. -NOTE: The `spring-ai-openai` dependency provides access also to the `OpenAiChatClient`. -For more information about the `OpenAiChatClient` refer to the link:../chat/openai-chat.html[OpenAI Chat Client] section. +NOTE: The `spring-ai-openai` dependency provides access also to the `OpenAiModelCall`. +For more information about the `OpenAiModelCall` refer to the link:../chat/openai-chat.html[OpenAI Chat Client] section. Next, create an `OpenAiEmbeddingClient` instance and use it to compute the similarity between two input texts: diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc index 96fab52f4..a66971270 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc @@ -11,7 +11,7 @@ Another analogy is a SQL statement that contain placeholders for certain express As Spring AI evolves, it will introduce higher levels of abstraction for interacting with AI models. The foundational classes described in this section can be likened to JDBC in terms of their role and functionality. -The `ChatClient` class, for instance, is analogous to the core JDBC library in the JDK. +The `ModelCall` class, for instance, is analogous to the core JDBC library in the JDK. Building upon this, Spring AI can provide helper classes similar to `JdbcTemplate`, Spring Data Repositories, and eventually, more advanced constructs like ChatEngines and Agents that consider past interactions with the model. The structure of prompts has evolved over time within the AI field. @@ -24,7 +24,7 @@ OpenAI have introduced even more structure to prompts by categorizing multiple m === Prompt -It is common to use the `call` method of `ChatClient` that takes a `Prompt` instance and returns an `ChatResponse`. +It is common to use the `call` method of `ModelCall` that takes a `Prompt` instance and returns an `ChatResponse`. The Prompt class functions as a container for an organized series of Message objects, with each one forming a segment of the overall prompt. Every Message embodies a unique role within the prompt, differing in its content and intent. diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/hana.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/hana.adoc index 182356e7c..a011c5009 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/hana.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/hana.adoc @@ -226,7 +226,7 @@ public class CricketWorldCupRepository implements HanaVectorRepositoryimage `ImageClient` implementations. Then `StabilityAiImageOptions` and `OpenAiImageOptions` provide the options specific to each model provider. All options classes are created via a fluent API builder all can be passed into the portable `ImageClient` API. These option data types are using in autoconfiguration/configuration properties for the `ImageClient` implementations. +* A new "portable options" design pattern. We wanted to provide as much portability in the `ModelCall` as possible across different chat based AI Models. There is a common set of generation options and then those that are specific to a model provider. A sort of "duck typing" approach is used. `ModelOptions` in the model package is a marker interface indicating implementations of this class will provide the options for a model. See `ImageOptions`, a subinterface that defines portable options across all text->image `ImageClient` implementations. Then `StabilityAiImageOptions` and `OpenAiImageOptions` provide the options specific to each model provider. All options classes are created via a fluent API builder all can be passed into the portable `ImageClient` API. These option data types are using in autoconfiguration/configuration properties for the `ImageClient` implementations. === January 13, 2024 Update @@ -79,7 +79,7 @@ Merge SimplePersistentVectorStore and InMemoryVectorStore into SimpleVectorStore Refactor the Ollama client and related classes and package names -* Replace the org.springframework.ai.ollama.client.OllamaClient by org.springframework.ai.ollama.OllamaChatClient. +* Replace the org.springframework.ai.ollama.client.OllamaClient by org.springframework.ai.ollama.OllamaModelCall. * The OllamaChatClient method signatures have changed. * Rename the org.springframework.ai.autoconfigure.ollama.OllamaProperties into org.springframework.ai.autoconfigure.ollama.OllamaChatProperties and change the suffix to: `spring.ai.ollama.chat`. Some of the properties have changed as well. diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfiguration.java index e94598a8d..cd184ff31 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.ai.autoconfigure.anthropic; import java.util.List; -import org.springframework.ai.anthropic.AnthropicChatClient; +import org.springframework.ai.anthropic.AnthropicModelCall; import org.springframework.ai.anthropic.api.AnthropicApi; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.ai.model.function.FunctionCallback; @@ -57,7 +57,7 @@ public class AnthropicAutoConfiguration { @Bean @ConditionalOnMissingBean - public AnthropicChatClient anthropicChatClient(AnthropicApi anthropicApi, AnthropicChatProperties chatProperties, + public AnthropicModelCall anthropicChatClient(AnthropicApi anthropicApi, AnthropicChatProperties chatProperties, RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext, List toolFunctionCallbacks) { @@ -65,7 +65,7 @@ public class AnthropicAutoConfiguration { chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks); } - return new AnthropicChatClient(anthropicApi, chatProperties.getOptions(), retryTemplate, + return new AnthropicModelCall(anthropicApi, chatProperties.getOptions(), retryTemplate, functionCallbackContext); } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicChatProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicChatProperties.java index d9cdc0565..2f89076a5 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicChatProperties.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/anthropic/AnthropicChatProperties.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.anthropic; -import org.springframework.ai.anthropic.AnthropicChatClient; +import org.springframework.ai.anthropic.AnthropicModelCall; import org.springframework.ai.anthropic.AnthropicChatOptions; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -43,9 +43,9 @@ public class AnthropicChatProperties { */ @NestedConfigurationProperty private AnthropicChatOptions options = AnthropicChatOptions.builder() - .withModel(AnthropicChatClient.DEFAULT_MODEL_NAME) - .withMaxTokens(AnthropicChatClient.DEFAULT_MAX_TOKENS) - .withTemperature(AnthropicChatClient.DEFAULT_TEMPERATURE) + .withModel(AnthropicModelCall.DEFAULT_MODEL_NAME) + .withMaxTokens(AnthropicModelCall.DEFAULT_MAX_TOKENS) + .withTemperature(AnthropicModelCall.DEFAULT_TEMPERATURE) .build(); public AnthropicChatOptions getOptions() { diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/azure/openai/AzureOpenAiAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/azure/openai/AzureOpenAiAutoConfiguration.java index a9b13e304..009909874 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/azure/openai/AzureOpenAiAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/azure/openai/AzureOpenAiAutoConfiguration.java @@ -22,7 +22,7 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.ClientOptions; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingClient; import org.springframework.ai.model.function.FunctionCallback; import org.springframework.ai.model.function.FunctionCallbackContext; @@ -37,7 +37,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @AutoConfiguration -@ConditionalOnClass({ OpenAIClientBuilder.class, AzureOpenAiChatClient.class }) +@ConditionalOnClass({ OpenAIClientBuilder.class, AzureOpenAiModelCall.class }) @EnableConfigurationProperties({ AzureOpenAiChatProperties.class, AzureOpenAiEmbeddingProperties.class, AzureOpenAiConnectionProperties.class }) public class AzureOpenAiAutoConfiguration { @@ -58,7 +58,7 @@ public class AzureOpenAiAutoConfiguration { @Bean @ConditionalOnProperty(prefix = AzureOpenAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public AzureOpenAiChatClient azureOpenAiChatClient(OpenAIClient openAIClient, + public AzureOpenAiModelCall azureOpenAiChatClient(OpenAIClient openAIClient, AzureOpenAiChatProperties chatProperties, List toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext) { @@ -66,8 +66,8 @@ public class AzureOpenAiAutoConfiguration { chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks); } - AzureOpenAiChatClient azureOpenAiChatClient = new AzureOpenAiChatClient(openAIClient, - chatProperties.getOptions(), functionCallbackContext); + AzureOpenAiModelCall azureOpenAiChatClient = new AzureOpenAiModelCall(openAIClient, chatProperties.getOptions(), + functionCallbackContext); return azureOpenAiChatClient; } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfiguration.java index 7b3d4d2d5..1073bdafe 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.ai.autoconfigure.bedrock.anthropic; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.anthropic.BedrockAnthropicChatClient; +import org.springframework.ai.bedrock.anthropic.BedrockAnthropicModelCall; import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -59,9 +59,9 @@ public class BedrockAnthropicChatAutoConfiguration { @Bean @ConditionalOnBean(AnthropicChatBedrockApi.class) - public BedrockAnthropicChatClient anthropicChatClient(AnthropicChatBedrockApi anthropicApi, + public BedrockAnthropicModelCall anthropicChatClient(AnthropicChatBedrockApi anthropicApi, BedrockAnthropicChatProperties properties) { - return new BedrockAnthropicChatClient(anthropicApi, properties.getOptions()); + return new BedrockAnthropicModelCall(anthropicApi, properties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfiguration.java index 60e5cdce6..116303352 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.ai.autoconfigure.bedrock.anthropic3; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.anthropic3.BedrockAnthropic3ChatClient; +import org.springframework.ai.bedrock.anthropic3.BedrockAnthropic3ModelCall; import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -59,9 +59,9 @@ public class BedrockAnthropic3ChatAutoConfiguration { @Bean @ConditionalOnBean(Anthropic3ChatBedrockApi.class) - public BedrockAnthropic3ChatClient anthropic3ChatClient(Anthropic3ChatBedrockApi anthropicApi, + public BedrockAnthropic3ModelCall anthropic3ChatClient(Anthropic3ChatBedrockApi anthropicApi, BedrockAnthropic3ChatProperties properties) { - return new BedrockAnthropic3ChatClient(anthropicApi, properties.getOptions()); + return new BedrockAnthropic3ModelCall(anthropicApi, properties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfiguration.java index 66b6d5e5e..eeb6a913e 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.ai.autoconfigure.bedrock.cohere; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.cohere.BedrockCohereChatClient; +import org.springframework.ai.bedrock.cohere.BedrockCohereModelCall; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -57,10 +57,10 @@ public class BedrockCohereChatAutoConfiguration { @Bean @ConditionalOnBean(CohereChatBedrockApi.class) - public BedrockCohereChatClient cohereChatClient(CohereChatBedrockApi cohereChatApi, + public BedrockCohereModelCall cohereChatClient(CohereChatBedrockApi cohereChatApi, BedrockCohereChatProperties properties) { - return new BedrockCohereChatClient(cohereChatApi, properties.getOptions()); + return new BedrockCohereModelCall(cohereChatApi, properties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/jurrasic2/BedrockAi21Jurassic2ChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/jurrasic2/BedrockAi21Jurassic2ChatAutoConfiguration.java index e8266a0e4..dc934c09e 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/jurrasic2/BedrockAi21Jurassic2ChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/jurrasic2/BedrockAi21Jurassic2ChatAutoConfiguration.java @@ -19,7 +19,7 @@ package org.springframework.ai.autoconfigure.bedrock.jurrasic2; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ChatClient; +import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ModelCall; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -59,10 +59,10 @@ public class BedrockAi21Jurassic2ChatAutoConfiguration { @Bean @ConditionalOnBean(Ai21Jurassic2ChatBedrockApi.class) - public BedrockAi21Jurassic2ChatClient jurassic2ChatClient(Ai21Jurassic2ChatBedrockApi ai21Jurassic2ChatBedrockApi, + public BedrockAi21Jurassic2ModelCall jurassic2ChatClient(Ai21Jurassic2ChatBedrockApi ai21Jurassic2ChatBedrockApi, BedrockAi21Jurassic2ChatProperties properties) { - return BedrockAi21Jurassic2ChatClient.builder(ai21Jurassic2ChatBedrockApi) + return BedrockAi21Jurassic2ModelCall.builder(ai21Jurassic2ChatBedrockApi) .withOptions(properties.getOptions()) .build(); } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfiguration.java index 9293acc84..bd36674cc 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfiguration.java @@ -16,12 +16,12 @@ package org.springframework.ai.autoconfigure.bedrock.llama; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.ai.bedrock.llama.BedrockLlamaModelCall; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.regions.providers.AwsRegionProvider; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.llama.BedrockLlamaChatClient; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -59,9 +59,9 @@ public class BedrockLlamaChatAutoConfiguration { @Bean @ConditionalOnBean(LlamaChatBedrockApi.class) - public BedrockLlamaChatClient llamaChatClient(LlamaChatBedrockApi llamaApi, BedrockLlamaChatProperties properties) { + public BedrockLlamaModelCall llamaChatClient(LlamaChatBedrockApi llamaApi, BedrockLlamaChatProperties properties) { - return new BedrockLlamaChatClient(llamaApi, properties.getOptions()); + return new BedrockLlamaModelCall(llamaApi, properties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfiguration.java index 67995b9e3..9e59c5243 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.ai.autoconfigure.bedrock.titan; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionConfiguration; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.titan.BedrockTitanChatClient; +import org.springframework.ai.bedrock.titan.BedrockTitanModelCall; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -57,10 +57,10 @@ public class BedrockTitanChatAutoConfiguration { @Bean @ConditionalOnBean(TitanChatBedrockApi.class) - public BedrockTitanChatClient titanChatClient(TitanChatBedrockApi titanChatApi, + public BedrockTitanModelCall titanChatClient(TitanChatBedrockApi titanChatApi, BedrockTitanChatProperties properties) { - return new BedrockTitanChatClient(titanChatApi, properties.getOptions()); + return new BedrockTitanModelCall(titanChatApi, properties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/huggingface/HuggingfaceChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/huggingface/HuggingfaceChatAutoConfiguration.java index 42c3b1e73..72b1ca584 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/huggingface/HuggingfaceChatAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/huggingface/HuggingfaceChatAutoConfiguration.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.huggingface; -import org.springframework.ai.huggingface.HuggingfaceChatClient; +import org.springframework.ai.huggingface.HuggingfaceModelCall; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; @AutoConfiguration -@ConditionalOnClass(HuggingfaceChatClient.class) +@ConditionalOnClass(HuggingfaceModelCall.class) @EnableConfigurationProperties(HuggingfaceChatProperties.class) public class HuggingfaceChatAutoConfiguration { @@ -32,8 +32,8 @@ public class HuggingfaceChatAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnProperty(prefix = HuggingfaceChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public HuggingfaceChatClient huggingfaceChatClient(HuggingfaceChatProperties huggingfaceChatProperties) { - return new HuggingfaceChatClient(huggingfaceChatProperties.getApiKey(), huggingfaceChatProperties.getUrl()); + public HuggingfaceModelCall huggingfaceChatClient(HuggingfaceChatProperties huggingfaceChatProperties) { + return new HuggingfaceModelCall(huggingfaceChatProperties.getApiKey(), huggingfaceChatProperties.getUrl()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfiguration.java index 1328f3488..78ec9ed69 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.ai.autoconfigure.mistralai; import java.util.List; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; -import org.springframework.ai.mistralai.MistralAiChatClient; +import org.springframework.ai.mistralai.MistralAiModelCall; import org.springframework.ai.mistralai.MistralAiEmbeddingClient; import org.springframework.ai.mistralai.api.MistralAiApi; import org.springframework.ai.model.function.FunctionCallback; @@ -69,7 +69,7 @@ public class MistralAiAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnProperty(prefix = MistralAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public MistralAiChatClient mistralAiChatClient(MistralAiCommonProperties commonProperties, + public MistralAiModelCall mistralAiChatClient(MistralAiCommonProperties commonProperties, MistralAiChatProperties chatProperties, RestClient.Builder restClientBuilder, List toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext, RetryTemplate retryTemplate, ResponseErrorHandler responseErrorHandler) { @@ -81,7 +81,7 @@ public class MistralAiAutoConfiguration { chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks); } - return new MistralAiChatClient(mistralAiApi, chatProperties.getOptions(), functionCallbackContext, + return new MistralAiModelCall(mistralAiApi, chatProperties.getOptions(), functionCallbackContext, retryTemplate); } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.java index 8b788e73b..17c2dd066 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.ollama; -import org.springframework.ai.ollama.OllamaChatClient; +import org.springframework.ai.ollama.OllamaModelCall; import org.springframework.ai.ollama.OllamaEmbeddingClient; import org.springframework.ai.ollama.api.OllamaApi; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -56,8 +56,8 @@ public class OllamaAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnProperty(prefix = OllamaChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public OllamaChatClient ollamaChatClient(OllamaApi ollamaApi, OllamaChatProperties properties) { - return new OllamaChatClient(ollamaApi, properties.getOptions()); + public OllamaModelCall ollamaChatClient(OllamaApi ollamaApi, OllamaChatProperties properties) { + return new OllamaModelCall(ollamaApi, properties.getOptions()); } @Bean diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.java index 848456468..0b6fa829d 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.java @@ -20,11 +20,8 @@ import java.util.List; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.ai.model.function.FunctionCallback; import org.springframework.ai.model.function.FunctionCallbackContext; -import org.springframework.ai.openai.OpenAiAudioTranscriptionClient; -import org.springframework.ai.openai.OpenAiChatClient; -import org.springframework.ai.openai.OpenAiEmbeddingClient; -import org.springframework.ai.openai.OpenAiImageClient; -import org.springframework.ai.openai.OpenAiAudioSpeechClient; +import org.springframework.ai.openai.*; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.api.OpenAiApi; import org.springframework.ai.openai.api.OpenAiAudioApi; import org.springframework.ai.openai.api.OpenAiImageApi; @@ -57,7 +54,7 @@ public class OpenAiAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnProperty(prefix = OpenAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public OpenAiChatClient openAiChatClient(OpenAiConnectionProperties commonProperties, + public OpenAiModelCall openAiChatClient(OpenAiConnectionProperties commonProperties, OpenAiChatProperties chatProperties, RestClient.Builder restClientBuilder, List toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext, RetryTemplate retryTemplate, ResponseErrorHandler responseErrorHandler) { @@ -69,7 +66,7 @@ public class OpenAiAutoConfiguration { chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks); } - return new OpenAiChatClient(openAiApi, chatProperties.getOptions(), functionCallbackContext, retryTemplate); + return new OpenAiModelCall(openAiApi, chatProperties.getOptions(), functionCallbackContext, retryTemplate); } @Bean diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfiguration.java index 12dfb8134..adad10a6e 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfiguration.java @@ -24,7 +24,7 @@ import com.google.cloud.vertexai.VertexAI; import org.springframework.ai.model.function.FunctionCallback; import org.springframework.ai.model.function.FunctionCallbackContext; import org.springframework.ai.model.function.FunctionCallbackWrapper.Builder.SchemaType; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -40,7 +40,7 @@ import org.springframework.util.StringUtils; * @author Christian Tzolov * @since 0.8.0 */ -@ConditionalOnClass({ VertexAI.class, VertexAiGeminiChatClient.class }) +@ConditionalOnClass({ VertexAI.class, VertexAiGeminiModelCall.class }) @EnableConfigurationProperties({ VertexAiGeminiChatProperties.class, VertexAiGeminiConnectionProperties.class }) public class VertexAiGeminiAutoConfiguration { @@ -74,7 +74,7 @@ public class VertexAiGeminiAutoConfiguration { @Bean @ConditionalOnMissingBean - public VertexAiGeminiChatClient vertexAiGeminiChat(VertexAI vertexAi, VertexAiGeminiChatProperties chatProperties, + public VertexAiGeminiModelCall vertexAiGeminiChat(VertexAI vertexAi, VertexAiGeminiChatProperties chatProperties, List toolFunctionCallbacks, ApplicationContext context) { FunctionCallbackContext functionCallbackContext = springAiFunctionManager(context); @@ -83,7 +83,7 @@ public class VertexAiGeminiAutoConfiguration { chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks); } - return new VertexAiGeminiChatClient(vertexAi, chatProperties.getOptions(), functionCallbackContext); + return new VertexAiGeminiModelCall(vertexAi, chatProperties.getOptions(), functionCallbackContext); } /** diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiChatProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiChatProperties.java index 866f4f352..3d97630c0 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiChatProperties.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiChatProperties.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.vertexai.gemini; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -30,7 +30,7 @@ public class VertexAiGeminiChatProperties { public static final String CONFIG_PREFIX = "spring.ai.vertex.ai.gemini.chat"; - public static final String DEFAULT_MODEL = VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_VISION.getValue(); + public static final String DEFAULT_MODEL = VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_VISION.getValue(); /** * Vertex AI Gemini API generative options. diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPalm2AutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPalm2AutoConfiguration.java index c1ac9fa75..13753c374 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPalm2AutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPalm2AutoConfiguration.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.vertexai.palm2; -import org.springframework.ai.vertexai.palm2.VertexAiPaLm2ChatClient; +import org.springframework.ai.vertexai.palm2.VertexAiPaLm2ModelCall; import org.springframework.ai.vertexai.palm2.VertexAiPaLm2EmbeddingClient; import org.springframework.ai.vertexai.palm2.api.VertexAiPaLm2Api; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -47,9 +47,9 @@ public class VertexAiPalm2AutoConfiguration { @ConditionalOnMissingBean @ConditionalOnProperty(prefix = VertexAiPlam2ChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) - public VertexAiPaLm2ChatClient vertexAiChatClient(VertexAiPaLm2Api vertexAiApi, + public VertexAiPaLm2ModelCall vertexAiChatClient(VertexAiPaLm2Api vertexAiApi, VertexAiPlam2ChatProperties chatProperties) { - return new VertexAiPaLm2ChatClient(vertexAiApi, chatProperties.getOptions()); + return new VertexAiPaLm2ModelCall(vertexAiApi, chatProperties.getOptions()); } @Bean diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/watsonxai/WatsonxAiAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/watsonxai/WatsonxAiAutoConfiguration.java index ce651ee17..7cec3a7eb 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/watsonxai/WatsonxAiAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/watsonxai/WatsonxAiAutoConfiguration.java @@ -15,7 +15,7 @@ */ package org.springframework.ai.autoconfigure.watsonxai; -import org.springframework.ai.watsonx.WatsonxAiChatClient; +import org.springframework.ai.watsonx.WatsonxAiModelCall; import org.springframework.ai.watsonx.api.WatsonxAiApi; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -50,8 +50,8 @@ public class WatsonxAiAutoConfiguration { @Bean @ConditionalOnMissingBean - public WatsonxAiChatClient watsonxChatClient(WatsonxAiApi watsonxApi, WatsonxAiChatProperties chatProperties) { - return new WatsonxAiChatClient(watsonxApi, chatProperties.getOptions()); + public WatsonxAiModelCall watsonxChatClient(WatsonxAiApi watsonxApi, WatsonxAiChatProperties chatProperties) { + return new WatsonxAiModelCall(watsonxApi, chatProperties.getOptions()); } } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfigurationIT.java index 69e33a304..20ed0de87 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfigurationIT.java @@ -22,9 +22,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.anthropic.AnthropicModelCall; import reactor.core.publisher.Flux; -import org.springframework.ai.anthropic.AnthropicChatClient; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -50,7 +50,7 @@ public class AnthropicAutoConfigurationIT { @Test void generate() { contextRunner.run(context -> { - AnthropicChatClient chatClient = context.getBean(AnthropicChatClient.class); + AnthropicModelCall chatClient = context.getBean(AnthropicModelCall.class); String response = chatClient.call("Hello"); assertThat(response).isNotEmpty(); logger.info("Response: " + response); @@ -60,7 +60,7 @@ public class AnthropicAutoConfigurationIT { @Test void generateStreaming() { contextRunner.run(context -> { - AnthropicChatClient chatClient = context.getBean(AnthropicChatClient.class); + AnthropicModelCall chatClient = context.getBean(AnthropicModelCall.class); Flux responseFlux = chatClient.stream(new Prompt(new UserMessage("Hello"))); String response = responseFlux.collectList() diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicPropertiesTests.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicPropertiesTests.java index 0c2c6aae3..c980a85bf 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicPropertiesTests.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicPropertiesTests.java @@ -17,7 +17,7 @@ package org.springframework.ai.autoconfigure.anthropic; import org.junit.jupiter.api.Test; -import org.springframework.ai.anthropic.AnthropicChatClient; +import org.springframework.ai.anthropic.AnthropicModelCall; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -102,7 +102,7 @@ public class AnthropicPropertiesTests { RestClientAutoConfiguration.class, AnthropicAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(AnthropicChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(AnthropicChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(AnthropicModelCall.class)).isNotEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -111,7 +111,7 @@ public class AnthropicPropertiesTests { RestClientAutoConfiguration.class, AnthropicAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(AnthropicChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(AnthropicChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(AnthropicModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -120,7 +120,7 @@ public class AnthropicPropertiesTests { RestClientAutoConfiguration.class, AnthropicAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(AnthropicChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(AnthropicChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(AnthropicModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithFunctionBeanIT.java index d170add72..88998257c 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithFunctionBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithFunctionBeanIT.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.anthropic.AnthropicChatClient; +import org.springframework.ai.anthropic.AnthropicModelCall; import org.springframework.ai.anthropic.AnthropicChatOptions; import org.springframework.ai.anthropic.api.AnthropicApi; import org.springframework.ai.autoconfigure.anthropic.AnthropicAutoConfiguration; @@ -61,7 +61,7 @@ class FunctionCallWithFunctionBeanIT { "spring.ai.anthropic.chat.options.model=" + AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue()) .run(context -> { - AnthropicChatClient chatClient = context.getBean(AnthropicChatClient.class); + AnthropicModelCall chatClient = context.getBean(AnthropicModelCall.class); var userMessage = new UserMessage( "What's the weather like in San Francisco, in Paris, France and in Tokyo, Japan? Return the temperature in Celsius."); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java index a9592cae7..565682494 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithPromptFunctionIT.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.anthropic.AnthropicChatClient; +import org.springframework.ai.anthropic.AnthropicModelCall; import org.springframework.ai.anthropic.AnthropicChatOptions; import org.springframework.ai.anthropic.api.AnthropicApi; import org.springframework.ai.autoconfigure.anthropic.AnthropicAutoConfiguration; @@ -54,7 +54,7 @@ public class FunctionCallWithPromptFunctionIT { "spring.ai.anthropic.chat.options.model=" + AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue()) .run(context -> { - AnthropicChatClient chatClient = context.getBean(AnthropicChatClient.class); + AnthropicModelCall chatClient = context.getBean(AnthropicModelCall.class); UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, in Paris and in Tokyo? Return the temperature in Celsius."); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/AzureOpenAiAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/AzureOpenAiAutoConfigurationIT.java index ce7075250..e70bacbe9 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/AzureOpenAiAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/AzureOpenAiAutoConfigurationIT.java @@ -21,11 +21,11 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.chat.messages.AssistantMessage; import reactor.core.publisher.Flux; import org.springframework.ai.autoconfigure.azure.openai.AzureOpenAiAutoConfiguration; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingClient; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -77,7 +77,7 @@ public class AzureOpenAiAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - AzureOpenAiChatClient chatClient = context.getBean(AzureOpenAiChatClient.class); + AzureOpenAiModelCall chatClient = context.getBean(AzureOpenAiModelCall.class); ChatResponse response = chatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -87,7 +87,7 @@ public class AzureOpenAiAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - AzureOpenAiChatClient chatClient = context.getBean(AzureOpenAiChatClient.class); + AzureOpenAiModelCall chatClient = context.getBean(AzureOpenAiModelCall.class); Flux response = chatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -127,17 +127,17 @@ public class AzureOpenAiAutoConfigurationIT { // Disable the chat auto-configuration. contextRunner.withPropertyValues("spring.ai.azure.openai.chat.enabled=false").run(context -> { - assertThat(context.getBeansOfType(AzureOpenAiChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(AzureOpenAiModelCall.class)).isEmpty(); }); // The chat auto-configuration is enabled by default. contextRunner.run(context -> { - assertThat(context.getBeansOfType(AzureOpenAiChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(AzureOpenAiModelCall.class)).isNotEmpty(); }); // Explicitly enable the chat auto-configuration. contextRunner.withPropertyValues("spring.ai.azure.openai.chat.enabled=true").run(context -> { - assertThat(context.getBeansOfType(AzureOpenAiChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(AzureOpenAiModelCall.class)).isNotEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionBeanIT.java index e8a7e2126..548b2633c 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionBeanIT.java @@ -24,9 +24,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.autoconfigure.azure.openai.AzureOpenAiAutoConfiguration; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.AzureOpenAiChatOptions; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; @@ -57,19 +57,19 @@ class FunctionCallWithFunctionBeanIT { contextRunner.withPropertyValues("spring.ai.azure.openai.chat.options..deployment-name=gpt-4-0125-preview") .run(context -> { - ChatClient chatClient = context.getBean(AzureOpenAiChatClient.class); + ModelCall modelCall = context.getBean(AzureOpenAiModelCall.class); UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Paris and in Tokyo? Use Multi-turn function calling."); - ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), + ChatResponse response = modelCall.call(new Prompt(List.of(userMessage), AzureOpenAiChatOptions.builder().withFunction("weatherFunction").build())); logger.info("Response: {}", response); assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15"); - response = chatClient.call(new Prompt(List.of(userMessage), + response = modelCall.call(new Prompt(List.of(userMessage), AzureOpenAiChatOptions.builder().withFunction("weatherFunction3").build())); logger.info("Response: {}", response); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionWrapperIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionWrapperIT.java index 934b84cf1..5b3fde935 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionWrapperIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionWrapperIT.java @@ -23,7 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.autoconfigure.azure.openai.AzureOpenAiAutoConfiguration; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.AzureOpenAiChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; @@ -56,7 +56,7 @@ public class FunctionCallWithFunctionWrapperIT { contextRunner.withPropertyValues("spring.ai.azure.openai.chat.options.deployment-name=gpt-4-0125-preview") .run(context -> { - AzureOpenAiChatClient chatClient = context.getBean(AzureOpenAiChatClient.class); + AzureOpenAiModelCall chatClient = context.getBean(AzureOpenAiModelCall.class); UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Paris and in Tokyo?"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java index 9bef922d2..7bca52093 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithPromptFunctionIT.java @@ -23,7 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.autoconfigure.azure.openai.AzureOpenAiAutoConfiguration; -import org.springframework.ai.azure.openai.AzureOpenAiChatClient; +import org.springframework.ai.azure.openai.AzureOpenAiModelCall; import org.springframework.ai.azure.openai.AzureOpenAiChatOptions; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; @@ -52,7 +52,7 @@ public class FunctionCallWithPromptFunctionIT { contextRunner.withPropertyValues("spring.ai.azure.openai.chat.options.deployment-name=gpt-4-0125-preview") .run(context -> { - AzureOpenAiChatClient chatClient = context.getBean(AzureOpenAiChatClient.class); + AzureOpenAiModelCall chatClient = context.getBean(AzureOpenAiModelCall.class); UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, in Paris and in Tokyo? Use Multi-turn function calling."); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfigurationIT.java index f8aca8b9a..706be8f82 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic/BedrockAnthropicChatAutoConfigurationIT.java @@ -21,12 +21,12 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.bedrock.anthropic.BedrockAnthropicModelCall; import org.springframework.ai.chat.messages.AssistantMessage; import reactor.core.publisher.Flux; import software.amazon.awssdk.regions.Region; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.anthropic.BedrockAnthropicChatClient; import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi.AnthropicChatModel; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -69,7 +69,7 @@ public class BedrockAnthropicChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockAnthropicChatClient anthropicChatClient = context.getBean(BedrockAnthropicChatClient.class); + BedrockAnthropicModelCall anthropicChatClient = context.getBean(BedrockAnthropicModelCall.class); ChatResponse response = anthropicChatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -79,7 +79,7 @@ public class BedrockAnthropicChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - BedrockAnthropicChatClient anthropicChatClient = context.getBean(BedrockAnthropicChatClient.class); + BedrockAnthropicModelCall anthropicChatClient = context.getBean(BedrockAnthropicModelCall.class); Flux response = anthropicChatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -130,7 +130,7 @@ public class BedrockAnthropicChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropicChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropicChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropicChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropicModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -138,7 +138,7 @@ public class BedrockAnthropicChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropicChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropicChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropicChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropicModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -146,7 +146,7 @@ public class BedrockAnthropicChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropicChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropicChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropicChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropicModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfigurationIT.java index 467fedc7e..be4194773 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/anthropic3/BedrockAnthropic3ChatAutoConfigurationIT.java @@ -21,12 +21,12 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.bedrock.anthropic3.BedrockAnthropic3ModelCall; import org.springframework.ai.chat.messages.AssistantMessage; import reactor.core.publisher.Flux; import software.amazon.awssdk.regions.Region; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.anthropic3.BedrockAnthropic3ChatClient; import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi.AnthropicChatModel; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; @@ -69,7 +69,7 @@ public class BedrockAnthropic3ChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockAnthropic3ChatClient anthropicChatClient = context.getBean(BedrockAnthropic3ChatClient.class); + BedrockAnthropic3ModelCall anthropicChatClient = context.getBean(BedrockAnthropic3ModelCall.class); ChatResponse response = anthropicChatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -79,7 +79,7 @@ public class BedrockAnthropic3ChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - BedrockAnthropic3ChatClient anthropicChatClient = context.getBean(BedrockAnthropic3ChatClient.class); + BedrockAnthropic3ModelCall anthropicChatClient = context.getBean(BedrockAnthropic3ModelCall.class); Flux response = anthropicChatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -130,7 +130,7 @@ public class BedrockAnthropic3ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropic3ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropic3ChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropic3ChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropic3ModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -138,7 +138,7 @@ public class BedrockAnthropic3ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropic3ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropic3ChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropic3ChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropic3ModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -146,7 +146,7 @@ public class BedrockAnthropic3ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAnthropic3ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAnthropic3ChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAnthropic3ChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAnthropic3ModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfigurationIT.java index e515f6afd..01f53e70b 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/cohere/BedrockCohereChatAutoConfigurationIT.java @@ -21,13 +21,13 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.bedrock.cohere.BedrockCohereModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.AssistantMessage; import reactor.core.publisher.Flux; import software.amazon.awssdk.regions.Region; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.cohere.BedrockCohereChatClient; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatModel; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatRequest.ReturnLikelihoods; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatRequest.Truncate; @@ -72,7 +72,7 @@ public class BedrockCohereChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockCohereChatClient cohereChatClient = context.getBean(BedrockCohereChatClient.class); + BedrockCohereModelCall cohereChatClient = context.getBean(BedrockCohereModelCall.class); ChatResponse response = cohereChatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -82,7 +82,7 @@ public class BedrockCohereChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - BedrockCohereChatClient cohereChatClient = context.getBean(BedrockCohereChatClient.class); + BedrockCohereModelCall cohereChatClient = context.getBean(BedrockCohereModelCall.class); Flux response = cohereChatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -146,7 +146,7 @@ public class BedrockCohereChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockCohereChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockCohereChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockCohereChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockCohereModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -154,7 +154,7 @@ public class BedrockCohereChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockCohereChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockCohereChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockCohereChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockCohereModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -162,7 +162,7 @@ public class BedrockCohereChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockCohereChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockCohereChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockCohereChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockCohereModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/jurassic2/BedrockAi21Jurassic2ChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/jurassic2/BedrockAi21Jurassic2ChatAutoConfigurationIT.java index 057e46483..4c9efdd01 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/jurassic2/BedrockAi21Jurassic2ChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/jurassic2/BedrockAi21Jurassic2ChatAutoConfigurationIT.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; import org.springframework.ai.autoconfigure.bedrock.jurrasic2.BedrockAi21Jurassic2ChatAutoConfiguration; import org.springframework.ai.autoconfigure.bedrock.jurrasic2.BedrockAi21Jurassic2ChatProperties; -import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ChatClient; +import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ModelCall; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.Message; @@ -69,8 +69,8 @@ public class BedrockAi21Jurassic2ChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockAi21Jurassic2ChatClient ai21Jurassic2ChatClient = context - .getBean(BedrockAi21Jurassic2ChatClient.class); + BedrockAi21Jurassic2ModelCall ai21Jurassic2ChatClient = context + .getBean(BedrockAi21Jurassic2ModelCall.class); ChatResponse response = ai21Jurassic2ChatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -111,7 +111,7 @@ public class BedrockAi21Jurassic2ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAi21Jurassic2ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAi21Jurassic2ModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -119,7 +119,7 @@ public class BedrockAi21Jurassic2ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAi21Jurassic2ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockAi21Jurassic2ModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -127,7 +127,7 @@ public class BedrockAi21Jurassic2ChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockAi21Jurassic2ChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockAi21Jurassic2ChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockAi21Jurassic2ModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfigurationIT.java index 6ca69b655..742eefa27 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/llama/BedrockLlamaChatAutoConfigurationIT.java @@ -21,13 +21,13 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.bedrock.llama.BedrockLlamaModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.AssistantMessage; import reactor.core.publisher.Flux; import software.amazon.awssdk.regions.Region; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.llama.BedrockLlamaChatClient; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi.LlamaChatModel; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.prompt.Prompt; @@ -71,7 +71,7 @@ public class BedrockLlamaChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockLlamaChatClient llamaChatClient = context.getBean(BedrockLlamaChatClient.class); + BedrockLlamaModelCall llamaChatClient = context.getBean(BedrockLlamaModelCall.class); ChatResponse response = llamaChatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -81,7 +81,7 @@ public class BedrockLlamaChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - BedrockLlamaChatClient llamaChatClient = context.getBean(BedrockLlamaChatClient.class); + BedrockLlamaModelCall llamaChatClient = context.getBean(BedrockLlamaModelCall.class); Flux response = llamaChatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -133,7 +133,7 @@ public class BedrockLlamaChatAutoConfigurationIT { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(BedrockLlamaChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockLlamaChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockLlamaChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockLlamaModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -141,7 +141,7 @@ public class BedrockLlamaChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockLlamaChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockLlamaChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockLlamaChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockLlamaModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -149,7 +149,7 @@ public class BedrockLlamaChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockLlamaChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockLlamaChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockLlamaChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockLlamaModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfigurationIT.java index 93c654178..ee5ed90f8 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/bedrock/titan/BedrockTitanChatAutoConfigurationIT.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Flux; import software.amazon.awssdk.regions.Region; import org.springframework.ai.autoconfigure.bedrock.BedrockAwsConnectionProperties; -import org.springframework.ai.bedrock.titan.BedrockTitanChatClient; +import org.springframework.ai.bedrock.titan.BedrockTitanModelCall; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatModel; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.prompt.Prompt; @@ -70,7 +70,7 @@ public class BedrockTitanChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - BedrockTitanChatClient chatClient = context.getBean(BedrockTitanChatClient.class); + BedrockTitanModelCall chatClient = context.getBean(BedrockTitanModelCall.class); ChatResponse response = chatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -80,7 +80,7 @@ public class BedrockTitanChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - BedrockTitanChatClient chatClient = context.getBean(BedrockTitanChatClient.class); + BedrockTitanModelCall chatClient = context.getBean(BedrockTitanModelCall.class); Flux response = chatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -137,7 +137,7 @@ public class BedrockTitanChatAutoConfigurationIT { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(BedrockTitanChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockTitanChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockTitanChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockTitanModelCall.class)).isEmpty(); }); // Explicitly enable the chat auto-configuration. @@ -145,7 +145,7 @@ public class BedrockTitanChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockTitanChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockTitanChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(BedrockTitanChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(BedrockTitanModelCall.class)).isNotEmpty(); }); // Explicitly disable the chat auto-configuration. @@ -153,7 +153,7 @@ public class BedrockTitanChatAutoConfigurationIT { .withConfiguration(AutoConfigurations.of(BedrockTitanChatAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(BedrockTitanChatProperties.class)).isEmpty(); - assertThat(context.getBeansOfType(BedrockTitanChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(BedrockTitanModelCall.class)).isEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfigurationIT.java index 25816e8c0..297db3737 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/MistralAiAutoConfigurationIT.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.mistralai.MistralAiModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; @@ -29,7 +30,6 @@ import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.embedding.EmbeddingResponse; -import org.springframework.ai.mistralai.MistralAiChatClient; import org.springframework.ai.mistralai.MistralAiEmbeddingClient; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -54,7 +54,7 @@ public class MistralAiAutoConfigurationIT { @Test void generate() { contextRunner.run(context -> { - MistralAiChatClient client = context.getBean(MistralAiChatClient.class); + MistralAiModelCall client = context.getBean(MistralAiModelCall.class); String response = client.call("Hello"); assertThat(response).isNotEmpty(); logger.info("Response: " + response); @@ -64,7 +64,7 @@ public class MistralAiAutoConfigurationIT { @Test void generateStreaming() { contextRunner.run(context -> { - MistralAiChatClient client = context.getBean(MistralAiChatClient.class); + MistralAiModelCall client = context.getBean(MistralAiModelCall.class); Flux responseFlux = client.stream(new Prompt(new UserMessage("Hello"))); String response = responseFlux.collectList().block().stream().map(chatResponse -> { return chatResponse.getResults().get(0).getOutput().getContent(); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanIT.java index d4259f3ee..4859b3bd9 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanIT.java @@ -30,7 +30,7 @@ import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.mistralai.MistralAiChatClient; +import org.springframework.ai.mistralai.MistralAiModelCall; import org.springframework.ai.mistralai.MistralAiChatOptions; import org.springframework.ai.mistralai.api.MistralAiApi; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -60,7 +60,7 @@ class PaymentStatusBeanIT { .withPropertyValues("spring.ai.mistralai.chat.options.model=" + MistralAiApi.ChatModel.LARGE.getValue()) .run(context -> { - MistralAiChatClient chatClient = context.getBean(MistralAiChatClient.class); + MistralAiModelCall chatClient = context.getBean(MistralAiModelCall.class); ChatResponse response = chatClient .call(new Prompt(List.of(new UserMessage("What's the status of my transaction with id T1001?")), diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanOpenAiIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanOpenAiIT.java index 15796f921..dd612bec8 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanOpenAiIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanOpenAiIT.java @@ -31,7 +31,7 @@ import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.mistralai.api.MistralAiApi; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -43,7 +43,7 @@ import org.springframework.context.annotation.Description; import static org.assertj.core.api.Assertions.assertThat; /** - * Same test as {@link PaymentStatusBeanIT.java} but using {@link OpenAiChatClient} for + * Same test as {@link PaymentStatusBeanIT.java} but using {@link OpenAiModelCall} for * Mistral AI Function Calling implementation. * * @author Christian Tzolov @@ -67,7 +67,7 @@ class PaymentStatusBeanOpenAiIT { .withPropertyValues("spring.ai.openai.chat.options.model=" + MistralAiApi.ChatModel.SMALL.getValue()) .run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); ChatResponse response = chatClient .call(new Prompt(List.of(new UserMessage("What's the status of my transaction with id T1001?")), diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java index 58bd9e84c..f8e64ae0a 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java @@ -30,7 +30,7 @@ import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.mistralai.MistralAiChatClient; +import org.springframework.ai.mistralai.MistralAiModelCall; import org.springframework.ai.mistralai.MistralAiChatOptions; import org.springframework.ai.mistralai.api.MistralAiApi; import org.springframework.ai.model.function.FunctionCallbackWrapper; @@ -71,7 +71,7 @@ public class PaymentStatusPromptIT { .withPropertyValues("spring.ai.mistralai.chat.options.model=" + MistralAiApi.ChatModel.SMALL.getValue()) .run(context -> { - MistralAiChatClient chatClient = context.getBean(MistralAiChatClient.class); + MistralAiModelCall chatClient = context.getBean(MistralAiModelCall.class); UserMessage userMessage = new UserMessage("What's the status of my transaction with id T1001?"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/WeatherServicePromptIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/WeatherServicePromptIT.java index 6bf052f56..1eee53117 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/WeatherServicePromptIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/WeatherServicePromptIT.java @@ -33,7 +33,7 @@ import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.mistralai.MistralAiChatClient; +import org.springframework.ai.mistralai.MistralAiModelCall; import org.springframework.ai.mistralai.MistralAiChatOptions; import org.springframework.ai.mistralai.api.MistralAiApi; import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ToolChoice; @@ -64,7 +64,7 @@ public class WeatherServicePromptIT { .withPropertyValues("spring.ai.mistralai.chat.options.model=" + MistralAiApi.ChatModel.LARGE.getValue()) .run(context -> { - MistralAiChatClient chatClient = context.getBean(MistralAiChatClient.class); + MistralAiModelCall chatClient = context.getBean(MistralAiModelCall.class); UserMessage userMessage = new UserMessage("What's the weather like in Paris?"); // UserMessage userMessage = new UserMessage("What's the weather like in diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaChatAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaChatAutoConfigurationIT.java index affa26197..a2d9f0f6a 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaChatAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaChatAutoConfigurationIT.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.Generation; import org.springframework.ai.chat.messages.AssistantMessage; -import org.springframework.ai.ollama.OllamaChatClient; +import org.springframework.ai.ollama.OllamaModelCall; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.SystemPromptTemplate; import org.springframework.ai.chat.messages.Message; @@ -104,7 +104,7 @@ public class OllamaChatAutoConfigurationIT { @Test public void chatCompletion() { contextRunner.run(context -> { - OllamaChatClient chatClient = context.getBean(OllamaChatClient.class); + OllamaModelCall chatClient = context.getBean(OllamaModelCall.class); ChatResponse response = chatClient.call(new Prompt(List.of(userMessage, systemMessage))); assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard"); }); @@ -114,7 +114,7 @@ public class OllamaChatAutoConfigurationIT { public void chatCompletionStreaming() { contextRunner.run(context -> { - OllamaChatClient chatClient = context.getBean(OllamaChatClient.class); + OllamaModelCall chatClient = context.getBean(OllamaModelCall.class); Flux response = chatClient.stream(new Prompt(List.of(userMessage, systemMessage))); @@ -136,17 +136,17 @@ public class OllamaChatAutoConfigurationIT { void chatActivation() { contextRunner.withPropertyValues("spring.ai.ollama.chat.enabled=false").run(context -> { assertThat(context.getBeansOfType(OllamaChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OllamaChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(OllamaModelCall.class)).isEmpty(); }); contextRunner.run(context -> { assertThat(context.getBeansOfType(OllamaChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OllamaChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(OllamaModelCall.class)).isNotEmpty(); }); contextRunner.withPropertyValues("spring.ai.ollama.chat.enabled=true").run(context -> { assertThat(context.getBeansOfType(OllamaChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OllamaChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(OllamaModelCall.class)).isNotEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfigurationIT.java index 44c2d7375..8a3c0e561 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiAutoConfigurationIT.java @@ -27,18 +27,15 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.image.ImagePrompt; import org.springframework.ai.image.ImageResponse; -import org.springframework.ai.openai.OpenAiImageClient; +import org.springframework.ai.openai.*; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import reactor.core.publisher.Flux; -import org.springframework.ai.openai.OpenAiAudioSpeechClient; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.embedding.EmbeddingResponse; -import org.springframework.ai.openai.OpenAiAudioTranscriptionClient; -import org.springframework.ai.openai.OpenAiChatClient; -import org.springframework.ai.openai.OpenAiEmbeddingClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -58,7 +55,7 @@ public class OpenAiAutoConfigurationIT { @Test void generate() { contextRunner.run(context -> { - OpenAiChatClient client = context.getBean(OpenAiChatClient.class); + OpenAiModelCall client = context.getBean(OpenAiModelCall.class); String response = client.call("Hello"); assertThat(response).isNotEmpty(); logger.info("Response: " + response); @@ -105,7 +102,7 @@ public class OpenAiAutoConfigurationIT { @Test void generateStreaming() { contextRunner.run(context -> { - OpenAiChatClient client = context.getBean(OpenAiChatClient.class); + OpenAiModelCall client = context.getBean(OpenAiModelCall.class); Flux responseFlux = client.stream(new Prompt(new UserMessage("Hello"))); String response = responseFlux.collectList().block().stream().map(chatResponse -> { return chatResponse.getResults().get(0).getOutput().getContent(); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiPropertiesTests.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiPropertiesTests.java index 10583ecd4..ba1d32a96 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiPropertiesTests.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OpenAiPropertiesTests.java @@ -21,7 +21,7 @@ import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration; import org.springframework.ai.model.ModelOptionsUtils; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiEmbeddingClient; import org.springframework.ai.openai.OpenAiImageClient; import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest.ResponseFormat; @@ -593,7 +593,7 @@ public class OpenAiPropertiesTests { RestClientAutoConfiguration.class, OpenAiAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(OpenAiChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OpenAiChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(OpenAiModelCall.class)).isEmpty(); }); new ApplicationContextRunner() @@ -602,7 +602,7 @@ public class OpenAiPropertiesTests { RestClientAutoConfiguration.class, OpenAiAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(OpenAiChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OpenAiChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(OpenAiModelCall.class)).isNotEmpty(); }); new ApplicationContextRunner() @@ -612,7 +612,7 @@ public class OpenAiPropertiesTests { RestClientAutoConfiguration.class, OpenAiAutoConfiguration.class)) .run(context -> { assertThat(context.getBeansOfType(OpenAiChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(OpenAiChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(OpenAiModelCall.class)).isNotEmpty(); }); } diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java index 67770f6af..eb41139a0 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackInPromptIT.java @@ -32,7 +32,7 @@ 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.model.function.FunctionCallbackWrapper; -import org.springframework.ai.openai.OpenAiChatClient; +import org.springframework.ai.openai.OpenAiModelCall; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -54,7 +54,7 @@ public class FunctionCallbackInPromptIT { void functionCallTest() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); @@ -79,7 +79,7 @@ public class FunctionCallbackInPromptIT { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWithPlainFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWithPlainFunctionBeanIT.java index d5437a62f..6a637ce4a 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWithPlainFunctionBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWithPlainFunctionBeanIT.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.ai.openai.OpenAiModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration; @@ -34,7 +35,6 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.function.FunctionCallingOptions; import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions; -import org.springframework.ai.openai.OpenAiChatClient; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -60,7 +60,7 @@ class FunctionCallbackWithPlainFunctionBeanIT { void functionCallTest() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); // Test weatherFunction UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); @@ -87,7 +87,7 @@ class FunctionCallbackWithPlainFunctionBeanIT { void functionCallWithPortableFunctionCallingOptions() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); // Test weatherFunction UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); @@ -106,7 +106,7 @@ class FunctionCallbackWithPlainFunctionBeanIT { void streamFunctionCallTest() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); // Test weatherFunction UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWrapperIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWrapperIT.java index 44e2c3af7..8e200194a 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWrapperIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWrapperIT.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.ai.openai.OpenAiModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration; @@ -33,7 +34,6 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.function.FunctionCallbackWrapper; import org.springframework.ai.model.function.FunctionCallback; -import org.springframework.ai.openai.OpenAiChatClient; import org.springframework.ai.openai.OpenAiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -58,7 +58,7 @@ public class FunctionCallbackWrapperIT { void functionCallTest() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); @@ -76,7 +76,7 @@ public class FunctionCallbackWrapperIT { void streamFunctionCallTest() { contextRunner.withPropertyValues("spring.ai.openai.chat.options.model=gpt-4-turbo-preview").run(context -> { - OpenAiChatClient chatClient = context.getBean(OpenAiChatClient.class); + OpenAiModelCall chatClient = context.getBean(OpenAiModelCall.class); UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfigurationIT.java index af0e77de9..e956e5241 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfigurationIT.java @@ -21,12 +21,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import reactor.core.publisher.Flux; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -46,7 +46,7 @@ public class VertexAiGeminiAutoConfigurationIT { @Test void generate() { contextRunner.run(context -> { - VertexAiGeminiChatClient client = context.getBean(VertexAiGeminiChatClient.class); + VertexAiGeminiModelCall client = context.getBean(VertexAiGeminiModelCall.class); String response = client.call("Hello"); assertThat(response).isNotEmpty(); logger.info("Response: " + response); @@ -56,7 +56,7 @@ public class VertexAiGeminiAutoConfigurationIT { @Test void generateStreaming() { contextRunner.run(context -> { - VertexAiGeminiChatClient client = context.getBean(VertexAiGeminiChatClient.class); + VertexAiGeminiModelCall client = context.getBean(VertexAiGeminiModelCall.class); Flux responseFlux = client.stream(new Prompt(new UserMessage("Hello"))); String response = responseFlux.collectList().block().stream().map(chatResponse -> { return chatResponse.getResults().get(0).getOutput().getContent(); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionBeanIT.java index 908445675..9b2d78479 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionBeanIT.java @@ -28,7 +28,7 @@ import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.messages.SystemMessage; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -55,12 +55,12 @@ class FunctionCallWithFunctionBeanIT { void functionCallTest() { contextRunner.withPropertyValues("spring.ai.vertex.ai.gemini.chat.options.model=" - // + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) - + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO.getValue()) - // + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_FLASH.getValue()) + // + VertexAiGeminiModelCall.ChatModel.GEMINI_PRO.getValue()) + + VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_1_5_PRO.getValue()) + // + VertexAiGeminiModelCall.ChatModel.GEMINI_PRO_1_5_FLASH.getValue()) .run(context -> { - VertexAiGeminiChatClient chatClient = context.getBean(VertexAiGeminiChatClient.class); + VertexAiGeminiModelCall chatClient = context.getBean(VertexAiGeminiModelCall.class); var systemMessage = new SystemMessage(""" Use Multi-turn function calling. @@ -74,7 +74,7 @@ class FunctionCallWithFunctionBeanIT { ChatResponse response = chatClient.call(new Prompt(List.of(systemMessage, userMessage), VertexAiGeminiChatOptions.builder().withFunction("weatherFunction").build())); - // ChatResponse response = chatClient.call(new + // ChatResponse response = modelCall.call(new // Prompt(List.of(userMessage), // VertexAiGeminiChatOptions.builder().withFunction("weatherFunction").build())); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionWrapperIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionWrapperIT.java index cbad663c9..11c671737 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionWrapperIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithFunctionWrapperIT.java @@ -30,7 +30,7 @@ import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.function.FunctionCallback; import org.springframework.ai.model.function.FunctionCallbackWrapper; import org.springframework.ai.model.function.FunctionCallbackWrapper.Builder.SchemaType; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -55,10 +55,10 @@ public class FunctionCallWithFunctionWrapperIT { void functionCallTest() { contextRunner .withPropertyValues("spring.ai.vertex.ai.gemini.chat.options.model=" - + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) + + VertexAiGeminiModelCall.ChatModel.GEMINI_PRO.getValue()) .run(context -> { - VertexAiGeminiChatClient chatClient = context.getBean(VertexAiGeminiChatClient.class); + VertexAiGeminiModelCall chatClient = context.getBean(VertexAiGeminiModelCall.class); var systemMessage = new SystemMessage(""" Use Multi-turn function calling. diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithPromptFunctionIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithPromptFunctionIT.java index b654fb124..d99d79449 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithPromptFunctionIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/gemini/tool/FunctionCallWithPromptFunctionIT.java @@ -29,7 +29,7 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.model.function.FunctionCallbackWrapper; import org.springframework.ai.model.function.FunctionCallbackWrapper.Builder.SchemaType; -import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiModelCall; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -51,10 +51,10 @@ public class FunctionCallWithPromptFunctionIT { void functionCallTest() { contextRunner .withPropertyValues("spring.ai.vertex.ai.gemini.chat.options.model=" - + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) + + VertexAiGeminiModelCall.ChatModel.GEMINI_PRO.getValue()) .run(context -> { - VertexAiGeminiChatClient chatClient = context.getBean(VertexAiGeminiChatClient.class); + VertexAiGeminiModelCall chatClient = context.getBean(VertexAiGeminiModelCall.class); var systemMessage = new SystemMessage(""" Use Multi-turn function calling. diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPaLm2AutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPaLm2AutoConfigurationIT.java index 0ea8f663e..b310abe64 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPaLm2AutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vertexai/palm2/VertexAiPaLm2AutoConfigurationIT.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.springframework.ai.embedding.EmbeddingResponse; -import org.springframework.ai.vertexai.palm2.VertexAiPaLm2ChatClient; +import org.springframework.ai.vertexai.palm2.VertexAiPaLm2ModelCall; import org.springframework.ai.vertexai.palm2.VertexAiPaLm2EmbeddingClient; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; @@ -48,7 +48,7 @@ public class VertexAiPaLm2AutoConfigurationIT { @Test void generate() { contextRunner.run(context -> { - VertexAiPaLm2ChatClient client = context.getBean(VertexAiPaLm2ChatClient.class); + VertexAiPaLm2ModelCall client = context.getBean(VertexAiPaLm2ModelCall.class); String response = client.call("Hello"); @@ -102,19 +102,19 @@ public class VertexAiPaLm2AutoConfigurationIT { // Disable the chat auto-configuration. contextRunner.withPropertyValues("spring.ai.vertex.ai.chat.enabled=false").run(context -> { assertThat(context.getBeansOfType(VertexAiPlam2ChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(VertexAiPaLm2ChatClient.class)).isEmpty(); + assertThat(context.getBeansOfType(VertexAiPaLm2ModelCall.class)).isEmpty(); }); // The chat auto-configuration is enabled by default. contextRunner.run(context -> { assertThat(context.getBeansOfType(VertexAiPlam2ChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(VertexAiPaLm2ChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(VertexAiPaLm2ModelCall.class)).isNotEmpty(); }); // Explicitly enable the chat auto-configuration. contextRunner.withPropertyValues("spring.ai.vertex.ai.chat.enabled=true").run(context -> { assertThat(context.getBeansOfType(VertexAiPlam2ChatProperties.class)).isNotEmpty(); - assertThat(context.getBeansOfType(VertexAiPaLm2ChatClient.class)).isNotEmpty(); + assertThat(context.getBeansOfType(VertexAiPaLm2ModelCall.class)).isNotEmpty(); }); } 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 bdc0750bd..5153bb1ea 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 @@ -17,7 +17,7 @@ package org.springframework.ai.evaluation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.ChatResponse; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.PromptTemplate; @@ -38,7 +38,7 @@ public class BasicEvaluationTest { private static final Logger logger = LoggerFactory.getLogger(BasicEvaluationTest.class); @Autowired - protected ChatClient openAiChatClient; + protected ModelCall openAiModelCall; @Value("classpath:/prompts/spring/test/evaluation/qa-evaluator-accurate-answer.st") protected Resource qaEvaluatorAccurateAnswerResource; @@ -68,12 +68,12 @@ public class BasicEvaluationTest { } Message userMessage = userPromptTemplate.createMessage(); Prompt prompt = new Prompt(List.of(userMessage, systemMessage)); - String yesOrNo = openAiChatClient.call(prompt).getResult().getOutput().getContent(); + String yesOrNo = openAiModelCall.call(prompt).getResult().getOutput().getContent(); logger.info("Is Answer related to question: " + yesOrNo); if (yesOrNo.equalsIgnoreCase("no")) { SystemMessage notRelatedSystemMessage = new SystemMessage(qaEvaluatorNotRelatedResource); prompt = new Prompt(List.of(userMessage, notRelatedSystemMessage)); - String reasonForFailure = openAiChatClient.call(prompt).getResult().getOutput().getContent(); + String reasonForFailure = openAiModelCall.call(prompt).getResult().getOutput().getContent(); fail(reasonForFailure); } else { diff --git a/vector-stores/spring-ai-hanadb-store/src/test/java/org/springframework/ai/vectorstore/CricketWorldCupHanaController.java b/vector-stores/spring-ai-hanadb-store/src/test/java/org/springframework/ai/vectorstore/CricketWorldCupHanaController.java index ad3f954a7..7e58a29bf 100644 --- a/vector-stores/spring-ai-hanadb-store/src/test/java/org/springframework/ai/vectorstore/CricketWorldCupHanaController.java +++ b/vector-stores/spring-ai-hanadb-store/src/test/java/org/springframework/ai/vectorstore/CricketWorldCupHanaController.java @@ -17,7 +17,7 @@ package org.springframework.ai.vectorstore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.ai.chat.ChatClient; +import org.springframework.ai.chat.ModelCall; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.SystemPromptTemplate; @@ -51,11 +51,11 @@ public class CricketWorldCupHanaController { private final VectorStore hanaCloudVectorStore; - private final ChatClient chatClient; + private final ModelCall modelCall; @Autowired - public CricketWorldCupHanaController(ChatClient chatClient, VectorStore hanaCloudVectorStore) { - this.chatClient = chatClient; + public CricketWorldCupHanaController(ModelCall modelCall, VectorStore hanaCloudVectorStore) { + this.modelCall = modelCall; this.hanaCloudVectorStore = hanaCloudVectorStore; } @@ -88,7 +88,7 @@ public class CricketWorldCupHanaController { var userMessage = new UserMessage(message); Prompt prompt = new Prompt(List.of(similarDocsMessage, userMessage)); - String generation = chatClient.call(prompt).getResult().getOutput().getContent(); + String generation = modelCall.call(prompt).getResult().getOutput().getContent(); logger.info("Generation: {}", generation); return Map.of("generation", generation); }