pydantic_function_tool()
Convert a Pydantic model into a function tool for chat completions. This enables structured outputs with automatic schema generation.Basic Usage
Function Signature
Parameters
Custom Name and Description
With Structured Outputs
Combine with theparse() method for automatic response parsing:
file_from_path()
Convert a file path to a format suitable for file upload APIs.Basic Usage
Function Signature
(filename, contents) where:
filenameis the base name of the filecontentsis the file’s bytes
Example with Path Objects
Direct Path Usage
You can also passPath objects directly without using file_from_path():
AssistantEventHandler
Event handler for streaming Assistant responses. This provides structured access to events during Assistant runs.Basic Usage
Available Methods
Override these methods to handle specific events:Text Deltas Iterator
Access just the text deltas:Properties
Access current state during streaming:AsyncAssistantEventHandler
Async version ofAssistantEventHandler: