chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:24:08 +08:00
commit 0d3cb498a3
5438 changed files with 1316560 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
# openai-tools-call (OpenAI Tools Call Example)
This example demonstrates how to use promptfoo to evaluate OpenAI's tools calling capabilities. It shows how to define and test tool usage with the Chat Completions API.
## Features Demonstrated
- Defining tools for AI models to use
- Testing tool call outputs
- Validating AI-generated function arguments
- Transforming outputs for assertions
## Environment Variables
This example requires the following environment variables:
- `OPENAI_API_KEY` - Your OpenAI API key
You can set this in a `.env` file or directly in your environment.
## Running the Example
You can run this example with:
```bash
npx promptfoo@latest init --example openai-tools-call
# and then
cd openai-tools-call
# Run the evaluation
npx promptfoo eval
# View the results
npx promptfoo view
```
## What This Example Does
The configuration defines a custom tool for getting weather information. It then tests the model's ability to:
1. Correctly call the weather function when asked about weather
2. Pass the correct location parameter based on the city mentioned
3. Handle various cities, including international ones
4. Format responses consistently
## Key Features
- Uses `is-valid-openai-tools-call` assertion to validate the function call structure
- Demonstrates output transformation to isolate and test specific parts of the response
- Shows how to use JavaScript assertions for detailed validation
- Tests with a variety of locations to ensure robust behavior
## Documentation
For more details, see:
- [OpenAI Tools documentation](https://platform.openai.com/docs/guides/function-calling)
- [promptfoo OpenAI Provider documentation](https://promptfoo.dev/docs/providers/openai#using-tools-and-functions)
@@ -0,0 +1,73 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: OpenAI tools calling with weather API integration
prompts:
- 'What is the weather like in {{city}}?'
providers:
- id: openai:chat:gpt-5.4-mini
config:
verbosity: high
tools:
[
{
'type': 'function',
'function':
{
'name': 'get_current_weather',
'description': 'Get the current weather in a given location',
'parameters':
{
'type': 'object',
'properties':
{
'location':
{
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA',
},
'unit': { 'type': 'string', 'enum': ['celsius', 'fahrenheit'] },
},
'required': ['location'],
},
},
},
]
tests:
- vars:
city: Boston
assert:
- type: is-json
- type: is-valid-openai-tools-call
- type: javascript
value: output[0].function.name === 'get_current_weather'
- type: javascript
value: JSON.parse(output[0].function.arguments).location === 'Boston, MA'
- vars:
city: New York
options:
# Transform is a cleaner way to pick out specific properties.
# This transform returns only the 'name' property
transform: output[0].function.name
assert:
- type: equals
value: get_current_weather
- vars:
city: Paris
assert:
- type: equals
value: get_current_weather
# Transform is a cleaner way to pick out specific properties.
# This transform returns only the 'name' property
transform: output[0].function.name
- type: similar
value: Paris, France
threshold: 0.5
# This transform returns only the parsed location argument.
transform: JSON.parse(output[0].function.arguments).location
- vars:
city: Mars