Skip to content

Commit c71e78e

Browse files
yinghsienwucopybara-github
authored andcommitted
fix!: Move generation config to the top level LiveConnectConfig
PiperOrigin-RevId: 746106589
1 parent f5bd874 commit c71e78e

File tree

3 files changed

+89
-10
lines changed

3 files changed

+89
-10
lines changed

examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public static void main(String[] args) {
6161
Client.builder().httpOptions(HttpOptions.builder().apiVersion("v1alpha").build()).build();
6262

6363
LiveConnectConfig config =
64-
LiveConnectConfig.builder().responseModalities(ImmutableList.of("TEXT")).build();
64+
LiveConnectConfig.builder()
65+
.responseModalities(ImmutableList.of("TEXT"))
66+
.maxOutputTokens(30)
67+
.seed(1234)
68+
.build();
6569

6670
CompletableFuture<Void> allDone = new CompletableFuture<>();
6771

src/main/java/com/google/genai/AsyncLive.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,33 @@ private String getSetupRequest(String model, LiveConnectConfig config) {
149149
// responseModalities and speechConfig are missing in the LiveClientSetup.
150150
// we need to manually add them to the request message.
151151
ObjectNode generationConfigNode = JsonSerializable.objectMapper.createObjectNode();
152-
if (config.generationConfig().isPresent()) {
152+
if (config.temperature().isPresent()) {
153153
generationConfigNode =
154-
JsonSerializable.toJsonNode(config.generationConfig().get()).deepCopy();
154+
JsonSerializable.toJsonNode(config.temperature().get()).deepCopy();
155+
}
156+
157+
if (config.topP().isPresent()) {
158+
generationConfigNode =
159+
JsonSerializable.toJsonNode(config.topP().get()).deepCopy();
160+
}
161+
162+
if (config.topK().isPresent()) {
163+
generationConfigNode =
164+
JsonSerializable.toJsonNode(config.topK().get()).deepCopy();
165+
}
166+
167+
if (config.maxOutputTokens().isPresent()) {
168+
generationConfigNode =
169+
JsonSerializable.toJsonNode(config.maxOutputTokens().get()).deepCopy();
170+
}
171+
172+
if (config.mediaResolution().isPresent()) {
173+
generationConfigNode =
174+
JsonSerializable.toJsonNode(config.mediaResolution().get()).deepCopy();
175+
}
176+
177+
if (config.seed().isPresent()) {
178+
generationConfigNode = JsonSerializable.toJsonNode(config.seed().get()).deepCopy();
155179
}
156180

157181
if (config.responseModalities().isPresent()) {

src/main/java/com/google/genai/types/LiveConnectConfig.java

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,53 @@
3030
@AutoValue
3131
@JsonDeserialize(builder = LiveConnectConfig.Builder.class)
3232
public abstract class LiveConnectConfig extends JsonSerializable {
33-
/** The generation configuration for the session. */
34-
@JsonProperty("generationConfig")
35-
public abstract Optional<GenerationConfig> generationConfig();
36-
3733
/**
3834
* The requested modalities of the response. Represents the set of modalities that the model can
3935
* return. Defaults to AUDIO if not specified.
4036
*/
4137
@JsonProperty("responseModalities")
4238
public abstract Optional<List<String>> responseModalities();
4339

40+
/**
41+
* Value that controls the degree of randomness in token selection. Lower temperatures are good
42+
* for prompts that require a less open-ended or creative response, while higher temperatures can
43+
* lead to more diverse or creative results.
44+
*/
45+
@JsonProperty("temperature")
46+
public abstract Optional<Float> temperature();
47+
48+
/**
49+
* Tokens are selected from the most to least probable until the sum of their probabilities equals
50+
* this value. Use a lower value for less random responses and a higher value for more random
51+
* responses.
52+
*/
53+
@JsonProperty("topP")
54+
public abstract Optional<Float> topP();
55+
56+
/**
57+
* For each token selection step, the ``top_k`` tokens with the highest probabilities are sampled.
58+
* Then tokens are further filtered based on ``top_p`` with the final token selected using
59+
* temperature sampling. Use a lower number for less random responses and a higher number for more
60+
* random responses.
61+
*/
62+
@JsonProperty("topK")
63+
public abstract Optional<Float> topK();
64+
65+
/** Maximum number of tokens that can be generated in the response. */
66+
@JsonProperty("maxOutputTokens")
67+
public abstract Optional<Integer> maxOutputTokens();
68+
69+
/** If specified, the media resolution specified will be used. */
70+
@JsonProperty("mediaResolution")
71+
public abstract Optional<String> mediaResolution();
72+
73+
/**
74+
* When ``seed`` is fixed to a specific number, the model makes a best effort to provide the same
75+
* response for repeated requests. By default, a random number is used.
76+
*/
77+
@JsonProperty("seed")
78+
public abstract Optional<Integer> seed();
79+
4480
/** The speech generation configuration. */
4581
@JsonProperty("speechConfig")
4682
public abstract Optional<SpeechConfig> speechConfig();
@@ -78,12 +114,27 @@ private static Builder create() {
78114
return new AutoValue_LiveConnectConfig.Builder();
79115
}
80116

81-
@JsonProperty("generationConfig")
82-
public abstract Builder generationConfig(GenerationConfig generationConfig);
83-
84117
@JsonProperty("responseModalities")
85118
public abstract Builder responseModalities(List<String> responseModalities);
86119

120+
@JsonProperty("temperature")
121+
public abstract Builder temperature(Float temperature);
122+
123+
@JsonProperty("topP")
124+
public abstract Builder topP(Float topP);
125+
126+
@JsonProperty("topK")
127+
public abstract Builder topK(Float topK);
128+
129+
@JsonProperty("maxOutputTokens")
130+
public abstract Builder maxOutputTokens(Integer maxOutputTokens);
131+
132+
@JsonProperty("mediaResolution")
133+
public abstract Builder mediaResolution(String mediaResolution);
134+
135+
@JsonProperty("seed")
136+
public abstract Builder seed(Integer seed);
137+
87138
@JsonProperty("speechConfig")
88139
public abstract Builder speechConfig(SpeechConfig speechConfig);
89140

0 commit comments

Comments
 (0)