diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java index 402e5f2d5..2378d7bc9 100644 --- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java +++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java @@ -93,7 +93,37 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** - * Vertex AI Gemini Chat Model implementation. + * Vertex AI Gemini Chat Model implementation that provides access to Google's Gemini + * language models. + * + *
+ * Key features include: + *
+ * The model can be configured with various options including temperature, top-k, top-p + * sampling, maximum output tokens, and candidate count through + * {@link VertexAiGeminiChatOptions}. + * + *
+ * Use the {@link Builder} to create instances with custom configurations: + * + *
{@code
+ * VertexAiGeminiChatModel model = VertexAiGeminiChatModel.builder()
+ * .vertexAI(vertexAI)
+ * .defaultOptions(options)
+ * .toolCallingManager(toolManager)
+ * .build();
+ * }
*
* @author Christian Tzolov
* @author Grogdunn
@@ -104,6 +134,9 @@ import org.springframework.util.StringUtils;
* @author Jihoon Kim
* @author Alexandros Pappas
* @since 0.8.1
+ * @see VertexAiGeminiChatOptions
+ * @see ToolCallingManager
+ * @see ChatModel
*/
public class VertexAiGeminiChatModel extends AbstractToolCallSupport implements ChatModel, DisposableBean {
@@ -203,6 +236,16 @@ public class VertexAiGeminiChatModel extends AbstractToolCallSupport implements
}
+ /**
+ * Creates a new instance of VertexAiGeminiChatModel.
+ * @param vertexAI the Vertex AI instance to use
+ * @param defaultOptions the default options to use
+ * @param toolCallingManager the tool calling manager to use. It is wrapped in a
+ * {@link VertexToolCallingManager} to ensure compatibility with Vertex AI's OpenAPI
+ * schema format.
+ * @param retryTemplate the retry template to use
+ * @param observationRegistry the observation registry to use
+ */
public VertexAiGeminiChatModel(VertexAI vertexAI, VertexAiGeminiChatOptions defaultOptions,
ToolCallingManager toolCallingManager, RetryTemplate retryTemplate,
ObservationRegistry observationRegistry) {
@@ -221,6 +264,8 @@ public class VertexAiGeminiChatModel extends AbstractToolCallSupport implements
this.retryTemplate = retryTemplate;
this.observationRegistry = observationRegistry;
+ // Wrap the provided tool calling manager in a VertexToolCallingManager to ensure
+ // compatibility with Vertex AI's OpenAPI schema format.
if (toolCallingManager instanceof VertexToolCallingManager) {
this.toolCallingManager = toolCallingManager;
}
diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java
index 9a39d9195..db75de5c7 100644
--- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java
+++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java
@@ -126,13 +126,12 @@ public class VertexAiGeminiChatOptions implements ToolCallingChatOptions {
@JsonIgnore
private List
+ * It delegates the actual tool execution to another {@link ToolCallingManager} while
+ * handling the necessary schema conversions for Vertex AI compatibility.
+ *
* @author Christian Tzolov
* @since 1.0.0
*/
-
public class VertexToolCallingManager implements ToolCallingManager {
+ /**
+ * The underlying tool calling manager that handles actual tool execution.
+ */
private final ToolCallingManager delegateToolCallingManager;
+ /**
+ * Creates a new instance of VertexToolCallingManager.
+ * @param delegateToolCallingManager the underlying tool calling manager that handles
+ * actual tool execution
+ */
public VertexToolCallingManager(ToolCallingManager delegateToolCallingManager) {
+ Assert.notNull(delegateToolCallingManager, "Delegate tool calling manager must not be null");
this.delegateToolCallingManager = delegateToolCallingManager;
}
+ /**
+ * Resolves tool definitions and converts their input schemas to be compatible with
+ * Vertex AI's OpenAPI format. This includes converting JSON schemas to OpenAPI format
+ * and ensuring proper type value casing.
+ * @param chatOptions the options containing tool preferences and configurations
+ * @return a list of tool definitions with Vertex AI compatible schemas
+ */
@Override
public List