Skip to main content

Module openai

Module openai 

Source
Expand description

OpenAI Chat Completions dialect: tool_calls in, role: "tool" denial messages out. Works with the OpenAI SDKs and any OpenAI-compatible server.

Constants§

DIALECT
Dialect name used in error messages and the Python bindings.

Functions§

denial
Render a denied/undecided call as the role: "tool" message the chat history expects, so the model receives the refusal as tool output. Returns None for allowed calls.
filter_tools
Filter a request’s tools array down to the definitions keep accepts. Handles both the Chat Completions shape ({"type": "function", "function": {"name": ...}}) and the Responses API shape ({"type": "function", "name": ...}). Unidentifiable entries are dropped.
parse_tool_calls
Parse tool calls from any of the shapes the OpenAI API surfaces them in: a full chat completion (choices[*].message.tool_calls), an assistant message ({"tool_calls": [...]}), or the bare tool_calls array.