Skip to content
Open
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
@@ -1,5 +1,6 @@
from __future__ import annotations

import ast
import re
from copy import deepcopy
from typing import Any
Expand Down Expand Up @@ -83,16 +84,22 @@ def get_tool_results_for_realtime(
) -> types.LiveClientToolResponse | None:
function_responses: list[types.FunctionResponse] = []
for msg in chat_ctx.items:
if msg.type == "function_call_output":
# If there is no output, skip the message.
if msg.type == "function_call_output" and msg.output:
res = types.FunctionResponse(
name=msg.name,
response={"output": msg.output},
# LiveKit sets output to the string representation of the tool's
# return value, but the Live API expects the actual value.
# https://ai.google.dev/gemini-api/docs/live-tools#function-calling
response=ast.literal_eval(msg.output),
scheduling=types.FunctionResponseScheduling.SILENT,
)
if not vertexai:
# vertexai does not support id in FunctionResponse
# see: https://github.com/googleapis/python-genai/blob/85e00bc/google/genai/_live_converters.py#L1435
res.id = msg.call_id
function_responses.append(res)
logger.debug("get_tool_results_for_realtime: function_responses=%s", function_responses)
return (
types.LiveClientToolResponse(function_responses=function_responses)
if function_responses
Expand Down