|
16 | 16 | ) |
17 | 17 | from openai.types.chat.chat_completion_message import Annotation as OpenAIAnnotation |
18 | 18 | from openai.types.responses import ( |
| 19 | + FunctionTool, |
19 | 20 | ResponseCodeInterpreterCallCodeDeltaEvent, |
20 | 21 | ResponseCodeInterpreterCallCodeDoneEvent, |
21 | 22 | ResponseCodeInterpreterCallCompletedEvent, |
|
36 | 37 | ResponseWebSearchCallCompletedEvent, |
37 | 38 | ResponseWebSearchCallInProgressEvent, |
38 | 39 | ResponseWebSearchCallSearchingEvent, |
| 40 | + ToolChoiceFunction, |
39 | 41 | ) |
40 | 42 | from openai.types.responses import ( |
41 | 43 | ResponseCompletedEvent as OpenAIResponseCompletedEvent, |
|
56 | 58 |
|
57 | 59 |
|
58 | 60 | from openai.types.responses.response import IncompleteDetails, ToolChoice |
59 | | -from openai.types.responses.tool import FunctionTool, Tool |
| 61 | +from openai.types.responses.tool import Tool |
60 | 62 | from openai.types.shared import Metadata, Reasoning |
61 | 63 | from pydantic import ( |
62 | 64 | BaseModel, |
@@ -296,13 +298,15 @@ def get_logits_processors( |
296 | 298 |
|
297 | 299 | def get_json_schema_from_tool( |
298 | 300 | tool_choice: str | ToolChoice | ChatCompletionNamedToolChoiceParam, |
299 | | - tools: list[Tool | ChatCompletionToolsParam] | None, |
| 301 | + tools: list[FunctionTool | ChatCompletionToolsParam] | None, |
300 | 302 | ) -> str | dict | None: |
301 | 303 | if tool_choice in ("none", None) or tools is None: |
302 | 304 | return None |
303 | | - if (not isinstance(tool_choice, str)) and isinstance(tool_choice, ToolChoice): |
| 305 | + if (not isinstance(tool_choice, str)) and isinstance( |
| 306 | + tool_choice, ToolChoiceFunction |
| 307 | + ): |
304 | 308 | tool_name = tool_choice.name |
305 | | - tool_map = {tool.name: tool for tool in tools if isinstance(tool, Tool)} |
| 309 | + tool_map = {tool.name: tool for tool in tools if isinstance(tool, FunctionTool)} |
306 | 310 | if tool_name not in tool_map: |
307 | 311 | raise ValueError(f"Tool '{tool_name}' has not been passed in `tools`.") |
308 | 312 | return tool_map[tool_name].parameters |
@@ -522,11 +526,11 @@ def _get_structured_outputs(self) -> StructuredOutputsParams | None: |
522 | 526 | raise NotImplementedError("json_object is not supported") |
523 | 527 | # Function call |
524 | 528 | elif not (self.tool_choice == "none" or self.tools is None): |
525 | | - structured_outputs = StructuredOutputsParams( |
526 | | - json=get_json_schema_from_tool( |
527 | | - tools=self.tools, tool_choice=self.tool_choice |
528 | | - ) |
| 529 | + json_schema = get_json_schema_from_tool( |
| 530 | + tools=self.tools, tool_choice=self.tool_choice |
529 | 531 | ) |
| 532 | + if json_schema is not None: |
| 533 | + structured_outputs = StructuredOutputsParams(json=json_schema) |
530 | 534 | return structured_outputs |
531 | 535 |
|
532 | 536 | def is_include_output_logprobs(self) -> bool: |
|
0 commit comments