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
+128
View File
@@ -0,0 +1,128 @@
# google-aistudio-tools (Google AI Studio Tools)
This example demonstrates how to use Google AI Studio's function calling, search capabilities, code execution, and URL context features with promptfoo.
You can run this example with:
```bash
npx promptfoo@latest init --example google-aistudio-tools
cd google-aistudio-tools
```
## Prerequisites
- Google AI Studio API key set as `GOOGLE_API_KEY` in your environment
## Overview
This example shows how to:
1. **Function Calling**: Use Gemini to invoke predefined functions based on user queries
2. **Google Search Integration**: Get up-to-date information from the web using Gemini models with search grounding
3. **Code Execution**: Execute Python code to solve computational problems
4. **URL Context**: Extract and analyze content from web URLs
## Function Calling Example
The function calling configuration (`promptfooconfig.yaml`) demonstrates:
- Defining a weather function in `tools.json`
- Validating that Gemini models correctly produce structured function calls
- Testing that the location parameter matches the user's query
Run with:
```bash
promptfoo eval -c promptfooconfig.yaml
```
## Search Grounding Example
The search grounding configuration (`promptfooconfig.search.yaml`) demonstrates:
- Using Gemini 2.5 Flash with Google Search as a tool
- Using Gemini 2.5 Pro with thinking capabilities and Search grounding
- Using Gemini 2.5 Flash-Lite with Google Search grounding
- Testing queries that benefit from real-time web information
- Verifying responses include relevant information
Run with:
```bash
promptfoo eval -c promptfooconfig.search.yaml
```
## Code Execution Example
The code execution configuration (`promptfooconfig.codeexecution.yaml`) demonstrates:
- Testing computational problems that require code to solve
- Verifying that the answer is correct from the code execution
Run with:
```bash
promptfoo eval -c promptfooconfig.codeexecution.yaml
```
## URL Context Example
The URL context configuration (`promptfooconfig.urlcontext.yaml`) demonstrates:
- Using Gemini to extract and analyze content from web URLs
- Combining URL context with search capabilities
Run with:
```bash
promptfoo eval -c promptfooconfig.urlcontext.yaml
```
## Example Files
- `promptfooconfig.yaml`: Function calling configuration
- `promptfooconfig.search.yaml`: Search grounding configuration
- `promptfooconfig.codeexecution.yaml`: Code execution configuration
- `promptfooconfig.urlcontext.yaml`: URL context configuration
- `tools.json`: Function definition for the weather example
## Notes on Google Search Integration
When using Search grounding in your own applications:
- The API response includes search metadata and sources
- Google requires displaying "Google Search Suggestions" in user-facing apps
- Models can retrieve current information about events, prices, and technical updates
### Search Methods
This example demonstrates three approaches to search:
1. **Search as a tool** (Gemini 2.5): Allows the model to decide when to use search
```yaml
tools:
- googleSearch: {}
```
2. **Search with thinking** (Gemini 2.5): Adds thinking capabilities for better reasoning
```yaml
generationConfig:
thinkingConfig:
thinkingBudget: 1024
tools:
- googleSearch: {}
```
3. **Search on Flash-Lite** (Gemini 2.5): Uses the lower-cost Flash-Lite model with the same search tool
```yaml
tools:
- googleSearch: {}
```
## Further Resources
- [Google AI Studio Function Calling documentation](https://ai.google.dev/docs/function_calling)
- [Google AI Studio Search Grounding documentation](https://ai.google.dev/docs/gemini_api/grounding)
- [promptfoo Google Provider documentation](/docs/providers/google)
@@ -0,0 +1,21 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Code execution with Google Gemini models
prompts:
- '{{query}}'
providers:
- id: google:gemini-2.5-flash
config:
temperature: 0.2
tools:
- codeExecution: {}
tests:
- vars:
query: |
"Draw an ASCII Sierpiński triangle of depth 4, then report how many * characters appear in the drawing."
assert:
- type: contains
value: 81 # A Sierpiński triangle of depth 4 has 3^4 = 81 asterisks
@@ -0,0 +1,62 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Web search grounding with Google Gemini models
prompts:
- '{{query}}'
providers:
# Google Search as a tool (using Gemini 2.5 Flash)
- id: google:gemini-2.5-flash
config:
temperature: 0.2
maxOutputTokens: 1024
tools:
- googleSearch: {}
# Alternate version with thinking capabilities
- id: google:gemini-2.5-pro
config:
temperature: 0.2
maxOutputTokens: 1024
generationConfig:
thinkingConfig:
thinkingBudget: 1024
tools:
- googleSearch: {}
# Google Search grounding on the cost-efficient Flash-Lite model
- id: google:gemini-2.5-flash-lite
config:
temperature: 0.2
maxOutputTokens: 1024
tools:
- googleSearch: {}
tests:
# Test current events
- vars:
query: What is the current Google stock price?
assert:
- type: contains
value: stock
- type: contains
value: '$'
# Test a technical question
- vars:
query: What are the latest features in TypeScript?
assert:
- type: contains
value: TypeScript
- type: contains
value: feature
# Test a factual question
- vars:
query: Who won the most recent Super Bowl?
assert:
- type: contains
value: Super Bowl
- type: contains
value: won
@@ -0,0 +1,32 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Url context with Google Gemini models
prompts:
- '{{query}}'
providers:
- id: google:gemini-2.5-flash
config:
temperature: 0.2
tools:
- urlContext: {}
# Advanced version with thinking capabilities and additional search
- id: google:gemini-2.5-pro
config:
temperature: 0.2
generationConfig:
thinkingConfig:
thinkingBudget: 1024
tools:
- googleSearch: {}
- urlContext: {}
tests:
- vars:
query: 'Could you make a tour plan inspired by https://www.nhm.ac.uk/visit/whats-on.html, https://www.tate.org.uk/whats-on/tate-modern/expressionists'
assert:
- type: llm-rubric
value: |
Contains a comprehensive plan to visit Natural History Museum and Tate Modern.
@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
# Learn more about building a configuration: https://promptfoo.dev/docs/configuration/guide
description: 'Function calling with Google AI Studio Gemini models'
prompts:
- What is the weather in {{location}}?
providers:
- id: 'google:gemini-2.5-flash'
config:
tools: file://tools.json
defaultTest:
options:
# This overrides the default grading providers with Vertex AI models
providers:
embedding: 'google:embedding:text-embedding-005'
text: 'google:gemini-2.5-flash'
tests:
# Function calling tests
- vars:
location: San Francisco
assert:
- type: is-valid-function-call
- type: equals
value: get_current_weather
# Transform is a cleaner way to pick out specific properties
transform: output[0].functionCall.name
- type: icontains
value: '{{location}}'
# Transform returns only the parsed location argument.
# The model may normalize locations, e.g. "San Francisco, CA".
transform: output[0].functionCall.args.location
- vars:
location: New York
assert:
- type: is-valid-function-call
- type: equals
value: get_current_weather
transform: output[0].functionCall.name
- type: icontains
value: '{{location}}'
transform: output[0].functionCall.args.location
+20
View File
@@ -0,0 +1,20 @@
[
{
"functionDeclarations": [
{
"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 or a zip code e.g. 95616"
}
},
"required": ["location"]
}
}
]
}
]