Skip to content

Commit a0fad81

Browse files
committed
feat: add image recognition for Google
Downloaded images only, Google doesn't have an API for images by external URL (Files URI is a separate matter imo)
1 parent 0cf4bd8 commit a0fad81

File tree

4 files changed

+143
-9
lines changed

4 files changed

+143
-9
lines changed

python/mirascope/llm/clients/google/_utils/encode.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Google message encoding and request preparation."""
22

3+
import base64
34
import json
45
from collections.abc import Sequence
56
from functools import lru_cache
@@ -56,6 +57,22 @@ def _encode_content(
5657
for part in content:
5758
if part.type == "text":
5859
result.append(genai_types.PartDict(text=part.text))
60+
elif part.type == "image":
61+
if part.source.type == "base64_image_source":
62+
result.append(
63+
genai_types.PartDict(
64+
inline_data=genai_types.BlobDict(
65+
data=base64.b64decode(part.source.data),
66+
mime_type=part.source.mime_type,
67+
)
68+
)
69+
)
70+
elif part.source.type == "url_image_source":
71+
raise FeatureNotSupportedError(
72+
"url_image_source",
73+
"google",
74+
message="Google does not support URL-referenced images. Try `llm.Image.download(...) or `llm.Image.download_async(...)`",
75+
)
5976
elif part.type == "tool_call":
6077
result.append(
6178
genai_types.PartDict(

0 commit comments

Comments
 (0)