Commit Graph

543 Commits

Author SHA1 Message Date
Ilayaperumal Gopinathan
f252b2417a Refactor ChatOptions Builder
- Deprecate existing ChatOptionsBuilder and its inner class DefaultChatOptions
- Create a new builder interface ChatOptions.Builder for building the Chat options
- Create an explicit DefaultChatOptions
- Create DefaultChatOptionBuilder which can create DefaultChatOptions
- Add javadoc for the deprecated Builder

Resolves #1875
2024-12-12 10:06:16 -05:00
Gareth Evans
e7bd8d5da1 feat: allow stream usage to be set for azure openai requests 2024-12-11 21:32:45 +00:00
Ilayaperumal Gopinathan
f7e8e7f388 Use RequiresAwsCredentials in AWS credentials based tests
- Update Spring AI Bedrock tests to use the @RequiresAwsCredentials to check the AWS keys
2024-12-11 18:21:14 +00:00
Christian Tzolov
ad87c122d9 Fix duplicaiton 2024-12-10 15:39:59 +01:00
Ilayaperumal Gopinathan
37cf20dfe4 Fix OpenAI ChatResponse usage calculation when toolcalling is used
- Fix OpenAI ChatModel's call() operation

   - When toolcalling is used, calculate cumulative usage from the preceding ChatResponses

 - Fix OpenAI ChatModel's stream() operation

   - Make sure that cumulative usage is calculated from the ChatResponse which has a valid usage
     - Use overlapping buffer to check and store the usage from the response that holds the usage.

 - Add tests for both call() and stream()
2024-12-10 15:38:18 +01:00
Christian Tzolov
ebc91680f8 Improve OllamaWithOpenAiChatModelIT stability 2024-12-10 15:14:35 +01:00
Christian Tzolov
16a9d891aa tests Improve stability for PerplexityWithOpenAiChatModelIT 2024-12-10 14:29:50 +01:00
Mark Pollack
dfbc394f83 Make Document support single text or media content
The Document class previously allowed multiple media entries while also having a
text field, leading to ambiguity in content handling. This change enforces a
clear separation between text and media documents to prevent content type
confusion and simplify document processing.

A Document now must contain either text content or a single media entry, but
never both. This aligns with the class's primary use in ETL pipelines where
clear content type boundaries are essential for proper embedding generation and
vector database storage.

Additional architectural changes:
- Document now implements a cleaner API by removing deprecated methods
- Removed MediaContent interface implementation from Document class
- Document.getMedia() now returns a single Media object instead of Collection
- Removed EMPTY_TEXT constant in favor of proper null handling
- Constructor signatures simplified and streamlined
- Builder pattern improved to enforce single content type constraint

The breaking changes include:
- Media is now a single entry instead of a collection
- Content field renamed to text for clarity
- Removed support for mixed content types
- Simplified builder API to prevent ambiguous construction

Prefer using text-related methods over deprecated content methods to
better reflect the actual content type being handled and improve API clarity.
2024-12-09 23:25:38 -05:00
Christian Tzolov
9a5d61cc05 Bedrock Converse: Add multimodal support for documents, images and videos
- Add BedrockMediaFormat class to handle media format conversions for documents, images and videos
- Enhance Media class with builder pattern and comprehensive format constants
- Refactor BedrockProxyChatModel to support multimodal content handling
- Add integration tests for PDF, image and video processing
- Add unit tests for Media and BedrockMediaFormat classes
- Upgrade AWS SDK version from 2.26.7 to 2.29.29
- Remove redundant aws.sdk.version property in favor of awssdk.version

Documentation updates for Bedrock Converse API

- Added multimodal support documentation (images, video, documents)
- Added deprecation notices for existing Bedrock model implementations
- Updated feature comparison table
- Added warning notes about transitioning to Converse API
2024-12-09 22:54:53 -05:00
Mark Pollack
778752a14d Disable brittle IT that pulls models from hugging face for Ollama 2024-12-09 10:09:30 -05:00
Mark Pollack
87d5112fe0 Disable brittle IT that pulls models from hugging face for Ollama 2024-12-09 09:37:43 -05:00
Eddú Meléndez
d084916ac3 Polish PostgresMlEmbeddingModelIT 2024-12-09 09:25:19 +00:00
Christian Tzolov
9f775ab2c2 feat(ollama): upgrade to 0.5.1 and improve code quality
- Upgrade Ollama version used for IT from 0.3.14 to 0.5.1
- Fix string comparison pattern in OllamaModelManager
- Re-enable stream function calling test
- Improve multimodal test assertions
2024-12-09 10:08:07 +01:00
Mark Pollack
b9e4123b5d Temporarily disable Ollama streaming function calling tests 2024-12-08 22:15:49 -05:00
Christian Tzolov
c4ca5826f7 feat(ollama): Add streaming support for function calls and improve OllamaApi
- Implement streaming tool call support in OllamaApi and OllamaChatModel
- Add OllamaApiHelper to manage merging of streaming chat response chunks
- Remove @Disabled annotations for streaming function call tests
- Update documentation to reflect new streaming function call capabilities
- Add a new default constructor for ChatResponse
- Update Ollama chat documentation to clarify streaming support requirements
- Deprecated withContent(), withImages(), and withToolCalls() methods
- Replaced with content(), images(), and toolCalls() methods

Add token and duration aggregation for Ollama chat responses

- Modify OllamaChatModel to support accumulating tokens and durations across multiple responses
- Update ChatResponse metadata generation to aggregate usage and duration metrics
- Add tests to verify metadata aggregation behavior

Refactor Ollama duration fields and tests

- Replace Duration fields in OllamaApi.ChatResponse with Long to represent durations in nanoseconds, ensuring precision and compatibility.
- Update methods to convert Long nanoseconds to Duration objects (getTotalDuration, getLoadDuration, getEvalDuration, getPromptEvalDuration).
- Adjust merge logic in OllamaApiHelper to sum Long values for duration fields.
- Modify test cases in OllamaChatModelTests to align with Long duration representation and Duration.ofNanos conversions.
- Add new test class OllamaDurationFieldsTests to validate JSON deserialization and Duration conversion for duration fields.

Resolves #1847
Related to #1800
Resolves #1796
Related to #1307

test: Update OllamaWithOpenAiChatModelIT integration tests

- Remove @Disabled annotation for streamFunctionCallTest
- Add inputType for function callback in stream function call test
2024-12-08 21:28:10 +00:00
Ilayaperumal Gopinathan
ebd29e0959 GH-1826 Fix EmbeddingModel's usage on Document#embedding
- Since the Document object's reference to the `embedding` is deprecated and will be removed, the VectorStore implementations require a way to store the embedding of the corresponding Document objects

     - One way to fix this is, to have the EmbeddingModel#embed to return the embeddings in the same order as that of the Documents passed to it.

       - Since both the Document and embedding collections use the List object, their iteration operation will make sure to keep them in line with the same order.

       - A fix is required to preserve the order when batching strategy is applied.
	  - Updated the Javadoc for BatchingStrategy
          - Fixed the Document List order in TokenCountBatchingStrategy

    - Refactored the vector store implementations to update this change

Resolves #GH-1826
2024-12-05 21:37:27 +01:00
Christian Tzolov
6cfe5e79e8 add chatclient IT for openai multimodal Audio resposne 2024-12-05 06:50:28 +01:00
Mark Pollack
b405536bba Fix failing OpenSearch IT and disable Mistral function calling IT
- PaymentStatusFunctionCallingIT in org.springframework.ai.mistralai.api.tool
  is failing.  Needs investigation.
  See https://github.com/spring-projects/spring-ai/issues/1853
- OpenSearchVectorStoreWithOllamaIT updated to pull model if not available.
2024-12-02 16:45:02 -05:00
Thomas Vitale
fe58fd30eb Support similarity scores in Document API
Document
* Introduced “score” attribute in Document API. It stores the similarity score.
* Consolidate “distance” metadata for Documents. It stores the distance measurement.
* Adopted prefix-less naming convention in Document.Builder and deprecated old methods.
* Deprecated the many overloaded Document constructors in favour of Document.Builder.

Vector Stores
* Every vector store implementation now configures a “score” attribute with the similarity score of the Document embedding. It also includes the “distance” metadata with the distance measurement.
* Fixed error in Elasticsearch where distance and similarity were mixed up.
* Added missing integration tests for SimpleVectorStore.
* The Azure Vector Store and HanaDB Vector Store do not include those measurements because the product documentation do not include information about how the similarity score is returned, and without access to the cloud products I could not verify that via debugging.
* Improved tests to actually assert the result of the similarity search based on the returned score.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-12-02 14:54:28 -05:00
Ilayaperumal Gopinathan
50223d20e3 Add IT test for OpenAI stream function call usage verification 2024-12-02 11:05:16 +00:00
Christian Tzolov
cdffc72c14 feat(openai) - Support for audio output in OpenAI chat model
- Introduced new options for audio output modalities in ChatCompletionRequest
- Added AudioParameters configuration for voice and audio format selection
- Enhanced OpenAiChatModel to handle audio generation and embedding
- Updated AssistantMessage and Media classes to support audio media
- Added integration tests for audio output functionality
- Implemented support for text and audio multi-modal responses
- Updated Spring AI's chat model comparison table to clarify OpenAI's input/output modalities
- Added new configuration properties for audio output:
  * spring.ai.openai.chat.options.output-modalities
  * spring.ai.openai.chat.options.output-audio
- Extended documentation to explain audio output generation with the gpt-4o-audio-preview model
- Updated Spring Boot configuration metadata to support new audio-related properties
- Included auto-configuration integration test for chat model with audio response generation

Resolves #1841
2024-11-28 20:27:02 +00:00
Christian Tzolov
6a195ee9fe refactor(core): extract common function callback builder functionality
Extracts shared function callback builder functionality into DefaultCommonCallbackInvokingSpec
base class, reducing code duplication across builder implementations.
Makes FunctionInvokingSpec and MethodInvokingSpec extend CommonCallbackInvokingSpec for better
code organization. Also fixes function/description builder order in Anthropic tests.

- Introduced a common base class for function callback builders to centralize shared logic
- Standardized the order of method chaining for function and description in multiple AI model test classes
- Refactored test cases across various AI model integrations
- Corrected builder method order from .description().function() to .function().description()
  and .description().method() to .method().description()
- Updated multiple test files to consistently use .function() before .description()
- Updated documentation examples to reflect new builder method order
- Modified DefaultFunctionCallbackResolver to maintain new builder method order
- Updated DefaultChatClient and ChatClient test classes to reflect new builder pattern
- Simplified callback specification by removing parent spec reference
- Removed cascading getter logic for description, schema type, and other properties
- Minor adjustments to function callback builder and invoking specs
2024-11-28 19:28:08 +00:00
Alexandros Pappas
dcc8d5b620 feat: Add Perplexity AI integration and documentation updates
- Introduced `PerplexityWithOpenAiChatModelIT` integration test for Perplexity AI with OpenAI Chat Model.
  - Includes various test cases for role-based prompts, streaming responses, token usage validation, and output converters.
  - Added tests for function calls and metadata validation.
- Updated Antora navigation (`nav.adoc`) to include Perplexity AI documentation link.
- Enhanced chat model comparison documentation to highlight Perplexity AI integration.
- Added a dedicated `perplexity-chat.adoc` page under `spring-ai-docs` to provide detailed documentation for integrating Perplexity AI.
  - Covers API prerequisites, auto-configuration, and runtime options.
  - Explains configuration properties such as `spring.ai.openai.base-url`, `spring.ai.openai.chat.model`, and `spring.ai.openai.chat.options.*`.
  - Provides examples for environment variable setup and runtime overrides.
  - Highlights limitations like lack of multimodal support and explicit function calling.
  - Includes a sample Spring Boot controller demonstrating integration usage.
  - Links to Perplexity documentation for further reference.
2024-11-28 19:11:27 +01:00
Thomas Vitale
d0a0c878f8 Portable ChatOptions ignored by OpenAiChatModel
When calling the OpenAiChatModel with ChatOptions, they are always ignored. Options are considered only when using OpenAiChatOptions or FunctionCallingOptions.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-11-28 16:44:08 +01:00
Ilayaperumal Gopinathan
9ebc6d2c3c Code cleanup
- Fix javadoc for Qdrant vector store
 - Fix checkstyle errors
2024-11-27 20:35:39 +00:00
Thomas Vitale
33f431e4a7 feat(openai) - Support audio input and output modality
- Added support for audio input and output in OpenAI Chat Completion API
- Introduced new audio-related parameters, enums, and record types
- Updated ChatCompletionMessage, ChatCompletionChunk, and related classes
- Added new AudioParameters, AudioOutput, and InputAudio record types
- Implemented method to handle audio media content conversion
- Included new model enum for GPT-4o audio preview
- Extended existing API classes to accommodate audio modalities
- Modified usage tracking and metadata classes to handle audio-specific token details
- Improved ModelOptionsUtils with additional JSON utility methods

Tests:
- Updated test classes to validate audio input and output functionality
- Added integration tests for multimodal audio input with streaming and non-streaming methods
- Created parameterized tests for audio-enabled models
- Enhanced OpenAI API integration tests to cover audio-related scenarios

Docs:
- Updated documentation in spring-ai-docs to explain audio multimodality support

Resolves #1560
2024-11-27 12:46:43 +01:00
Christian Tzolov
479a095976 refactor: introduce FunctionCallbackResolver interface
- Introduces a new FunctionCallbackResolver interface to define the strategy for
  resolving FunctionCallback instances.
- Renames FunctionCallbackContext to DefaultFunctionCallbackResolver to better reflect its
  implementation role. Updates all related components to use the new interface.
- Update the affected AI model implementations
  - Replaces FunctionCallbackContext parameter with FunctionCallbackResolver in all
    model constructors
  - Updates builder patterns to use functionCallbackResolver() method instead of
    withFunctionCallbackContext()
  - Deprecates old withFunctionCallbackContext() methods in builders to guide
    migration
- Updates integration tests to use DefaultFunctionCallbackResolver
- Improves documentation to clarify the resolver's role in function callbacks
- Moves SchemaType enum from FunctionCallbackContext to FunctionCallback

Resolves #758
2024-11-26 11:34:05 +00:00
GR
308d8d4cc2 fix: incorrect json property annotation for ZhiPuAI 2024-11-26 11:18:45 +00:00
Ilayaperumal Gopinathan
a782486b06 chores: Fix checkstyle errors 2024-11-26 10:47:10 +00:00
Christian Tzolov
f388f5349a Enhance ChatGenerationMetadata with metadata Map and Builder
- ChatGenerationMetadata provides Map for additional metadata
- Add Builder interface and DefaultChatGenerationMetadataBuilder
- Add DefaultChatGenerationMetadata implementation
- Update all AI model implementations to use the new builder pattern
- Deprecate ChatGenerationMetadata.from() factory method
- Remove commented out legacy code from ChatGenerationMetadata interface
- Make metadata and content filter collections immutable via Collections.unmodifiableSet()
- Add null validation in DefaultChatGenerationMetadata constructor
- Improve toString() method with more informative output
2024-11-26 00:25:18 -05:00
Christian Tzolov
e543cd082d Update AnthropicChatModel and Spring AI Documentation for Multimodal Support
- Enhance AnthropicChatModel to support PDF and document content types
- Introduce getContentBlockTypeByMedia method for flexible media type handling
- Update ContentBlock handling to dynamically determine content type for media
- Add multimodal PDF support test case for Claude 3.5 Sonnet
- Update documentation to reflect PDF and multimodal capabilities
- Modify comparison chart to show PDF support for Anthropic Claude

Fixese #1819

review
2024-11-25 23:54:57 -05:00
Mark Pollack
d1735725ad Enable easier debugging of Azure Image and Audio Transcription tests 2024-11-25 16:33:58 -05:00
Christian Tzolov
d030b82b59 Update mavne build with a profile for fast integration tests
- Add new Maven profile 'ci-fast-integration-tests' for running selective ITs
- Remove redundant vector store skip flags from properties section
- Update maven-failsafe-plugin to version 3.5.2
- Configure test exclusions for various components:
  - Most model integration tests (Anthropic and OpenAI)
  - Most vector store tests (except PgVector and Chroma)
  - Most auto-configuration tests
  - All test containers and docker compose tests
  - AI evaluation tests
- Convert the docker-compose tests into ITs
- Convert the testcontainers tests into ITs
- Updated README.md
  - Explain the new profile and also the new integration tests repo
  - Describe ways to run integration tests for specific modules
  - Add badge for https://github.com/spring-projects/spring-ai-integration-tests
2024-11-25 16:07:32 -05:00
Christian Tzolov
979de19162 docs(vertex-ai-gemini): Add Gemini PDF support docs and add IT
- Add test case for PDF document summarization using Gemini multimodal capabilities
- Update documentation to reflect PDF support in model comparison table
- Add PDF format to multimodal capabilities documentation
2024-11-25 14:09:54 +01:00
Christian Tzolov
c057148813 chore: Update dependencies and fix OpenAPI client generation
- Upgrade Spring Boot to 3.3.6
- Update swagger-codegen-maven-plugin to 3.0.64
- Add custom template for HttpBasicAuth
- Fix mockwebserver version to 4.12.0
- Fix parent version reference in opensearch-store
2024-11-22 14:22:37 +01:00
jitokim
7feb13b63d fix typos in VertexAiGeminiChatModel class
Signed-off-by: jitokim <pigberger70@gmail.com>
2024-11-22 12:08:40 +00:00
Mark Pollack
67a8896422 Next development version 2024-11-20 18:03:30 -05:00
Mark Pollack
33c05c399c Release version 1.0.0-M4 2024-11-20 18:02:47 -05:00
Christian Tzolov
5dbfbf98aa feat: Add Pixtral and new Llama 3.2 Vision models to MistralAi and Ollama integrations
- Add Pixtral models (PIXTRAL and PIXTRAL_LARGE) to MistralAiApi.ChatModel
- Update MistralAiChatClientIT to use Pixtral model for testing
- Add new Ollama models:
  * QWEN_2_5_7B
  * LLAMA3_2_VISION_11b
  * LLAMA3_2_VISION_90b
2024-11-20 17:59:45 +01:00
Mark Pollack
c783c6b2db Add deprecation in Document of embeddings and content formatter 2024-11-20 10:21:46 -05:00
Soby Chacko
1abfd9ab96 Add truncation support for Cohere embeddings
Fixes: #1753

https://github.com/spring-projects/spring-ai/issues/1753

- Add character-based truncation (max 2048 chars) for Cohere embedding requests
- Support both START and END truncation strategies
- Add unit tests verifying truncation behavior for both strategies

Truncation is applied before sending requests to Bedrock API to avoid
ValidationException when text exceeds maximum length. The END strategy
(default) keeps the first 2048 characters while START keeps the last
2048 characters.
2024-11-20 10:06:38 -05:00
Christian Tzolov
551206feb0 fix(bedrock-converse): Update tool use handling and add usage aggregation tests (#1777)
- Replace hardcoded "tool_use" with StopReason enum value
- Add tests for token usage aggregation with tool calls
- Add handling for null response metadata
2024-11-20 12:37:30 +00:00
Christian Tzolov
00ede3f564 Fix Bedrock Converse streaming/call and token handling
- Modify stream method to support recursive tool call handling
     - Update token tracking and metadata merging for streamed responses
     - Improve token usage calculation for tool use events
     - Update test cases to handle new response processing

    - Modify call method to support recursive tool call handling
     - Add support for cumulative token tracking across tool call iterations
     - Introduce internal call method to track and aggregate token usage
     - Merge previous chat response tokens with current response tokens

Resolves #1743
2024-11-20 10:59:40 +00:00
Ilayaperumal Gopinathan
3b95dfd87f Fix checkstyle errors 2024-11-19 23:29:36 +00:00
Ilayaperumal Gopinathan
3812d2e6d8 Remove explicit ChatOptions for the models using FunctionCallingOptions
- Since FunctionCallingOptions already extends ChatOptions,
   removing explicit usage of ChatOptions in the Model Options classes
2024-11-19 18:02:54 -05:00
Christian Tzolov
0eacc9193b feat(tools): Add tool call history to ToolContext
- Add TOOL_CALL_HISTORY constant to store tool call history
- Extend ToolContext with getToolConversationHistory method
- Include tool call history in tool context during function execution
- Add test coverage for tool call history verification

Resolves #1202
2024-11-19 22:50:38 +00:00
Soby Chacko
edc70031dc Remove Boot dependency from core anthropic and watson modules
Fixes: #1591
2024-11-19 17:05:41 -05:00
Gareth Evans
a7b5652790 Upgrade azure-openai library to beta.12
- Correct merge utils after lib update
2024-11-19 15:11:23 -05:00
Mark Pollack
aff18bfca9 Fixes for Azure OpenAI ITs 2024-11-19 14:43:22 -05:00
jitokim
1298a28216 add OllamaChatModelTests
Signed-off-by: jitokim <pigberger70@gmail.com>
2024-11-19 16:13:47 +00:00