Skip to content

Commit 378fcb3

Browse files
committed
GH-4826: Expose seed in vertex ai configuration.
1 parent e928ca9 commit 378fcb3

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ private GenerationConfig toGenerationConfig(VertexAiGeminiChatOptions options) {
725725
if (options.getTopK() != null) {
726726
generationConfigBuilder.setTopK(options.getTopK());
727727
}
728+
if (options.getSeed() != null) {
729+
generationConfigBuilder.setSeed(options.getSeed());
730+
}
728731
if (options.getTopP() != null) {
729732
generationConfigBuilder.setTopP(options.getTopP().floatValue());
730733
}

models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatOptions.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public class VertexAiGeminiChatOptions implements ToolCallingChatOptions {
8888
*/
8989
private @JsonProperty("topK") Integer topK;
9090

91+
/**
92+
* Optional. When seed is fixed to a specific value, the model makes a best effort to provide the same response for
93+
* repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such
94+
* as the temperature, can cause variations in the response even when you use the same seed value.
95+
* By default, a random seed value is used.
96+
*/
97+
private @JsonProperty("seed") Integer seed;
98+
9199
/**
92100
* Optional. The maximum number of tokens to generate.
93101
*/
@@ -183,6 +191,7 @@ public static VertexAiGeminiChatOptions fromOptions(VertexAiGeminiChatOptions fr
183191
options.setToolContext(fromOptions.getToolContext());
184192
options.setLogprobs(fromOptions.getLogprobs());
185193
options.setResponseLogprobs(fromOptions.getResponseLogprobs());
194+
options.setSeed(fromOptions.getSeed());
186195
return options;
187196
}
188197

@@ -226,6 +235,14 @@ public void setTopK(Integer topK) {
226235
this.topK = topK;
227236
}
228237

238+
public Integer getSeed() {
239+
return this.seed;
240+
}
241+
242+
public void setSeed(Integer seed) {
243+
this.seed = seed;
244+
}
245+
229246
public Integer getCandidateCount() {
230247
return this.candidateCount;
231248
}
@@ -393,7 +410,7 @@ public boolean equals(Object o) {
393410
&& Objects.equals(this.safetySettings, that.safetySettings)
394411
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled)
395412
&& Objects.equals(this.toolContext, that.toolContext) && Objects.equals(this.logprobs, that.logprobs)
396-
&& Objects.equals(this.responseLogprobs, that.responseLogprobs);
413+
&& Objects.equals(this.responseLogprobs, that.responseLogprobs) && Objects.equals(this.seed, that.seed);
397414
}
398415

399416
@Override
@@ -402,7 +419,7 @@ public int hashCode() {
402419
this.frequencyPenalty, this.presencePenalty, this.maxOutputTokens, this.model, this.responseMimeType,
403420
this.responseSchema, this.toolCallbacks, this.toolNames, this.googleSearchRetrieval,
404421
this.safetySettings, this.internalToolExecutionEnabled, this.toolContext, this.logprobs,
405-
this.responseLogprobs);
422+
this.responseLogprobs, this.seed);
406423
}
407424

408425
@Override
@@ -414,7 +431,7 @@ public String toString() {
414431
+ ", responseMimeType='" + this.responseMimeType + '\'' + ", responseSchema='" + this.responseSchema
415432
+ ", toolCallbacks=" + this.toolCallbacks + ", toolNames=" + this.toolNames + ", googleSearchRetrieval="
416433
+ this.googleSearchRetrieval + ", safetySettings=" + this.safetySettings + ", logProbs=" + this.logprobs
417-
+ ", responseLogprobs=" + this.responseLogprobs + '}';
434+
+ ", responseLogprobs=" + this.responseLogprobs + ", seed=" + this.seed + '}';
418435
}
419436

420437
@Override
@@ -452,6 +469,11 @@ public Builder topK(Integer topK) {
452469
return this;
453470
}
454471

472+
public Builder seed(Integer seed) {
473+
this.options.setSeed(seed);
474+
return this;
475+
}
476+
455477
public Builder frequencyPenalty(Double frequencyPenalty) {
456478
this.options.setFrequencyPenalty(frequencyPenalty);
457479
return this;

0 commit comments

Comments
 (0)