Skip to content

Commit f17c9a2

Browse files
fix: non passing tests
1 parent da5023f commit f17c9a2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

posthog/ai/gemini/gemini_converter.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ def _format_parts_as_content_blocks(parts: List[Any]) -> List[FormattedContentIt
5353
elif isinstance(part, str):
5454
content_blocks.append({"type": "text", "text": part})
5555

56-
# Handle dict with inline_data (images)
56+
# Handle dict with inline_data (images, documents, etc.)
5757
elif isinstance(part, dict) and "inline_data" in part:
5858
inline_data = part["inline_data"]
59+
mime_type = inline_data.get("mime_type", "")
60+
content_type = "image" if mime_type.startswith("image/") else "document"
61+
5962
content_blocks.append(
6063
{
61-
"type": "image",
64+
"type": content_type,
6265
"inline_data": inline_data,
6366
}
6467
)
@@ -74,11 +77,15 @@ def _format_parts_as_content_blocks(parts: List[Any]) -> List[FormattedContentIt
7477
inline_data = part.inline_data
7578
# Convert to dict if needed
7679
if hasattr(inline_data, "mime_type") and hasattr(inline_data, "data"):
80+
# Determine type based on mime_type
81+
mime_type = inline_data.mime_type
82+
content_type = "image" if mime_type.startswith("image/") else "document"
83+
7784
content_blocks.append(
7885
{
79-
"type": "image",
86+
"type": content_type,
8087
"inline_data": {
81-
"mime_type": inline_data.mime_type,
88+
"mime_type": mime_type,
8289
"data": inline_data.data,
8390
},
8491
}

posthog/test/ai/gemini/test_gemini_async.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ async def test_async_client_different_input_formats(
392392
)
393393
call_args = mock_client.capture.call_args[1]
394394
props = call_args["properties"]
395-
assert props["$ai_input"] == [{"role": "user", "content": "hey"}]
395+
assert props["$ai_input"] == [
396+
{"role": "user", "content": [{"type": "text", "text": "hey"}]}
397+
]
396398

397399
# Test multiple parts in the parts array
398400
mock_client.reset_mock()
@@ -403,7 +405,15 @@ async def test_async_client_different_input_formats(
403405
)
404406
call_args = mock_client.capture.call_args[1]
405407
props = call_args["properties"]
406-
assert props["$ai_input"] == [{"role": "user", "content": "Hello world"}]
408+
assert props["$ai_input"] == [
409+
{
410+
"role": "user",
411+
"content": [
412+
{"type": "text", "text": "Hello "},
413+
{"type": "text", "text": "world"},
414+
],
415+
}
416+
]
407417

408418
# Test list input with string
409419
mock_client.capture.reset_mock()

0 commit comments

Comments
 (0)