| 3721 | |
| 3722 | |
| 3723 | def _make_tools(tools: Iterable[ParseableToolParam] | Omit) -> List[ToolParam] | Omit: |
| 3724 | if not is_given(tools): |
| 3725 | return omit |
| 3726 | |
| 3727 | converted_tools: List[ToolParam] = [] |
| 3728 | for tool in tools: |
| 3729 | if tool["type"] != "function": |
| 3730 | converted_tools.append(tool) |
| 3731 | continue |
| 3732 | |
| 3733 | if "function" not in tool: |
| 3734 | # standard Responses API case |
| 3735 | converted_tools.append(tool) |
| 3736 | continue |
| 3737 | |
| 3738 | function = cast(Any, tool)["function"] # pyright: ignore[reportUnnecessaryCast] |
| 3739 | if not isinstance(function, PydanticFunctionTool): |
| 3740 | raise Exception( |
| 3741 | "Expected Chat Completions function tool shape to be created using `openai.pydantic_function_tool()`" |
| 3742 | ) |
| 3743 | |
| 3744 | assert "parameters" in function |
| 3745 | new_tool = ResponsesPydanticFunctionTool( |
| 3746 | { |
| 3747 | "type": "function", |
| 3748 | "name": function["name"], |
| 3749 | "description": function.get("description"), |
| 3750 | "parameters": function["parameters"], |
| 3751 | "strict": function.get("strict") or False, |
| 3752 | }, |
| 3753 | function.model, |
| 3754 | ) |
| 3755 | |
| 3756 | converted_tools.append(new_tool.cast()) |
| 3757 | |
| 3758 | return converted_tools |
| 3759 | |
| 3760 | |
| 3761 | class AsyncResponsesConnection: |