⚫OpenAI Assistant
The OpenAI Assistant class provides a wrapper around OpenAI's Assistants API, integrating it with the zytron framework.
Overview
The OpenAIAssistant
class allows you to create and interact with OpenAI Assistants, providing a simple interface for:
Creating assistants with specific roles and capabilities
Adding custom functions that the assistant can call
Managing conversation threads
Handling tool calls and function execution
Getting responses from the assistant
Insstallation
Basic Usage
Function Calling
The assistant supports custom function integration:
API Reference
Constructor
Methods
run(task: str) -> str
Sends a task to the assistant and returns its response. The conversation thread is maintained between calls.
add_function(func: Callable, description: str, parameters: Dict[str, Any]) -> None
Adds a callable function that the assistant can use during conversations.
add_message(content: str, file_ids: Optional[List[str]] = None) -> None
Adds a message to the current conversation thread.
Error Handling
The assistant implements robust error handling: - Retries on rate limits - Graceful handling of API errors - Clear error messages for debugging - Status monitoring for runs and completions
Best Practices
Thread Management
Use the same assistant instance for related conversations
Create new instances for unrelated tasks
Monitor thread status during long-running operations
Function Integration
Keep functions simple and focused
Provide clear descriptions and parameter schemas
Handle errors gracefully in custom functions
Test functions independently before integration
Performance
Reuse assistant instances when possible
Monitor and handle rate limits appropriately
Use appropriate polling intervals for status checks
Consider implementing timeouts for long-running operations
Last updated