Commit Graph

435 Commits

Author SHA1 Message Date
Thomas Vitale
ef2e39a8ad Normalize Ollama model names in auto-pull feature
In order to support edge cases due to different naming formats, this PR introduced an explicit normalization logic to ensure the correct matching when checking for the availability of a certain model. Integration tests have been added to cover the different scenarios, including models from Ollama and from Hugging Face.

Also fix the container creation on the useTestcontainers flag (christian)

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-22 12:10:58 +02:00
Thomas Vitale
d5bc9c998c Consolidate Ollama auto-pull logic
Consolidate the Ollama auto-pull logic at startup time, supporting the auto-pull for the default models specified via configuration properties and for optional models specified for initialization.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-21 23:19:11 +02:00
Christian Tzolov
278a61fde4 Fix doc ref links 2024-10-21 10:24:28 +02:00
devholic22
854a7d99a3 fix: remove 1.0-SNAPSHOT in all OpenAI links
- remove 1.0-SNAPSHOT in all OpenAI links
2024-10-21 10:15:59 +02:00
devholic22
fd8746a99d fix: remove snapshot link in OpenAI TTS link
- remove snapshop link in OpenAI TTS link
2024-10-21 10:15:59 +02:00
Thomas Vitale
5e8cecd8b1 Enhance Ollama model auto-pull feature
* Fix configuration inheritance issue when default value is not specified.
* Make it possible to enable the auto-pull feature only for specific model types (e.g. for chat models only).
* Add the possibility to list explicit models to auto-pull at startup time.

Update Ollama model defaults and add new embedding model

* Change default chat model to Mistral
* Change default embedding model to mxbai-embed-large
* Add MXBAI_EMBED_LARGE to OllamaModel enum
* Remove DEFAULT_MODEL constant from OllamaOptions
* Update relevant classes to use new defaults

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Co-authored-by:Christian Tzolov <ctzolov@vmware.com>
2024-10-20 08:20:16 +02:00
Josh Long
d17c0720fd reproducible. 2024-10-19 13:29:46 +03:00
Thomas Vitale
8eef6e6da5 Ollama: Pull models automatically at startup
* Introduce support for Ollama model auto-pull at startup time
* Enhance support for Ollama model auto-pull at run time
* Update documentation about integrating with Ollama and managing models
* Adopt Builder pattern in Ollama Model classes for better code readability
* Unify Ollama model auto-pull functionality in production and test code
* Improve integration tests for Ollama with Testcontainers
2024-10-18 15:42:28 +02:00
Christian Tzolov
322d0fb336 Refactor Ollama implementation and improve documentation
- Enhance OllamaModelPuller with configurable retry timeout
 - Update test cases to use LLAMA3_1 instead of LLAMA3_2
 - Improve Ollama documentation with clearer prerequisites and model pulling instructions
 - Update Spring AI introduction page with new logo and diagram
 - Remove unnecessary main method from OllamaModelPuller
2024-10-17 12:54:47 +02:00
Christian Tzolov
2a9f9c811d Ollama: add model auto-pull feature
- Introduce internal OllamaModelPuller helper for managing model availability
 - Add pullMissingModel option to OllamaOptions
 - Implement auto-pull functionality in OllamaChatModel and OllamaEmbeddingModel
 - Update tests to cover new auto-pull feature
 - Add reference documentation

 Resolves #526
2024-10-17 00:14:59 +02:00
Mark Pollack
d0c53392aa Update spring-javaformat to version 0.0.43
- Ran ./mvnw spring-javaformat:apply that made some new formatting changes
2024-10-16 15:50:04 -04:00
Christian Tzolov
2e0a51fac5 Streamline dependencies and improve API consistency
- Remove unnecessary spring-web dependencies
 - Update third-party library versions
 - Refactor API classes to use consistent header handling
 - Remove ApiUtils class and inline its functionality
 - Adjust RestClient and WebClient builder usage in autoconfiguration
 - Replace direct RestClient.Builder injections with ObjectProvider<RestClient.Builder>
   and WebClient.Builder injections with ObjectProvider<WebClient.Builder>
 - Update ChromaVectorStoreAutoConfiguration to use ObjectProvider
 - Rename MongoDbAtlasLocalContainerConnectionDetailsFactoryTest to IT
 - Switch spring-ai-chroma-store dependency from spring-web to spring-webflux
 - Simplify ChromaApi constructor by using method reference for default headers
 - Adjust import order

 Resolves #1066
 Resolves #524
2024-10-16 15:46:03 -04:00
Thomas Vitale
f0f3501f8e Ollama integration tests fix
* Disable tests by default
* Improve Testcontainers configuration
2024-10-15 09:06:44 +02:00
Thomas Vitale
cc518b2cbc Support Ollama APIs for model management
* Extend the OllamaApi to support listing, copying, deleting, and pulling models programmatically.
* Improve setup for integration testing with Ollama and Testcontainers.

Enables gh-526

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-14 22:03:59 -04:00
dafriz
c9f50da12a Add metadata to BedrockAnthropic3ChatModel response
This commit enhances the Bedrock Anthropic model's output:

- Add response ID, model name, and usage data to ChatResponseMetadata
- Introduce DefaultUsage class for token usage information
- Update BedrockAnthropic3ChatModel to include new metadata
- Add Jackson annotations for serialization/deserialization
- Implement unit tests for DefaultUsage

These changes provide structured, serializable metadata in the
ChatResponse, improving the model's output with additional
information.
2024-10-14 14:58:37 -04:00
Christian Tzolov
6d38c85ff6 Refactor Ollama usage metadata to add embedding support
- Extend the OllamaApi.EmbeddingsResponse with total_duration,
   load_duration and prompt_eval_count fields
 - Rename OllamaUsage to OllamaChatUsage for clarity
 - Add OllamaEmbeddingUsage to track embedding-specific usage metrics
 - Update OllamaEmbeddingModel to use OllamaEmbeddingUsage
 - Extend EmbeddingsResponse with additional metadata fields
 - Update tests to reflect new usage tracking for embeddings

 Resolves #1536
2024-10-14 11:52:23 +02:00
Mark Pollack
4c83fe8302 Guard against NPE in ZhiPu embedding model
- Update retry test to pass - needs investigation
2024-10-08 23:37:00 +02:00
Mark Pollack
4a892b5269 Release version 1.0.0-M3 2024-10-08 23:18:50 +02:00
GR
cc3d338fa3 optimize: remove useless TODO comment on ZhiPu chat model 2024-10-08 20:53:32 +02:00
GR
77586d5f86 Add observability to QianFan image model 2024-10-08 20:51:11 +02:00
GR
73df85d5eb MiniMax embedding model autoconfiguration
- Add context isolation in embedding unit test
2024-10-08 20:47:41 +02:00
GR
3309c27254 Add observability to ZhiPu embedding model 2024-10-08 20:36:45 +02:00
Christian Tzolov
2cd85a0781 Remove unnecessary resource cleanup in TransformersEmbeddingModel 2024-10-08 14:38:47 +02:00
Christian Tzolov
3367ebd897 Prevent double-closing of tensors in TransformersEmbeddingModel 2024-10-08 14:30:08 +02:00
Mark Pollack
e30105e5fb minor test fixes 2024-10-08 14:26:35 +02:00
Christian Tzolov
d50e7e2a8d Adjust Bedrok reponse API models 2024-10-08 13:50:34 +02:00
GR
d4ab868921 Add observability to QianFan embedding model 2024-10-08 13:34:32 +02:00
Christian Tzolov
7ed73e8478 Improve resource management in TransformersEmbeddingModel
- Prevent potential resource leaks
 - Wrap OnnxTensor creation in try-with-resources block
 - Explicitly close inputIds, attentionMask, and tokenTypeIds tensors
 - Close OrtSession.SessionOptions() in afterPropertiesSet
 - Add javadoc

Resolves #1427
2024-10-08 12:30:46 +02:00
Christian Tzolov
10193431f6 Observability instrumentation for VertexAI Text Embedding 2024-10-08 11:20:08 +02:00
Christian Tzolov
d71ca0e68e Add observability support to TransformersEmbeddingModel
- Integrate ObservationRegistry and EmbeddingModelObservationConvention
 - Update TransformersEmbeddingModel to use observations
 - Add TransformersEmbeddingModelObservationTests
 - Update TransformersEmbeddingModelAutoConfiguration for observation support
 - Add ONNX to AiProvider enum
2024-10-08 10:48:48 +02:00
GR
7bd8a17d33 Add observability to zhipu chat model 2024-10-08 10:38:18 +02:00
GR
6203325f30 Add observability to qianfan chat model 2024-10-08 10:33:58 +02:00
GR
1606383704 Add observability to moonshot chat model 2024-10-08 00:40:27 +02:00
GR
ee7d2b2556 Add observability to minimax chat model
- add observability to minimax embedding model
- fix chat web search result error
- fix minimax auto configuration
2024-10-08 00:24:22 +02:00
Soby Chacko
bac002bf83 Observation for Vertex gemini chat model streaming operation
- Adding observability for Vertex Gemini chat model streaming call
- Updating auto-configuration for gemini chat model with the observability components
- Integration test for streaming observability
2024-10-08 00:14:47 +02:00
Mark Pollack
06392f90cb Update azure embedding test not to set dimensions 2024-10-08 00:10:46 +02:00
Christian Tzolov
6f39704d46 Extend observation support to Azure OpenAI models (#1491)
- Implement observation instrumentation for AzureOpenAiEmbeddingModel
 - Create AzureOpenAiEmbeddingModelObservationIT for integration testing
 - Update AzureOpenAiAutoConfiguration to support observation
 - Introduce ObservationRegistry and observation conventions
2024-10-07 17:43:13 -04:00
Soby Chacko
0763d78fef Add observability for the regular imperative call in VertexAi Gemini chat model
- Integrate ObservationRegistry for instrumentation in VertexAiGeminiChatModel's non-streaming call
- Add ChatModelObservationContext and related classes for observation
- Refactor createGeminiRequest method to support runtime options for imperative calls
- Implement observation for non-streaming chat operations in VertexAiChatModelObservationIT
- Add VertexAiGeminiConstants class for provider name

This commit enhances the VertexAiGeminiChatModel with observability features
for the non-streaming, imperative call() method. It allows for better
monitoring and instrumentation of synchronous chat operations. The changes
include refactoring to improve runtime option handling for these calls and
adds integration tests for the new observability features.
2024-10-07 23:25:40 +02:00
Christian Tzolov
9678ea53e8 Fix NPE in a test fixture 2024-10-07 20:48:10 +02:00
Mark Pollack
64b147e699 Restructure OpenAI and AzureOpenAI ChatClientITs
- Use List<ChatResponse> to better examine the full response
2024-10-07 17:29:11 +02:00
Mark Pollack
22a61548ac Fix Keyword extractor test as chatgpt's response changed 2024-10-07 16:25:19 +02:00
Christian Tzolov
38082de0f8 Refactor FunctionCallback API to use ToolContext instead of Map<String, Object>
- Replaced `Map<String, Object>` with `ToolContext` in the `FunctionCallback`, `AbstractFunctionCallback`, and related classes.
 - Updated all BiFunction definitions to use `ToolContext` as the second parameter,
   enhancing the clarity and structure of the tool context management.
 - Modified `FunctionCallbackWrapper` and `FunctionCallbackContext` to adapt to the new `ToolContext` parameter.
 - Adjusted the handling of tool context in the documentation and test classes.
 - Updated relevant test cases to reflect the API changes and modified the function handling logic to ensure consistency.
2024-10-07 16:15:55 +02:00
Christian Tzolov
4e7e4cf2b5 Add tool context support to ChatClient and related classes
- Introduce toolContext to ChatClient, DefaultChatClient, and AdvisedRequest
 - Add methods to set and manage toolContext via the FunctionCallingOptions
 - Update tests to include toolContext in relevant scenarios
 - Implement toolContext handling in function calling options
2024-10-07 11:50:41 +02:00
Mudabir Hussain
2090826656 Fix NullPointerException with Ollama + tool calls
Fixed #1459
2024-10-07 11:48:40 +02:00
Hyune-c
e12372171b Fix anthropicApi visibility in AnthropicChatModel 2024-10-06 22:41:23 +02:00
Soby Chacko
8ea56329ac Adding observability for AzureOpenAiChatModel streaming 2024-10-06 15:37:15 +02:00
Thomas Vitale
21504a6296 Keep model metric attributes fixed for Prometheus
Unlike other metrics implementations supported by Micrometer, when using the Prometheus integration, all metric attributes are supposed to have a value, or else the related metrics are dropped.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 15:36:49 +02:00
Thomas Vitale
3b1c68ac10 Improve optional values handling in chat model observations
Chat model observations support several key-value pairs, coming from the Spring AI abstractions.
Currently, whenever a value is not available (either because not configured by the user or not supported by the model provider), a span/metrics is generated anyway with value none.
That causes several issues, including an unneeded increase in time series, challenges in alerting/monitoring (especially for integer/double attributes that suddenly are populated with a string), and incompliance with the OpenTelemetry Semantic Conventions (according to which, attributes should be excluded altogether if there's no value).
This pull request changes the conventions for chat model observation to exclude the generation of span/metrics attributes for optional values which don't have any value.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-05 23:55:16 +02:00
Christian Tzolov
9c10a08bef Add tool context support to chat options and enhance function calling
This commit adds support for tool context in various chat options classes across
  different AI model implementations and enhances function calling capabilities.

  The tool context allows passing additional contextual information to function callbacks.

 - Add toolContext field to chat options classes
 - Update builder classes to support setting toolContext
 - Enhance FunctionCallback interface to support context-aware function calls
 - Update AbstractFunctionCallback to implement BiFunction instead of Function
 - Modify FunctionCallbackWrapper to support both Function and BiFunction and
   to use the new SchemaType location
 - Add support for BiFunction in TypeResolverHelper
 - Update ChatClient interface and DefaultChatClient implementation to support
   new function calling methods with Function, BiFunction and FunctionCallback arguments
 - Refactor AbstractToolCallSupport to pass tool context to function execution
 - Update all affected <Model>ChatOptions with tool context support
 - Simplify OpenAiChatClientMultipleFunctionCallsIT test
 - Add tests for function calling with tool context
 - Add new test cases for function callbacks with context in various integration tests
 - Modify existing tests to incorporate new context-aware function calling capabilities
 - Add docs in in openai function calling

 Resolves #864, #1303, #991
2024-10-04 16:47:42 -04:00
Soby Chacko
b68112d4cb Add Micrometer observability for Azure OpenAI chat
Implement observability for imperative calls in AzureOpenAiChatModel:

* Integrate ObservationRegistry to track metrics and events
* Create observation context and define conventions for consistency
* Add integration test to verify chat model observations
* Update AiProvider enum with new AZURE_OPENAI entry
2024-10-04 16:09:18 -04:00