Prerequisites
- OpenAI API key (Get one here)
- Seltz API key (Get one here)
Installation
Setup
Set your API keys as environment variables:Define the Search Tool
Create a tool schema that describes the Seltz search function to OpenAI:Using Chat Completions API
Here’s a complete example using OpenAI’s Chat Completions API with Seltz search:How It Works
- User sends a message - The user asks a question that may require search
- OpenAI decides to search - The model determines if it needs external information
- Tool call is made - OpenAI returns a tool call with the search query
- Seltz executes search - Your code calls Seltz with the query
- Results sent back - Search results are added to the conversation
- Final response - OpenAI generates a response using the search results
Streaming Responses
For a better user experience, stream the final response:Multi-Turn Conversations
Maintain conversation history for follow-up questions:Error Handling
Handle Seltz errors gracefully so the model can respond appropriately:Best Practices
Write clear tool descriptions
Write clear tool descriptions
The description helps OpenAI decide when to use the tool. Be specific about what the search returns and when it should be used.
Limit results appropriately
Limit results appropriately
More results mean more tokens. Use
max_results to balance comprehensiveness with cost and latency.Handle errors gracefully
Handle errors gracefully
Return error information as JSON so the model can inform the user or try alternative approaches.
Use streaming for better UX
Use streaming for better UX
Stream the final response so users see output immediately rather than waiting for the full response.
Next Steps
Anthropic Tool Calling
Integrate with Claude models.
Agno Framework
Build autonomous agents with Seltz.