* Adds reasoningEffort field to AzureOpenAiChatOptions builder, copy, equals, hashCode
* Propagates value to ChatCompletionsOptions
Fixes#2703
Signed-off-by: Andres da Silva Santos <40636137+andresssantos@users.noreply.github.com>
Remove circular dependencies:
Move utility classes from various packages to dedicated support packages:
- Move ToolCallbacks from ai.tool to ai.support
- Move UsageUtils to UsageCalculator in ai.support
- Move tool.util to tool.support
- Create new ToolDefinitions utility class
Support packages for the classes in question is more idomatic in spring than util packages.
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
Without this fix during the stream event handling when `EventType.MESSAGE_STOP` occurs, the latest content block was resent again and it caused to the additional tool call(if it was the latest event)
[anthropic] Replace `switchMap` -> `flatMap` to avoid cancellation of the original request
Previously, internalStream used switchMap to process ChatCompletionResponses,
which caused the active stream (including potential recursive calls) to be
canceled whenever a new response arrived. This led to incomplete processing
of streaming tool calls and unexpected behavior when handling tool_use events.
Replaced switchMap with flatMap to ensure that each response is fully processed
without being interrupted, allowing recursive internalStream calls to complete
as expected.
Without this fix during the stream event handling when `EventType.MESSAGE_STOP` occurs, the latest content block was resent again and it caused to the additional tool call(if it was the latest event)
Signed-off-by: Mikhail Mazurkevich <Mikhail.Mazurkevich@jetbrains.com>
Fixes: #1378
- Add warnings for unsupported frequency/presence penalty in Anthropic API
- Add warnings for unsupported frequency/presence penalty and topK in BedrockProxyChatModel
- Add warning for unsupported topK in OpenAI chat models
- Implement frequency and presence penalty parameters for Vertex AI Gemini model
- Update Vertex AI Gemini options and tests
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
- Renamed all occurrences of supportStFunctions to validateStFunctions for clarity.
- Updated default field, constructor, and builder method to use new naming.
- Improved getInputVariables logic to better distinguish variables, function calls, and property access.
- Ensured built-in functions accessed as properties are only skipped when validateStFunctions is true.
- Enhanced builder usage to reflect new flag and naming.
- More tests added
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
Since the builders for HTTP clients are mutable and shared, they should
only be configured with globally applicable settings. The current use
leaks specific details into other usages and affects newly instantiated
clients. This PR applies the clone() method right before mutation
happens as it probably is the strategy that avoids multiple unnecessary
copies.
feat: improve RestClient and WebClient instantiation and configuration across AI modules
- Ensure RestClient.Builder and WebClient.Builder are properly cloned before setting base URLs and headers in Mistral, OpenAI, and Ollama API classes to prevent side effects.
- Add WebClientAutoConfiguration to auto-configuration classes for Anthropic and Mistral AI modules.
- Update Mistral AI auto-configuration to inject and use WebClient.Builder.
- Clean up test and annotation usage (remove unnecessary @Nullable, fix test builder usage in AnthropicApiIT).
- Improve consistency and reliability of HTTP client configuration across model integrations.
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
* Update remaining Advisors and related classes to use the new APIs.
* In AbstractChatMemoryAdvisor, the “doNextWithProtectFromBlockingBefore()” protected method has been changed from accepting AdvisedRequest to ChatClientRequest. It’s a breaking change since the alternative was not part of M8.
* MessageAggregator has a new method to aggregate messages from ChatClientRequest. The previous method aggregating messages from AdvisedRequest has been removed. Warning since it wasn’t marked as deprecated in M8.
* In SimpleLoggerAdvisor, the “requestToString” input argument needs to be updated to use ChatClientRequest. It’s a breaking change since the alternative was not part of M8. Same thing about the constructor.
* The “getTemplateRenderer” method has been removed from BaseAdvisorChain. Each Advisor is encouraged to accept a PromptTemplate to achieve self-contained prompt augmentation operations.
* Remove deprecations in ChatClient and Advisors, and update tests accordingly.
* When building a Prompt from the ChatClient input, the SystemMessage passed via systemText() is placed first in the message list. Before, it was put last, resulting in errors with several model providers.
Relates to gh-2655
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit makes several improvements to the OpenAiImageOptions class:
1. Remove all deprecated methods from OpenAiImageOptions.Builder:
- Removed withN(), withModel(), withQuality(), withResponseFormat(),
withWidth(), withHeight(), withStyle(), and withUser() methods
- These were marked as @Deprecated(forRemoval = true, since = "1.0.0-M8")
2. Align OpenAiImageOptions structure with OpenAiChatOptions:
- Added fromOptions() static method for creating copies
- Added copy() instance method
- Updated Builder class to match pattern in OpenAiChatOptions
- Changed Builder field from private final to protected
- Added Builder constructor that takes an existing options object
3. Enhance setSize() method to maintain consistency:
- Updated setSize() to parse the size string and update width/height properties
- Added proper error handling for invalid formats
- Ensures consistent state between size, width, and height properties
4. Comprehensive test coverage improvements:
- Added tests for builder pattern with all fields
- Added tests for copy functionality
- Added tests for all setter methods
- Added tests for default values
- Added tests for equals(), hashCode(), and toString() methods
- Added specific tests for the updated setSize() behavior
- Fixed test expectations to match actual implementation behavior
These changes improve code consistency, maintainability, and test coverage
while removing deprecated methods that were scheduled for removal.
Signed-off-by: jonghoonpark <dev@jonghoonpark.com>
- Remove deprecated constructor method Media(MimeType mimeType, URL url) from Media
- Remove deprecated builder method data(URL url) from Media builder
- Update references to use the builder and the data(URI) methods
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Remove the deprecated constructors from PromptTemplate and replace the references using the builder methods
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Remove deprecated constructors from OllamaApi and AnthropicApi
- Modify AnthropicApi's public constructor to be private so that only the builder method can use it to construct
- Update OllamApiAutoConfiguration and AnthropicChatAutoconfiguration to use the builder methods to construct the respective
Apis
- Fix other constructor usages to builder methods
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Improve the jsonToStruct method in VertexAiGeminiChatModel to handle JSON arrays
in addition to JSON objects. When a JSON array is detected, it's now properly
converted to a Protobuf Struct with an items field containing the array elements.
- Added test
Resolves#2647 , #2849
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This PR introduces support for streamUsage in the AzureOpenAiChatOptions.
- Set com.azure.ai.openai.models.ChatCompletionStreamOptions#includeUsage via AzureOpenAiChatOptions.
Additionally:
- Updates the unit test AzureOpenAiChatOptionsTests to reflect the changes.
- Updates the documentation in azure-openai-chat.adoc.
Signed-off-by: Andres da Silva Santos <40636137+andresssantos@users.noreply.github.com>
- Move evaluation core classes (Request, Response, Evaluator) to spring-ai-commons.
- Move chat-specific evaluators (FactChecking, Relevancy) to spring-ai-client-chat#evaluation package.
- Move OutputConverter implementations and related classes to spring-ai-model#converter package.
- Move MetadataEnricher transformer classes to spring-ai-model#transformer package.
- Move PromptAssert utility to spring-ai-rag#util package.
- Update relevant pom.xml files and adjust imports in affected classes.
- Document class movements in upgrade-notes.adoc for M8 release.
This refactoring improves module organization and separation of concerns.
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
Renames the ambiguous overloaded `tools` methods in `ChatClient.PromptRequestSpec`
to `toolNames` and `toolCallbacks` respectively. This improves clarity
and prevents potential issues with method dispatching based on argument types.
Updates relevant code examples and adds documentation to upgrade notes.
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
This reverts commit 4eeeb83d3f.
Revert "Make ImageOptions non-null when constructing ImagePrompt"
This reverts commit 0c0787b849.
Need to review more the impact of making these options not null.
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Extend the ChatClient with a new templateRenderer() method to pass a custom TemplateRenderer object used to render user and system templates.
- Evolve the QuestionAnswerAdvisor to accept a PromptTemplate for customising the RAG prompt and templating logic while maintaining backward compatibility.
- Introduce integration tests for the QuestionAnswerAdvisor.
- Document the TemplateRenderer API and how to use it to build PromptTemplate with custom templating logic.
- Document how to customise the templating logic used internally by the ChatClient via the TemplateRendererAPI.
Add validation tests and improve PromptTemplate resource handling
Enhance robustness and reliability of the PromptTemplate class with better
resource handling and comprehensive input validation:
- Add dedicated validation tests for builder methods with null/invalid inputs
- Improve renderResource method to gracefully handle edge cases:
- Null resources return empty string
- ByteArrayResource handling with proper charset (UTF-8)
- Empty resources check with proper existence test
- Better error handling with logging instead of exception propagation
- Add input validation assertions to all Builder methods
- Fix typo in deprecated annotation comment ("fahvor" → "favor")
Update documentation to clarify template rendering in different contexts:
- Add clear notes about TemplateRenderer usage in ChatClient vs Advisors
- Document how advisor template customization differs from ChatClient template rendering
- Add comprehensive API upgrade notes for template-related deprecations
- Include detailed migration examples for PromptTemplate and QuestionAnswerAdvisor
Fixes gh-355, gh-1687, gh-2448, gh-1849, gh-1428
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
fix: correct name typo from 'AsynClients' to 'AsyncClients'
fix: correct name typo from 'Autoconfiguration' to 'AutoConfiguration', 'optoins' to 'options'
fix: correct name typo from 'Differnt' to 'Different'
fix: correct name typo from 'Compatability' to 'Compatibility'
fix: correct name typo from 'Evalutaor' to 'Evaluator'
fix: correct name typo from 'Empyt' to 'Empty'
fix: correct name typo from 'Chroma Vecor Store' to 'Chroma Vector Store'
fix: correct name typo from 'Specificaiton' to 'Specification'
fix: correct name typo from 'applicaiton' to 'application'
fix: correct name typo from 'apropriate' to 'appropriate'
fix: correct name typo from 'asigned' to 'assigned'
fix: correct name typo from 'capabilitity' to 'capability'
fix: correct name typo from 'configuraiton' to 'configuration'
fix: correct name typo from 'conntection' to 'connection'
fix: correct name typo from 'curent' to 'current'
fix: correct name typo from 'customised' to 'customized'
Signed-off-by: Changho Kim <dukso4885@gmail.com>
Add presence_penalty, frequency_penalty, and n parameters
Following Mistral AI API specifications as referenced in https://docs.mistral.ai/api/#tag/chat
Rename Builder method N() to n()
Signed-off-by: Seunghyeon Ji <3aroa2@gmail.com>
- The commit removes deprecated methods and parameters, including
- requestOptions in image observation context and proxyToolCalls in Vertex AI
- Gemini options. Updates code to use ImagePrompt.getOptions() instead of
- the separate parameter for more consistent API design.
- Remove the deprecated FunctionCallback related classes, references
- Replace them with the corresponding ToolCallback usage
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
Fixes: #2518
Issue: https://github.com/spring-projects/spring-ai/issues/2518
This commit removes the deprecated requestOptions field from ChatModelObservationContext
and EmbeddingModelObservationContext classes. Instead of passing options separately,
the code now retrieves them directly from the request objects (prompt.getOptions() or
embeddingRequest.getOptions()).
Key changes:
- Removed requestOptions parameter from observation context builders
- Updated all model implementations to stop passing options separately
- Fixed EmbeddingRequest handling in several model implementations
- Added buildEmbeddingRequest method in models to properly merge options
This change simplifies the API and removes duplication, as options are already
available in the request objects themselves.
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
- FunctionCallbackResolver is deprecated and replaced by ToolCallingManager's ToolCallbackResolver
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
* ChatMemory will become a generic interface to implement different memory management strategies. It’s been moved from the “”spring-ai-client-chat” package to “spring-ai-model” package while retaining the same package, so it’s transparent to users.
* A MessageWindowChatMemory has been introduced to provide support for a chat memory that keeps at most N messages in the memory.
* A ChatMemoryRepository interface has been introduced to support different storage strategies for the chat memory. It’s meant to be used as part of a ChatMemory implementation. This is different than before, where the storage-specific implementation was directly tied to the ChatMemory. This design is familiar to Spring users since it’s used already in the ecosystem. The goal was to use a programming model similar to Spring Session and Spring Data.
* The JdbcChatMemory has been supersed by JdbcChatMemoryRepository.
* A ChatMemory bean is auto-configured for you whenever using one of the Spring AI Model starters. By default, it uses the MessageWindowChatMemory implementation and stores the conversation history in memory. If a different repository is already configured (e.g., Cassandra, JDBC, or Neo4j), Spring AI will use that instead.
* First-class documentation has been introduced to describe the ChatMemory API and related features.
* All the changes introduced in this PR are backward-compatible.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
- Update ZhipuAI Chat Model to use ToolCalling Manager and ToolExecutionEligibilityPredicate
- Update ZhipuAI ChatOptions to implement ToolCallingChatOptions
- Update Autoconfiguration for ZhipuAI model to use ToolCallingAutoconfiguration
- Update tests
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Update Minimax Chat Model to use ToolCalling Manager and ToolExecutionEligibilityPredicate
- Update Minimax ChatOptions to implement ToolCallingChatOptions
- Update Autoconfiguration for MinimaxChat model to use ToolCallingAutoconfiguration
- Update tests
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
Adjust MergeUtils to accommodate API changes:
- Update ChatCompletions constructor parameter list to remove the usage argument
- Move usage assignment to post-construction via reflection
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>