|
1 | 1 | package swiss.ameri.gemini.api; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
3 | 4 | import java.util.List; |
4 | 5 |
|
5 | 6 | /** |
@@ -42,5 +43,68 @@ public record GenerationConfig( |
42 | 43 | Integer topK |
43 | 44 | ) { |
44 | 45 |
|
| 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 | + } |
45 | 109 |
|
46 | 110 | } |
0 commit comments