将工具定义从 Responses API 格式转换为 Chat Completions API 格式
(tools: list)
| 118 | |
| 119 | |
| 120 | def _convert_tools(tools: list) -> list: |
| 121 | """将工具定义从 Responses API 格式转换为 Chat Completions API 格式""" |
| 122 | result = [] |
| 123 | for tool in tools: |
| 124 | if not isinstance(tool, dict): |
| 125 | continue |
| 126 | if tool.get("type") != "function": |
| 127 | continue |
| 128 | func = { |
| 129 | "name": tool.get("name", ""), |
| 130 | "description": tool.get("description", ""), |
| 131 | } |
| 132 | if "parameters" in tool: |
| 133 | func["parameters"] = _clean_schema(tool["parameters"]) |
| 134 | result.append({"type": "function", "function": func}) |
| 135 | return result |
| 136 | |
| 137 | |
| 138 | def _convert_tool_choice(tc): |
no test coverage detected