Skip to content

Commit 702e04e

Browse files
committed
feat: add image recognition for openai:responses
1 parent 1f09b06 commit 702e04e

File tree

5 files changed

+336
-10
lines changed

5 files changed

+336
-10
lines changed

python/mirascope/llm/clients/openai/responses/_utils/encode.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
response_create_params,
1919
)
2020
from openai.types.responses.easy_input_message_param import EasyInputMessageParam
21+
from openai.types.responses.response_input_image_param import ResponseInputImageParam
2122
from openai.types.responses.response_input_param import (
2223
FunctionCallOutput,
2324
Message as ResponseInputMessageParam,
@@ -78,6 +79,18 @@ def flush_message_content() -> None:
7879
current_content.append(
7980
ResponseInputTextParam(text=part.text, type="input_text")
8081
)
82+
elif part.type == "image":
83+
image_url = (
84+
part.source.url
85+
if part.source.type == "url_image_source"
86+
else f"data:{part.source.mime_type};base64,{part.source.data}"
87+
)
88+
89+
current_content.append(
90+
ResponseInputImageParam(
91+
image_url=image_url, detail="auto", type="input_image"
92+
)
93+
)
8194
elif part.type == "tool_output":
8295
flush_message_content()
8396
result.append(

0 commit comments

Comments
 (0)