This change updates the type of portable chat options from Float to
Double. Affected options include:
- frequencyPenalty
- presencePenalty
- temperature
- topP
The motivation for this change is to simplify coding. In Java, Float
values require an "f" suffix (e.g., 0.5f), while Double values don't
need any suffix. This makes Double easier to type and reduces
potential errors from forgetting the "f" suffix.
APIs, tests, and documentation have been updated to reflect this
change.
Fixes gh-712
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Refactoring and enhancements to the advisor functionality.
New Advisor interfaces in the org.springframework.ai.chat.client.advisor.api package:
- Advisor: Base interface for all advisor types.
- RequestAdvisor: For advising on request data before execution.
- ResponseAdvisor: For advising on response data after execution, with enhanced streaming modes.
- CallAroundAdvisor and StreamAroundAdvisor: For around advice on synchronous and streaming requests respectively.
- AroundAdvisorChain and DefaultAroundAdvisorChain: To manage chaining of around advisors.
Advisor Chain and Prompt Generation:
- Added the DefaultAroundAdvisorChain class to manage the sequence of advisors applied around chat model methods.
- Adjusted the prompt generation (toPrompt) to integrate with the refactored AdvisedRequest object.
Refactoring and Updates:
- Replaced the deprecated RequestResponseAdvisor interface with RequestAdvisor and ResponseAdvisor across the spring-ai-core and test modules.
- Updated the DefaultChatClient and related classes to use the new Advisor interface, improving modularity and consistency.
- Refactored DefaultAdvisorSpec and DefaultChatClientRequestSpec to handle the new Advisor type, and revised advisor lists and methods accordingly.
- Enhanced the handling of streaming responses, introducing StreamResponseMode for better control during streaming scenarios.
- Precompute document token counts before batching into List<List<Document>>
- Introduce configurable reserve percentage for max input token count
Resolves#1260
* Fixes an issue with advisor name resolution
* Streamlines repeating code
* Add a new advisor strategy for ON_FINISH_REASON streaming responses, which is used by the Q&A advisor
* Improve observable instrumentation by passing the parent observation to the advisor observation
This commit introduces the OpenAiModerationModel and related classes:
- Add OpenAiModerationModel for content moderation
- Create OpenAiModerationOptions for configuration
- Implement OpenAiModerationProperties for Spring Boot setup
- Add integration tests in OpenAiModerationModelIT
- Add documentation
Co-authored-by: hemeda3 <hemeda3@users.noreply.github.com>
* Consolidate usage of “db.collection.name” attribute to track table name, collection name, index name, document name, or whatever concept a vector database uses to store data. Removed “db.index” that was use sometimes instead of “db.collection.name”. This usage is in line with the OpenTelemetry Semantic Conventions.
* Configure query response content to be included as a “span event” instead of a “span attribute” if the backend system supports that, similar to how we do for the model observations.
* Structure vector store observation attributes in dedicated enums, including one for the Spring AI Kinds to avoid hard-coding the same value in a lot of places. This follows the OpenTelemetry Semantic Conventions as much as possible. Also, adopt Spring usual non-null-by-default strategy as much as possible.
* Align vector store conventions to the chat model ones, and follow alphabetical order for values. This is particularly useful for the convention classes, for which the Micrometer performance of exporting telemetry data improves when key values are added already sorted to the context.
* Fix flaky test in Mistral AI.
* Improve Qdrant integration tests.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Enhance JsonReader to detect and process both JSON objects and arrays at
the root level. This update introduces type checking for the JSON root node
using JsonNode and leverages the Stream API to handle JSON arrays.
- Refactor parsing logic to support both JSON arrays and objects
- Rename variable: resourceArray to arrayResource for clarity
- Convert for-loop to Stream API for processing JSON keys
- Add additional tests to ensure proper array handling
- When embedding documents, allow batching the documents using some criteria.
- `BatchingStrategy` interface with a `TokenCountBatchingStrategy` implementation that uses
the openai max input token size of 8191 as the default.
- Add a default method in EmbeddingModel to embed document using this new batching strategy.
- Change `MilvusVectorStore` to make use of this new batching API.
- Adding unit tests for `TokenCountBatchingStrategy`.
- Adding openai integration test to call the embed API that uses batching.
Resolves https://github.com/spring-projects/spring-ai/issues/1214
Other vector stores will be updated seperately
Implementation:
- Introduce AbstractObservationVectorStore with instrumentation for add, delete, and similaritySearch methods
- Create VectorStoreObservationContext to capture operation details
- Implement DefaultVectorStoreObservationConvention for naming and tagging
- Add VectorStoreObservationDocumentation for defining observation keys
- Create VectorStoreObservationAutoConfiguration for auto-configuring observations
- Add VectorStoreObservationProperties to control optional observation content filters
- Update VectorStore interface with getName() method
- Modify PgVectorStore and SimpleVectorStore to extend AbstractObservationVectorStore
- Add vector_store Spring AI kind
Filters:
- Implement VectorStoreQueryResponseObservationFilter
- Add VectorStoreDeleteRequestContentObservationFilter and VectorStoreAddRequestContentObservationFilter
Enhancements:
- Update PgVectorStoreAutoConfiguration to support observations
- Add observation support to PgVectorStore's Builder
- Add VectorStoreObservationContext.Operation enum with ADD, DELETE, and QUERY options
Tests:
- Add tests for VectorStore context, convention, and filters
- Add VectorStoreObservationAutoConfiguration tests
- Add PgVectorObservationIT
Resolves#1205
- Implement observable chat responses in DefaultChatClient
- Add ChatClientObservationContext and related classes for metrics
- Update ChatClient and builder methods to support ObservationRegistry
- Enhance RequestResponseAdvisor with getName() method
- Add ChatClient streaming observability support
- Introduce ChatClientObservationDocumentation for metric key names
- Create DefaultChatClientObservationConvention for implementing conventions
- Add ChatClientInputContentObservationFilter for optional input content logging
- Update ChatClientAutoConfiguration to include new observation components
- Extend ChatClientBuilderProperties with observation configuration options
- Add unit tests for new observation classes and configurations
- Update AiOperationType and AiProvider enums with new values
- Implement safeguards and warnings for sensitive data in observations
Resolves#1206
* Surface more configuration APIs to ChatOptions
* Use abstraction in Observations directly instead of dedicated implementation
* Simplify metadata config in observations for defined models
* Improve merging of runtime and default options in OpenAI
* Fix missing option in Mistral AI
Relates to gh-1148
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
- Added support for OpenAI's structured outputs feature, which allows specifying a JSON schema for the model to match
- Introduced new record to configure the desired response format
- Added support for configuring the response format via application properties or the chat options builder
- Extend teh BeanOutputConverter to help generate JSON schema from a target domain object and convert the response.
- Added comprehensive tests to cover the new response format functionality
Resolves#1196
Integrated Micrometer's Observation into the OpenAiChatModel#stream reactive chain.
Included changes:
- Added ability to aggregate streaming responses for use in Observation metadata.
- Improved error handling and logging for chat response processing.
- Updated unit tests to include new observation logic and subscribe to Flux responses.
- Refined validation of observations in both normal and streaming chat operations.
- Disabled retry for streaming which used RetryTemplate - should use .retryWhen operator as the next step.
- Added an integration test.
Resolves#1190
Co-authored-by Christian Tzolov <ctzolov@vmware.com>
* Add model and dimensions to option abstraction
* Use abstraction in Observations directly instead of dedicated implementation
* Clean-up the merge of runtime and default embedding options in OpenAI
Relates to #gh-1148
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
* Add style to option abstraction
* Use abstraction in Observations directly instead of dedicated implementation
* Clean-up the merge of runtime and default image options in OpenAI and Stability AI
Related to #1148
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
- Update OllamaEmbeddingModel to support batch embedding requests
- Rename EmbeddingRequest/Response to EmbeddingsRequest/Response
- Add truncate option to control input truncation
- Update documentation and tests for new embedding API
- Remove deprecated withModel and withDefaultOptions methods
- Adjust default values for various Ollama model options
- Include response medata with response model name
Resolves#1158
* Observation APIs for chat, embedding and image models
* Conventions based on OpenTelemetry Semantic Conventions for GenAI
* Instrumentation for OpenAI chat, embedding, and image models
* Autoconfiguration for observability for OpenAI
Fixes gh-953
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
The autoconfiguration adds the FunctionCallbacks directly to the model's ChatOptions,
which results in the FunctionCallback being included in the request each time it is called.
The modification registers the container's FunctionCallback directly to the model's functionCallbackRegister
using the parent AbstractToolCallSupport constsructor.
Replace the handleFunctionCallbackConfigurations by simplified runtimeFunctionCallbackConfigurations.
Co-authored-by Christian Tzolov <ctzolov@vmware.com>
- factor out the common funciton calling logic form AnthropicChatModel to the AbstractToolCallSupport.
- improve the AbstractToolCallSupport isToolCall to handle OpenAi and Anthropic.
- fix an issue with the function calling streaming aggreagation leading to lost usage statistics.
- small code improvements for OpenAiChatModel.
- extend the OllamaApi with Tool, ToolCalls and Function and add Tool Role.
- make OllamaChatModel extend the AbstractToolCallSupport.
- extend the OllamaChatModel to convert the Spring AI messages to OllamaApi messages, including Tools.
- OllamaOptions implements FunctionCallingOptions.
- add OllamaApiToolFunctionCallIT for testing function calling.
- patch the AbstractToolCallSupport#isToolCall to take set of stop resons.
- add FunctionCallbackInPromptIT and FunctionCallbackWrapperIT function calling auto-configuration tests.
- extend OllamAutoConfiguration to support function calling registration.
- add function call tests to OllamChatAutoConfigurationIT.
- add OllamaWithOpenAiChatModelIT to OpenAi that uses the OpenAI API to call Ollama.
- move buildToolCallConversation and handleToolCalls to parent AbstractToolCallSupport.
- update Docs. add Ollama function call docs.
- update Ollama diagrams.
Resolves#720
The Lambda functions do not retain the type information, so we need to provide the input type explicitly.
Resolves#1052
Co-authored-by: liuzhifei <2679431923@qq.com>
- Breaking changes: Classes from the org.springframework.ai.openai.metadata.audio.transcription package have been moved to the org.springframework.ai.audio.transcription package.
- The AzureOpenAiAudioTranscriptionModel has been added to the auto-configuration.
- The spring.ai.azure.openai.audio.transcription prefix was introduced for properties.
- Introduces options properties which cover all of them (see: AzureOpenAiAudioTranscriptionOptions).
- fix missing MutableResponseMetadata
- add docs
- adjust code to updated ResponseMetadata design
- add test to AzureOpenAiAutoConfiguration
- add missing AzureOpenAiAudioTranscriptionModel tests