-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Responses API native content types in adapter #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
21a2be0
ed18b0c
84426c0
4edac8f
c082691
3485440
38b76d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,7 +327,7 @@ def __translate_role(role: str) -> str: | |
| raise ValueError(f"Gemini formatting found unexpected role {role}") | ||
|
|
||
|
|
||
| class OpenAIResponsesAdapter(OpenAIAdapter): | ||
| class OpenAIResponsesAdapter(LLMAdapter): | ||
| role_support = RoleSupport( | ||
| supported=frozenset({"system", "user", "assistant", "developer", "tool"}), | ||
| coerce_map={}, | ||
|
|
@@ -336,9 +336,51 @@ class OpenAIResponsesAdapter(OpenAIAdapter): | |
| def to_llm_syntax( | ||
| self, messages: List[Dict[str, Any]] | ||
| ) -> Union[str, List[Dict[str, Any]]]: | ||
| formatted = super().to_llm_syntax(messages) | ||
| assert isinstance(formatted, list) | ||
| return [{"type": "message", **m} for m in formatted if m["role"] != "system"] | ||
| result: List[Dict[str, Any]] = [] | ||
| for message in messages: | ||
| if message["role"] == "system": | ||
| continue | ||
| if "has_media" in message and message["has_media"]: | ||
| result.append( | ||
| { | ||
| "type": "message", | ||
| "role": message["role"], | ||
| "content": [ | ||
| OpenAIResponsesAdapter._map_responses_content(content) | ||
| for content in message["content"] | ||
| ], | ||
| } | ||
| ) | ||
| else: | ||
| msg = copy.deepcopy(message) | ||
| result.append({"type": "message", **msg}) | ||
|
Comment on lines
+355
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: wc -l src/freeplay/resources/adapters.pyRepository: freeplayai/freeplay-python Length of output: 108 🏁 Script executed: cat -n src/freeplay/resources/adapters.py | sed -n '340,370p'Repository: freeplayai/freeplay-python Length of output: 1475 🏁 Script executed: cat -n src/freeplay/resources/adapters.py | sed -n '1,100p'Repository: freeplayai/freeplay-python Length of output: 3623 🏁 Script executed: cat -n src/freeplay/resources/adapters.py | sed -n '320,360p'Repository: freeplayai/freeplay-python Length of output: 1725 🏁 Script executed: cat -n src/freeplay/resources/adapters.py | sed -n '200,320p'Repository: freeplayai/freeplay-python Length of output: 5279 🏁 Script executed: rg "tool" src/freeplay/resources/adapters.py -i -B 3 -A 3Repository: freeplayai/freeplay-python Length of output: 410 🏁 Script executed: rg "type.*message" src/freeplay/resources/ -i -B 2 -A 2Repository: freeplayai/freeplay-python Length of output: 748 🏁 Script executed: git ls-files | grep -E "(test|spec)" | head -20Repository: freeplayai/freeplay-python Length of output: 770 🏁 Script executed: find tests -name "*.py" -type f | xargs rg "OpenAIResponsesAdapter|tool" -B 3 -A 3Repository: freeplayai/freeplay-python Length of output: 35639 🏁 Script executed: rg "class OpenAI" src/freeplay/resources/adapters.py -A 50 | head -80Repository: freeplayai/freeplay-python Length of output: 3023 🏁 Script executed: cat -n tests/test_adapters.py | grep -A 30 "openai_responses"Repository: freeplayai/freeplay-python Length of output: 5007 🏁 Script executed: cat -n tests/test_adapters.py | grep -B 5 -A 20 "test_openai_responses"Repository: freeplayai/freeplay-python Length of output: 4048 🏁 Script executed: web_search
OpenAI Conversations API Responses create-item schema allowed roles message typeRepository: freeplayai/freeplay-python Length of output: 165 🌐 Web query:
💡 Result: For the Responses API / Conversations-compat message items, the schema is:
Sources: [1] [2] [3] [4] Remove The Either remove 🤖 Prompt for AI Agents |
||
| return result | ||
|
|
||
| @staticmethod | ||
| def _map_responses_content( | ||
| content: Union[TextContent, MediaContentBase64, MediaContentUrl], | ||
| ) -> Dict[str, Any]: | ||
| if isinstance(content, TextContent): | ||
| return {"type": "input_text", "text": content.text} | ||
| if content.type == "audio": | ||
| raise ValueError("Audio content is not yet supported by the Responses API") | ||
| if isinstance(content, MediaContentUrl): | ||
| if content.type != "image": | ||
| raise ValueError( | ||
| "Message contains a non-image URL, but the Responses API only supports image URLs." | ||
| ) | ||
| return {"type": "input_image", "image_url": content.url} | ||
| # Must be MediaContentBase64 at this point | ||
| if content.type == "file": | ||
| return { | ||
| "type": "input_file", | ||
| "filename": f"{content.slot_name}.{content.content_type.split('/')[-1]}", | ||
| "file_data": f"data:{content.content_type};base64,{content.data}", | ||
| } | ||
| return { | ||
| "type": "input_image", | ||
| "image_url": f"data:{content.content_type};base64,{content.data}", | ||
| } | ||
|
|
||
|
|
||
| class BedrockConverseAdapter(LLMAdapter): | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.