MCPcopy
hub / github.com/openai/openai-python / _make_tools

Function _make_tools

src/openai/resources/responses/responses.py:3723–3758  ·  view source on GitHub ↗
(tools: Iterable[ParseableToolParam] | Omit)

Source from the content-addressed store, hash-verified

3721
3722
3723def _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
3761class AsyncResponsesConnection:

Callers 4

streamMethod · 0.85
parseMethod · 0.85
streamMethod · 0.85
parseMethod · 0.85

Calls 5

castMethod · 0.95
is_givenFunction · 0.85
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected