Represents a single tool call in a list of tool calls generated by OpenAI LLM API. See https://platform.openai.com/docs/api-reference/chat/create Attributes: id: The id of the tool call. type: The type of the tool call; only "function" is currently possible
| 164 | |
| 165 | |
| 166 | class OpenAIToolCall(BaseModel): |
| 167 | """ |
| 168 | Represents a single tool call in a list of tool calls generated by OpenAI LLM API. |
| 169 | See https://platform.openai.com/docs/api-reference/chat/create |
| 170 | |
| 171 | Attributes: |
| 172 | id: The id of the tool call. |
| 173 | type: The type of the tool call; |
| 174 | only "function" is currently possible (7/26/24). |
| 175 | function: The function call. |
| 176 | """ |
| 177 | |
| 178 | id: str | None = None |
| 179 | type: ToolTypes = "function" |
| 180 | function: LLMFunctionCall | None = None |
| 181 | extra_content: Dict[str, Any] | None = None |
| 182 | |
| 183 | @staticmethod |
| 184 | def from_dict(message: Dict[str, Any]) -> "OpenAIToolCall": |
| 185 | """ |
| 186 | Initialize from dictionary. |
| 187 | Args: |
| 188 | d: dictionary containing fields to initialize |
| 189 | """ |
| 190 | id = message["id"] |
| 191 | type = message["type"] |
| 192 | function = LLMFunctionCall.from_dict(message["function"]) |
| 193 | extra_content = message.get("extra_content") |
| 194 | return OpenAIToolCall( |
| 195 | id=id, type=type, function=function, extra_content=extra_content |
| 196 | ) |
| 197 | |
| 198 | def __str__(self) -> str: |
| 199 | if self.function is None: |
| 200 | return "" |
| 201 | return "OAI-TOOL: " + json.dumps(self.function.model_dump(), indent=2) |
| 202 | |
| 203 | |
| 204 | class OpenAIToolSpec(BaseModel): |
no outgoing calls
searching dependent graphs…