Prerequisites
- Mistral 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 Mistral:Using the Chat API
Here’s a complete example using Mistral’s Chat API with Seltz search:How It Works
- User sends a message - The user asks a question that may require search
- Mistral decides to search - The model determines if it needs external information
- Tool call is made - Mistral 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 - Mistral generates a response using the search results
Streaming Responses
Stream the final response for better user experience:Multi-Turn Conversations
Maintain conversation history for follow-up questions:Available Models
Mistral models that support function calling:Error Handling
Handle Seltz errors gracefully so Mistral can respond appropriately:Best Practices
Write clear tool descriptions
Write clear tool descriptions
Mistral uses the description to decide when to use the tool. Be explicit about what information the search provides and when it should be used.
Choose the right model
Choose the right model
Use
mistral-large-latest for complex queries requiring nuanced understanding. Use smaller models for straightforward searches to reduce latency and cost.Handle errors gracefully
Handle errors gracefully
Return error information as JSON so Mistral can inform the user or suggest alternatives.
Use streaming for better UX
Use streaming for better UX
Stream the final response so users see output immediately rather than waiting for the complete response.
Next Steps
OpenAI Tool Calling
Integrate with OpenAI models.
Anthropic Tool Calling
Integrate with Claude models.