fix: handle malformed function calls in vertex (#1987)

This commit is contained in:
Andy Li
2025-05-02 11:45:41 -07:00
committed by GitHub
parent 2a3ff11c1d
commit d1865eaa22
2 changed files with 7 additions and 3 deletions

View File

@@ -122,8 +122,8 @@ class GoogleAIClient(LLMClientBase):
for candidate in response_data["candidates"]:
content = candidate["content"]
if "role" not in content:
# This means the response is malformed
if "role" not in content or not content["role"]:
# This means the response is malformed like MALFORMED_FUNCTION_CALL
# NOTE: must be a ValueError to trigger a retry
raise ValueError(f"Error in response data from LLM: {response_data}")
role = content["role"]

View File

@@ -110,7 +110,11 @@ class GoogleVertexClient(GoogleAIClient):
for candidate in response.candidates:
content = candidate.content
role = content.role
if "role" not in content or not content["role"]:
# This means the response is malformed like MALFORMED_FUNCTION_CALL
# NOTE: must be a ValueError to trigger a retry
raise ValueError(f"Error in response data from LLM: {response_data}")
role = content["role"]
assert role == "model", f"Unknown role in response: {role}"
parts = content.parts