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 3a55ee58611..f53028a68a8 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 @@ -725,6 +725,9 @@ private GenerationConfig toGenerationConfig(VertexAiGeminiChatOptions options) { if (options.getTopK() != null) { generationConfigBuilder.setTopK(options.getTopK()); } + if (options.getSeed() != null) { + generationConfigBuilder.setSeed(options.getSeed()); + } if (options.getTopP() != null) { generationConfigBuilder.setTopP(options.getTopP().floatValue()); } 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 bbdf7cdbd9a..adf469a7b29 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 @@ -88,6 +88,14 @@ public class VertexAiGeminiChatOptions implements ToolCallingChatOptions { */ private @JsonProperty("topK") Integer topK; + /** + * Optional. When seed is fixed to a specific value, the model makes a best effort to provide the same response for + * repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such + * as the temperature, can cause variations in the response even when you use the same seed value. + * By default, a random seed value is used. + */ + private @JsonProperty("seed") Integer seed; + /** * Optional. The maximum number of tokens to generate. */ @@ -183,6 +191,7 @@ public static VertexAiGeminiChatOptions fromOptions(VertexAiGeminiChatOptions fr options.setToolContext(fromOptions.getToolContext()); options.setLogprobs(fromOptions.getLogprobs()); options.setResponseLogprobs(fromOptions.getResponseLogprobs()); + options.setSeed(fromOptions.getSeed()); return options; } @@ -226,6 +235,14 @@ public void setTopK(Integer topK) { this.topK = topK; } + public Integer getSeed() { + return this.seed; + } + + public void setSeed(Integer seed) { + this.seed = seed; + } + public Integer getCandidateCount() { return this.candidateCount; } @@ -393,7 +410,7 @@ public boolean equals(Object o) { && Objects.equals(this.safetySettings, that.safetySettings) && Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled) && Objects.equals(this.toolContext, that.toolContext) && Objects.equals(this.logprobs, that.logprobs) - && Objects.equals(this.responseLogprobs, that.responseLogprobs); + && Objects.equals(this.responseLogprobs, that.responseLogprobs) && Objects.equals(this.seed, that.seed); } @Override @@ -402,7 +419,7 @@ public int hashCode() { this.frequencyPenalty, this.presencePenalty, this.maxOutputTokens, this.model, this.responseMimeType, this.responseSchema, this.toolCallbacks, this.toolNames, this.googleSearchRetrieval, this.safetySettings, this.internalToolExecutionEnabled, this.toolContext, this.logprobs, - this.responseLogprobs); + this.responseLogprobs, this.seed); } @Override @@ -414,7 +431,7 @@ public String toString() { + ", responseMimeType='" + this.responseMimeType + '\'' + ", responseSchema='" + this.responseSchema + ", toolCallbacks=" + this.toolCallbacks + ", toolNames=" + this.toolNames + ", googleSearchRetrieval=" + this.googleSearchRetrieval + ", safetySettings=" + this.safetySettings + ", logProbs=" + this.logprobs - + ", responseLogprobs=" + this.responseLogprobs + '}'; + + ", responseLogprobs=" + this.responseLogprobs + ", seed=" + this.seed + '}'; } @Override @@ -452,6 +469,11 @@ public Builder topK(Integer topK) { return this; } + public Builder seed(Integer seed) { + this.options.setSeed(seed); + return this; + } + public Builder frequencyPenalty(Double frequencyPenalty) { this.options.setFrequencyPenalty(frequencyPenalty); return this;