Class VertexAiGeminiChatModel
java.lang.Object
org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel
- All Implemented Interfaces:
ChatModel
,StreamingChatModel
,Model<Prompt,
,ChatResponse> StreamingModel<Prompt,
,ChatResponse> org.springframework.beans.factory.DisposableBean
public class VertexAiGeminiChatModel
extends Object
implements ChatModel, org.springframework.beans.factory.DisposableBean
Vertex AI Gemini Chat Model implementation that provides access to Google's Gemini
language models.
Key features include:
- Support for multiple Gemini model versions including Gemini Pro, Gemini 1.5 Pro, Gemini 1.5/2.0 Flash variants
- Tool/Function calling capabilities through
ToolCallingManager
- Streaming support via
stream(Prompt)
method - Configurable safety settings through
VertexAiGeminiSafetySetting
- Support for system messages and multi-modal content (text and images)
- Built-in retry mechanism and observability through Micrometer
- Google Search Retrieval integration
The model can be configured with various options including temperature, top-k, top-p
sampling, maximum output tokens, and candidate count through
VertexAiGeminiChatOptions
.
Use the VertexAiGeminiChatModel.Builder
to create instances with custom configurations:
VertexAiGeminiChatModel model = VertexAiGeminiChatModel.builder()
.vertexAI(vertexAI)
.defaultOptions(options)
.toolCallingManager(toolManager)
.build();
- Since:
- 0.8.1
- Author:
- Christian Tzolov, Grogdunn, luocongqiu, Chris Turchin, Mark Pollack, Soby Chacko, Jihoon Kim, Alexandros Pappas, Ilayaperumal Gopinathan
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
static enum
static enum
static final record
-
Constructor Summary
ConstructorsConstructorDescriptionVertexAiGeminiChatModel
(com.google.cloud.vertexai.VertexAI vertexAI, VertexAiGeminiChatOptions defaultOptions, ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new instance of VertexAiGeminiChatModel.VertexAiGeminiChatModel
(com.google.cloud.vertexai.VertexAI vertexAI, VertexAiGeminiChatOptions defaultOptions, ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry, ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate) Creates a new instance of VertexAiGeminiChatModel. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Executes a method call to the AI model.void
destroy()
reactor.core.publisher.Flux<ChatResponse>
internalStream
(Prompt prompt, ChatResponse previousChatResponse) protected List<Generation>
responseCandidateToGeneration
(com.google.cloud.vertexai.api.Candidate candidate) void
setObservationConvention
(ChatModelObservationConvention observationConvention) Use the provided convention for reporting observation datareactor.core.publisher.Flux<ChatResponse>
Executes a method call to the AI model.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.chat.model.StreamingChatModel
stream, stream
-
Constructor Details
-
VertexAiGeminiChatModel
public VertexAiGeminiChatModel(com.google.cloud.vertexai.VertexAI vertexAI, VertexAiGeminiChatOptions defaultOptions, ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new instance of VertexAiGeminiChatModel.- Parameters:
vertexAI
- the Vertex AI instance to usedefaultOptions
- the default options to usetoolCallingManager
- the tool calling manager to use. It is wrapped in aVertexToolCallingManager
to ensure compatibility with Vertex AI's OpenAPI schema format.retryTemplate
- the retry template to useobservationRegistry
- the observation registry to use
-
VertexAiGeminiChatModel
public VertexAiGeminiChatModel(com.google.cloud.vertexai.VertexAI vertexAI, VertexAiGeminiChatOptions defaultOptions, ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry, ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate) Creates a new instance of VertexAiGeminiChatModel.- Parameters:
vertexAI
- the Vertex AI instance to usedefaultOptions
- the default options to usetoolCallingManager
- the tool calling manager to use. It is wrapped in aVertexToolCallingManager
to ensure compatibility with Vertex AI's OpenAPI schema format.retryTemplate
- the retry template to useobservationRegistry
- the observation registry to usetoolExecutionEligibilityPredicate
- the tool execution eligibility predicate
-
-
Method Details
-
call
Description copied from interface:Model
Executes a method call to the AI model. -
stream
Description copied from interface:StreamingModel
Executes a method call to the AI model.- Specified by:
stream
in interfaceChatModel
- Specified by:
stream
in interfaceStreamingChatModel
- Specified by:
stream
in interfaceStreamingModel<Prompt,
ChatResponse> - Parameters:
prompt
- the request object to be sent to the AI model- Returns:
- the streaming response from the AI model
-
internalStream
public reactor.core.publisher.Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousChatResponse) -
responseCandidateToGeneration
protected List<Generation> responseCandidateToGeneration(com.google.cloud.vertexai.api.Candidate candidate) -
getDefaultOptions
- Specified by:
getDefaultOptions
in interfaceChatModel
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
setObservationConvention
Use the provided convention for reporting observation data- Parameters:
observationConvention
- The provided convention
-
builder
-