Are you sure you want to delete this access key?
Evaluate Azure OpenAI Assistants with file search, function tools, and multi-tool interactions.
You can run this example with:
npx promptfoo@latest init --example azure-openai-assistant
This example requires the following environment variables:
AZURE_API_KEY
- Your Azure OpenAI API keyAZURE_OPENAI_API_HOST
- Your Azure OpenAI API host (e.g., "your-resource-name.openai.azure.com")You can set these in a .env
file or directly in your environment.
This example includes several configuration files, each demonstrating different tool capabilities:
To run a specific configuration:
# File search example
npx promptfoo@latest eval -c promptfooconfig-file-search.yaml
# Function tool capability example
npx promptfoo@latest eval -c promptfooconfig-function.yaml
# Multi-tool example
npx promptfoo@latest eval -c promptfooconfig-multi-tool.yaml
The file search configuration demonstrates how to use vector store-backed file search.
Key components:
tools
configuration with type: "file_search"
(no description field)tool_resources
with vector store ID configurationImportant: The file search tool must be defined without a description field, as Azure OpenAI API does not support it for this tool type.
The function tool configuration shows how to define and use custom functions.
Key components:
tools/weather-function.json
)callbacks/weather.js
The multi-tool configuration demonstrates how to combine multiple tools.
Key components:
To use this example with your own Azure OpenAI Assistant:
your_assistant_id
with your actual ID)your_vector_store_id
with your own vector store IDapiHost
to match your Azure OpenAI endpoint (e.g., "your-resource-name.openai.azure.com")This example demonstrates two approaches to implementing functions:
# Load tools from external file
tools: file://tools/weather-function.json
# External file-based callback
functionToolCallbacks:
get_weather: file://callbacks/weather.js:getWeather
For more complex scenarios, you can combine multiple tools and inline function callbacks:
# Multiple tools defined
tools: file://tools/multiple-tools.json
# Multiple inline function callbacks
functionToolCallbacks:
get_weather: |
async function(args) {
// Weather function implementation
}
suggest_recipe: |
async function(args) {
// Recipe function implementation
}
Function callbacks can optionally receive context information about the current conversation:
// Enhanced callback with context for audit logging
functionToolCallbacks: {
get_employee_data: async (args, context) => {
const { employeeId } = JSON.parse(args);
// Log access with thread context for audit trail
console.log(`Access to employee ${employeeId} requested`, {
threadId: context?.threadId,
timestamp: new Date().toISOString(),
provider: context?.provider,
});
// Your function logic here
return JSON.stringify({ name: 'John Doe', department: 'Engineering' });
};
}
The context object includes:
threadId
: Unique identifier for the conversation threadrunId
: Identifier for the current assistant runassistantId
: The assistant being usedprovider
: The provider type ('azure' or 'openai')This is particularly useful for session management, audit logging, and tracking stateful interactions across function calls.
For more information about using Azure OpenAI with promptfoo, including authentication methods, provider types, and configuration options, see the official Azure provider documentation.
type: "file_search"
without a description field. Adding a description will cause API errorsPress p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?