fix: Refine Ollama content flattening and provider checks

- Stripping whitespace from custom LLM provider and model names when checking for "ollama_chat".
- Enhancing `_flatten_ollama_content` to correctly handle content that is None, a string, a dictionary, or an iterable (like a tuple) of content blocks, not just lists. This aligns with LiteLLM's `OpenAIMessageContent` type being an `Iterable`.

Close #3928

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 845848017
This commit is contained in:
George Weale
2025-12-17 11:25:44 -08:00
committed by Copybara-Service
parent 1add41e160
commit c6f389d4bc
2 changed files with 33 additions and 6 deletions
+11
View File
@@ -1549,6 +1549,17 @@ async def test_generate_content_async_custom_provider_flattens_content(
assert "Describe this image." in message_content
def test_flatten_ollama_content_accepts_tuple_blocks():
from google.adk.models.lite_llm import _flatten_ollama_content
content = (
{"type": "text", "text": "first"},
{"type": "text", "text": "second"},
)
flattened = _flatten_ollama_content(content)
assert flattened == "first\nsecond"
@pytest.mark.asyncio
async def test_content_to_message_param_user_message():
content = types.Content(