Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.genai.types.Blob;
import com.google.genai.types.Content;
import com.google.genai.types.FinishReason;
import com.google.genai.types.FunctionCall;
import com.google.genai.types.FunctionResponse;
import com.google.genai.types.LiveConnectConfig;
import com.google.genai.types.LiveSendClientContentParameters;
Expand Down Expand Up @@ -202,14 +201,15 @@ private static LlmResponse createToolCallResponse(LiveServerToolCall toolCall) {
toolCall
.functionCalls()
.ifPresent(
calls -> {
for (FunctionCall call : calls) {
calls ->
builder.content(
Content.builder()
.parts(ImmutableList.of(Part.builder().functionCall(call).build()))
.build());
}
});
.role("model")
.parts(
calls.stream()
.map(call -> Part.builder().functionCall(call).build())
.collect(toImmutableList()))
.build()));
return builder.partial(false).turnComplete(false).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.genai.types.Content;
import com.google.genai.types.FunctionCall;
import com.google.genai.types.GenerateContentResponseUsageMetadata;
Expand Down Expand Up @@ -164,13 +165,47 @@ public void convertToServerResponse_withToolCall_mapsContentWithFunctionCall() {
testObserver.assertComplete();
LlmResponse response = testObserver.values().get(0);
assertThat(response.content()).isPresent();
assertThat(response.content().get().role()).hasValue("model");
assertThat(response.content().get().parts()).isPresent();
assertThat(response.content().get().parts().get()).hasSize(1);
assertThat(response.content().get().parts().get().get(0).functionCall()).hasValue(functionCall);
assertThat(response.partial()).hasValue(false);
assertThat(response.turnComplete()).hasValue(false);
}

@Test
public void convertToServerResponse_withMultipleFunctionCalls_preservesAllCallsAsParts() {
// Regression test for parallel tool calling on the live/BIDI path: a single toolCall message
// can carry multiple FunctionCalls, and all of them must be preserved (not just the last).
FunctionCall getWeather =
FunctionCall.builder().name("getWeather").args(ImmutableMap.of("city", "Paris")).build();
FunctionCall getTime =
FunctionCall.builder()
.name("getTime")
.args(ImmutableMap.of("timezone", "Europe/London"))
.build();
LiveServerToolCall toolCall =
LiveServerToolCall.builder().functionCalls(ImmutableList.of(getWeather, getTime)).build();

LiveServerMessage message = LiveServerMessage.builder().toolCall(toolCall).build();

TestObserver<LlmResponse> testObserver = new TestObserver<>();

GeminiLlmConnection.convertToServerResponse(message).subscribe(testObserver);

testObserver.assertValueCount(1);
testObserver.assertComplete();
LlmResponse response = testObserver.values().get(0);
assertThat(response.content()).isPresent();
assertThat(response.content().get().role()).hasValue("model");
assertThat(response.content().get().parts()).isPresent();
assertThat(response.content().get().parts().get()).hasSize(2);
assertThat(response.content().get().parts().get().get(0).functionCall()).hasValue(getWeather);
assertThat(response.content().get().parts().get().get(1).functionCall()).hasValue(getTime);
assertThat(response.partial()).hasValue(false);
assertThat(response.turnComplete()).hasValue(false);
}

@Test
public void convertToServerResponse_withUsageMetadata_mapsGenerateResponseUsageMetadata() {
LiveServerMessage message =
Expand Down
Loading