mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-13 15:14:50 -06:00
fix: Simplify content for ollama provider
Even though litellm type definitions and openai API specifies content as list of dictionaries (with type and relevant attributes potentially to allow multimodal inputs/outputs in addition to text), ollama has been demonstrating marshal errors. As a workaround this change simplifies the content as string when there is no more than one content part. Fixes #642, #928, #376 PiperOrigin-RevId: 766890141
This commit is contained in:
parent
32c5ffa8ca
commit
eaee49bc89
@ -196,6 +196,14 @@ def _content_to_message_param(
|
|||||||
content_present = True
|
content_present = True
|
||||||
|
|
||||||
final_content = message_content if content_present else None
|
final_content = message_content if content_present else None
|
||||||
|
if final_content and isinstance(final_content, list):
|
||||||
|
# when the content is a single text object, we can use it directly.
|
||||||
|
# this is needed for ollama_chat provider which fails if content is a list
|
||||||
|
final_content = (
|
||||||
|
final_content[0].get("text", "")
|
||||||
|
if final_content[0].get("type", None) == "text"
|
||||||
|
else final_content
|
||||||
|
)
|
||||||
|
|
||||||
return ChatCompletionAssistantMessage(
|
return ChatCompletionAssistantMessage(
|
||||||
role=role,
|
role=role,
|
||||||
|
@ -889,15 +889,16 @@ def test_content_to_message_param_function_call():
|
|||||||
content = types.Content(
|
content = types.Content(
|
||||||
role="assistant",
|
role="assistant",
|
||||||
parts=[
|
parts=[
|
||||||
|
types.Part.from_text(text="test response"),
|
||||||
types.Part.from_function_call(
|
types.Part.from_function_call(
|
||||||
name="test_function", args={"test_arg": "test_value"}
|
name="test_function", args={"test_arg": "test_value"}
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
content.parts[0].function_call.id = "test_tool_call_id"
|
content.parts[1].function_call.id = "test_tool_call_id"
|
||||||
message = _content_to_message_param(content)
|
message = _content_to_message_param(content)
|
||||||
assert message["role"] == "assistant"
|
assert message["role"] == "assistant"
|
||||||
assert message["content"] == None
|
assert message["content"] == "test response"
|
||||||
|
|
||||||
tool_call = message["tool_calls"][0]
|
tool_call = message["tool_calls"][0]
|
||||||
assert tool_call["type"] == "function"
|
assert tool_call["type"] == "function"
|
||||||
|
Loading…
Reference in New Issue
Block a user