Skip to content

Commit d1c2828

Browse files
fix: tests and lint
1 parent 0455e23 commit d1c2828

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

posthog/ai/gemini/gemini_converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def _format_object_message(item: Any) -> FormattedMessage:
175175
content = item.content
176176

177177
if isinstance(content, list):
178-
content = _extract_text_from_parts(content)
178+
content_blocks = _format_parts_as_content_blocks(content)
179+
return {"role": role, "content": content_blocks}
179180

180181
elif not isinstance(content, str):
181182
content = str(content)

posthog/ai/sanitization.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
def _is_multimodal_enabled() -> bool:
1010
"""Check if multimodal capture is enabled via environment variable."""
11-
return os.environ.get("_INTERNAL_LLMA_MULTIMODAL", "").lower() in ("true", "1", "yes")
11+
return os.environ.get("_INTERNAL_LLMA_MULTIMODAL", "").lower() in (
12+
"true",
13+
"1",
14+
"yes",
15+
)
1216

1317

1418
def is_base64_data_url(text: str) -> bool:

posthog/test/ai/gemini/test_gemini.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ def test_new_client_different_input_formats(
407407
)
408408
call_args = mock_client.capture.call_args[1]
409409
props = call_args["properties"]
410-
assert props["$ai_input"] == [{"role": "user", "content": "hey"}]
410+
assert props["$ai_input"] == [
411+
{"role": "user", "content": [{"type": "text", "text": "hey"}]}
412+
]
411413

412414
# Test multiple parts in the parts array
413415
mock_client.reset_mock()
@@ -418,7 +420,15 @@ def test_new_client_different_input_formats(
418420
)
419421
call_args = mock_client.capture.call_args[1]
420422
props = call_args["properties"]
421-
assert props["$ai_input"] == [{"role": "user", "content": "Hello world"}]
423+
assert props["$ai_input"] == [
424+
{
425+
"role": "user",
426+
"content": [
427+
{"type": "text", "text": "Hello "},
428+
{"type": "text", "text": "world"},
429+
],
430+
}
431+
]
422432

423433
# Test list input with string
424434
mock_client.capture.reset_mock()

posthog/test/ai/test_sanitization.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ def test_gemini_multimodal_enabled(self):
409409
os.environ["_INTERNAL_LLMA_MULTIMODAL"] = "true"
410410

411411
input_data = [
412-
{"parts": [{"inline_data": {"mime_type": "image/jpeg", "data": "base64data"}}]}
412+
{
413+
"parts": [
414+
{"inline_data": {"mime_type": "image/jpeg", "data": "base64data"}}
415+
]
416+
}
413417
]
414418

415419
result = sanitize_gemini(input_data)
@@ -509,7 +513,9 @@ def test_gemini_audio_preserved_with_flag(self):
509513
]
510514

511515
result = sanitize_gemini(input_data)
512-
self.assertEqual(result[0]["parts"][0]["inline_data"]["data"], "base64audiodata")
516+
self.assertEqual(
517+
result[0]["parts"][0]["inline_data"]["data"], "base64audiodata"
518+
)
513519

514520

515521
if __name__ == "__main__":

0 commit comments

Comments
 (0)