Commit Graph

507 Commits

Author SHA1 Message Date
Peter Dolukhanov
26c5674acb Fix where previous Assistant Messages were not being added to the parts list.
Results in: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini
2024-09-10 11:18:36 +02:00
GR
b38cbe6386 Enhance MiniMax chat model compatibility and add tests
- Add web search mode response in choice.message for enhanced
compatibility
- Implement web search mode for stream mode
- Add comprehensive unit tests for new features

Related to #1292

feat: enhance the compatibility of the minimax model and tests, related issue #1292
2024-09-09 17:56:04 -04:00
inpink
897a4114f5 Fix Javadoc comments in OpenAiAudioApi and OpenAiApi
- Correct OpenAiAudioApi Javadoc: remove chat completion reference
- Add missing @param for webClientBuilder in OpenAiApi constructor
2024-09-09 17:48:05 -04:00
Christian Tzolov
28276d14a4 Refactor Advisor Interfaces and add AroundAdvisor support
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.
2024-09-05 12:35:34 -04:00
Craig Walls
3cab5bd009 Autowire WebClient.Builder into OllamaApi 2024-09-04 14:11:21 -04:00
Christian Tzolov
bf8dabfb11 Improve stream advisor processing
* 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
2024-09-03 21:41:36 -04:00
Mark Pollack
e1884d1d92 Next development version 2024-08-23 18:47:37 -04:00
Mark Pollack
43ad2bdb97 Release version 1.0.0-M2 2024-08-23 18:46:58 -04:00
GR
4fac212b0d Add web search capability to MiniMax model
Implement web search functionality for the MiniMax model.
Includes unit tests
This enhancement expands the model's ability to access and utilize current information from the internet.

Resolves #1245
2024-08-23 12:17:45 -04:00
GR
0927bd197d Fix MiniMax model function call implementation
Implement function call capability for MiniMax model and add unit tests based on new tool classes.
Address most scenarios, but note limitations in complex English contexts
with multiple function calls. Weather query example: may stop
prematurely when querying multiple locations due to single-location
parameter limit. This behavior stems from model performance constraints.

Streaming function calling is not passing tests, will be address seperately.

Resolves #1077

Implement function call capability for the Moonshot model. Include unit
tests to verify the new functionality. This feature addresses the
requirements outlined in issue #1058.
fix: MiniMax function call

review
2024-08-23 12:03:33 -04:00
GR
611c9493e3 Add function call support for Moonshot model
Implement function call capability for the Moonshot model. Include unit
tests to verify the new functionality.

Resolves #1058
2024-08-23 11:43:07 -04:00
GR
935e1a38ed Add ZhiPu model support for AbstractToolCallSupport
Implement ZhiPu function call to work with AbstractToolCallSupport
framework. Add unit tests for function call functionality.

Resolves #1078.
2024-08-23 11:12:21 -04:00
Szymon Ochnio
197fe8105c Fix Azure chat client image handling for byte arrays
Resolve issue with AzureOpenAiChatModel processing non-public images as
byte arrays. Implement handling for both URL strings and byte arrays,
converting latter to base64 encoded data URLs. Add test case for
resource-based media data. Update documentation with sample for
classpath resources.
2024-08-23 10:50:24 -04:00
Christian Tzolov
99a4fec214 Remove the reactive advisor observability support
-  Add Anthropic WebClient.Builder autoconfiguration to activate the OOTB WebClient obsercabilty support.
2024-08-23 09:57:49 -04:00
Mark Pollack
793052c2e9 Add googleSearchRetrieval as an option for VertexAIGeminiChatOptions
- Add test
2024-08-22 19:26:36 -04:00
KimMinjeong
bc55bc7196 Add responseMimeType option in VertexAiGeminiChatOptions
- Add test
2024-08-22 18:48:59 -04:00
Mohammed, Ahmed yousri salama (Canada)
189468127c Implement OpenAI Moderation model
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>
2024-08-22 17:39:16 -04:00
GR
a3c0927c9b Add MiniMax chat option to mask sensitive information
This commit introduces a new boolean option 'maskSensitiveInfo' for
the MiniMax API model support in Spring AI. This feature allows users
to control whether sensitive information in the output is masked.

Relevant unit tests have been added to ensure proper functionality.

Resolves: #1216
2024-08-22 11:23:59 -04:00
Thomas Vitale
036093a42b Enhance vector store observability support
* 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>
2024-08-22 09:38:59 +02:00
wmz7year
32a4652aba Fix out of bounds exception in BedrockAnthropic3ChatModel
Handle the case where AnthropicChatResponse content is empty to prevent
an out of bounds exception. This ensures that the model behaves correctly
even when no content is returned in the response.
2024-08-20 14:55:47 -04:00
Soby Chacko
949f1ed4e8 Add Batching strategy for embedding documents
- 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
2024-08-20 14:08:06 -04:00
Thomas Vitale
3b7522b6c0 Model observability for Anthropic
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 01:13:43 -04:00
Thomas Vitale
80fe5e4897 Model observability for Mistral
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 00:36:31 -04:00
Christian Tzolov
46893b0a99 Add documentation for NVIDIA LLM API integration
Add NVIDIA LLM API - OpenAI Integration Test.
2024-08-19 21:53:20 +02:00
Seongmin Kim
58c292ab87 Remove unnecessary if statement in test code
* Remove unnecessary if statement in 'toolFunctionCall' test code from OpenAiApiToolFunctionCallIT
* Reformat using java-format plugin
2024-08-19 15:40:41 -04:00
uzhuraul
c2b6e85608 Fix OpenAiAudioSpeechOptions speed description
formatting
2024-08-19 15:26:41 -04:00
Thomas Vitale
10e1e13fa2 Add observability support for Ollama
- Improve ITs to reuse a single container across tests
2024-08-16 14:29:23 -04:00
KAMOsama
3bef5c12bf Remove redundant withRateLimit call from OpenAiChatModel.
The withRateLimit call is redundant as rateLimit is already handled conditionally elsewhere. Its removal helps simplify the code and improves maintainability.
2024-08-16 11:52:27 -04:00
Johnny Lim
2d6117b796 Fix typos (#1223) 2024-08-15 10:27:12 -04:00
Christian Tzolov
d538e00643 Replace the Embedding format from List<Double> to float[]
- Adjust all affected classes including the Document.
 - Update docs.

Related to #405
2024-08-13 11:53:08 -04:00
Thomas Vitale
bf84d5945e Streamline ChatOptions
* 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>
2024-08-10 14:48:05 +02:00
Christian Tzolov
af25430054 Update OpenAI chat UML diagram 2024-08-09 10:05:39 +02:00
Christian Tzolov
2da161cfb1 Improve OpenAI structured outputs support
- Add `TEXT` to the supported ResponseFormat types
- Add JsonSchema record for structured output configuration
- Update OpenAI chat documentation with details on Structured Outputs
- Clarify usage of JSON_SCHEMA response format in properties and code examples
- Update Structured Output Converter docs to mention OpenAI Structured Outputs
2024-08-09 08:22:58 +02:00
Christian Tzolov
91afed5ae5 OpenAi: Add support for structured outputs and JSON schema
- 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
2024-08-08 17:00:18 -04:00
TarasVovk669
866b262cdd Add refusal field to ChatCompletionMessage and related classes
- Updated OpenAiChatModel, OpenAiApi, and OpenAiStreamFunctionCallingHelper to include the `refusal` field in metadata.
- Adjusted constructors and methods to handle the new `refusal` attribute.
- Modified related tests to account for the new `refusal` field.
- Add the refusal field value to the Spring AI AssistantMessage metadata

Resolves #1178
2024-08-08 19:19:09 +02:00
Dariusz Jędrzejczyk
478f180297 Add OpenAiChatModel stream observability
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>
2024-08-08 13:05:28 +02:00
Thomas Vitale
08ccc10a16 Streamline EmbeddingOptions
* 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>
2024-08-08 11:35:08 +02:00
Thomas Vitale
17ba1fc3ba Streamline ImageOptions
* 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>
2024-08-07 10:19:08 +02:00
Thomas Vitale
8784dee16f Update convention for chat finish reason in LLM observations
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-07 09:25:06 +02:00
Thomas Vitale
9a8a133d93 Fix NPE in OpenAiUsage
Fix gh-1152

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-04 11:29:06 +02:00
Christian Tzolov
4cacbe8468 Refactor Ollama embedding model implementation
- 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
2024-08-04 11:21:45 +02:00
Christian Tzolov
3978e8ecc2 Enhance OpenAI Authentication and Configuration
- Add org-id and project-id properties with unified merging logic
- Update autoconfig and docs for all OpenAI models
- Introduce OpenAiChatOptions#httpHeaders option
- Add integration test for httpHeaders and update docs

Resolves #1141
2024-08-03 22:30:37 +02:00
Thomas Vitale
12cf38a669 Make MeterObservationHandler conditional on MeterRegistry bean
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-02 22:11:47 +02:00
Thomas Vitale
6bdb395686 Initial observability for Spring AI
* 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>
2024-08-01 22:25:43 +02:00
Christian Tzolov
a077e1b952 patch for 3f19c4a6e5 2024-08-01 17:40:28 +02:00
Christian Tzolov
3f19c4a6e5 Add OpenAI paralel funciton call option
Resolves #1143
2024-08-01 17:11:11 +02:00
kamosama
7c800f35b8 Fix a FunctionCallback inside a container that pollutes the global model's ChatOptions
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>
2024-07-30 20:11:14 +02:00
Christian Tzolov
d875d48bd3 Streamline Azure OpenAI Function Calling 2024-07-30 11:52:44 +02:00
Christian Tzolov
6978e8f111 Streamline the VertexAI Gemini Function Calling
- Align with AbstractToolCallSupport
2024-07-30 10:46:38 +02:00
Christian Tzolov
14b5397ca0 Streamline the MistralAI Function Calling
Align with the parent AbstractToolCallSupport and remove the redundant code.
2024-07-30 10:43:39 +02:00