Skip to content

Commit 574b5b4

Browse files
committed
GenerationConfigBuilder
1 parent 389a8de commit 574b5b4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

gemini-api/src/main/java/swiss/ameri/gemini/api/GenerationConfig.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package swiss.ameri.gemini.api;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
/**
@@ -42,5 +43,68 @@ public record GenerationConfig(
4243
Integer topK
4344
) {
4445

46+
/**
47+
* Builder for {@link GenerationConfig}.
48+
*/
49+
public static GenerationConfigBuilder builder() {
50+
return new GenerationConfigBuilder();
51+
}
52+
53+
public static class GenerationConfigBuilder {
54+
private final List<String> stopSequences = new ArrayList<>();
55+
private String responseMimeType;
56+
private String responseSchema;
57+
private Integer maxOutputTokens;
58+
private Double temperature;
59+
private Double topP;
60+
private Integer topK;
61+
62+
public GenerationConfigBuilder addStopSequence(String stopSequence) {
63+
this.stopSequences.add(stopSequence);
64+
return this;
65+
}
66+
67+
public GenerationConfigBuilder responseMimeType(String responseMimeType) {
68+
this.responseMimeType = responseMimeType;
69+
return this;
70+
}
71+
72+
public GenerationConfigBuilder responseSchema(String responseSchema) {
73+
this.responseSchema = responseSchema;
74+
return this;
75+
}
76+
77+
public GenerationConfigBuilder maxOutputTokens(Integer maxOutputTokens) {
78+
this.maxOutputTokens = maxOutputTokens;
79+
return this;
80+
}
81+
82+
public GenerationConfigBuilder temperature(Double temperature) {
83+
this.temperature = temperature;
84+
return this;
85+
}
86+
87+
public GenerationConfigBuilder topP(Double topP) {
88+
this.topP = topP;
89+
return this;
90+
}
91+
92+
public GenerationConfigBuilder topK(Integer topK) {
93+
this.topK = topK;
94+
return this;
95+
}
96+
97+
public GenerationConfig build() {
98+
return new GenerationConfig(
99+
stopSequences.isEmpty() ? null : stopSequences,
100+
responseMimeType,
101+
responseSchema,
102+
maxOutputTokens,
103+
temperature,
104+
topP,
105+
topK
106+
);
107+
}
108+
}
45109

46110
}

0 commit comments

Comments
 (0)