chore: import upstream snapshot with attribution
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
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) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
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) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
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) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
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
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# simple-csv (Simple CSV Example)
|
||||
|
||||
You can run this example with:
|
||||
|
||||
```bash
|
||||
npx promptfoo@latest init --example simple-csv
|
||||
cd simple-csv
|
||||
```
|
||||
|
||||
This example demonstrates how to use CSV and Excel files for test cases in promptfoo, including working with JSON fields for language translation tasks.
|
||||
|
||||
## Features Demonstrated
|
||||
|
||||
- CSV and Excel (XLSX) test case formats with JSON configuration fields
|
||||
- Multiple prompt variations for different translation styles
|
||||
- Style configuration via JSON fields (tone, length)
|
||||
- Case-insensitive test assertions (icontains)
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `promptfooconfig.yaml`: Main configuration file
|
||||
- `prompts.txt`: Contains two prompt templates:
|
||||
1. A formal translator prompt
|
||||
2. A conversational language assistant prompt
|
||||
- `tests.csv`: Test cases for French and Pirate translations
|
||||
- `tests.xlsx`: Same test cases in Excel format (optional)
|
||||
|
||||
## Using Excel Files
|
||||
|
||||
To use Excel files instead of CSV:
|
||||
|
||||
1. Install the read-excel-file package (optional peer dependency):
|
||||
|
||||
```bash
|
||||
npm install read-excel-file
|
||||
```
|
||||
|
||||
2. Update `promptfooconfig.yaml` to use the Excel file:
|
||||
```yaml
|
||||
tests: file://tests.xlsx
|
||||
```
|
||||
|
||||
Excel files work exactly like CSV files - each row becomes a test case, and column headers become variable names.
|
||||
|
||||
### Multi-sheet Excel Files
|
||||
|
||||
For workbooks with multiple sheets, you can specify which sheet to use:
|
||||
|
||||
```yaml
|
||||
# Use a specific sheet by name
|
||||
tests: file://tests.xlsx#MyDataSheet
|
||||
|
||||
# Or by 1-based index (2 = second sheet)
|
||||
tests: file://tests.xlsx#2
|
||||
```
|
||||
|
||||
## Running the Tests
|
||||
|
||||
From the root of this example, you can run the eval as:
|
||||
|
||||
```bash
|
||||
promptfoo eval
|
||||
```
|
||||
|
||||
To view the results in your browser:
|
||||
|
||||
```bash
|
||||
promptfoo view
|
||||
```
|
||||
|
||||
For more details on using CSV and Excel files in promptfoo, see our [CSV Format](https://www.promptfoo.dev/docs/configuration/test-cases/#csv-format) documentation.
|
||||
@@ -0,0 +1,98 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Table Output</title>
|
||||
<style>
|
||||
body {
|
||||
font-family:
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
Segoe UI,
|
||||
Roboto,
|
||||
Helvetica,
|
||||
Arial,
|
||||
sans-serif;
|
||||
}
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid black;
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
word-break: break-all;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
padding: 5px;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
tr > td[data-content^='[PASS]'] {
|
||||
color: green;
|
||||
}
|
||||
tr > td[data-content^='[FAIL]'] {
|
||||
color: #ad0000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<thead>
|
||||
<th>Rephrase this in {{language}}: {{body}}</th>
|
||||
|
||||
<th>Translate this to conversational {{language}}: {{body}}</th>
|
||||
|
||||
<th>body</th>
|
||||
|
||||
<th>language</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-content="Bonjour le monde">Bonjour le monde</td>
|
||||
|
||||
<td data-content="Bonjour le monde">Bonjour le monde</td>
|
||||
|
||||
<td data-content="Hello world">Hello world</td>
|
||||
|
||||
<td data-content="French">French</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td data-content="J'ai faim.">J'ai faim.</td>
|
||||
|
||||
<td data-content="J'ai faim.">J'ai faim.</td>
|
||||
|
||||
<td data-content="I'm hungry">I'm hungry</td>
|
||||
|
||||
<td data-content="French">French</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td data-content="Ahoy thar, world!">Ahoy thar, world!</td>
|
||||
|
||||
<td data-content="Ahoy thar world!">Ahoy thar world!</td>
|
||||
|
||||
<td data-content="Hello world">Hello world</td>
|
||||
|
||||
<td data-content="Pirate">Pirate</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td data-content="Arrr, me belly be empty and yearnin' for grub.">
|
||||
Arrr, me belly be empty and yearnin' for grub.
|
||||
</td>
|
||||
|
||||
<td data-content="Arrr, me belly be rumblin'! I be needin' some grub!">
|
||||
Arrr, me belly be rumblin'! I be needin' some grub!
|
||||
</td>
|
||||
|
||||
<td data-content="I'm hungry">I'm hungry</td>
|
||||
|
||||
<td data-content="Pirate">Pirate</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"version": 1,
|
||||
"results": [
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Rephrase this in French: Hello world",
|
||||
"display": "Rephrase this in {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "French",
|
||||
"body": "Hello world"
|
||||
},
|
||||
"response": {
|
||||
"output": "Bonjour le monde",
|
||||
"tokenUsage": {
|
||||
"cached": 19
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Translate this to conversational French: Hello world",
|
||||
"display": "Translate this to conversational {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "French",
|
||||
"body": "Hello world"
|
||||
},
|
||||
"response": {
|
||||
"output": "Bonjour le monde",
|
||||
"tokenUsage": {
|
||||
"cached": 20
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Rephrase this in French: I'm hungry",
|
||||
"display": "Rephrase this in {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "French",
|
||||
"body": "I'm hungry"
|
||||
},
|
||||
"response": {
|
||||
"output": "J'ai faim.",
|
||||
"tokenUsage": {
|
||||
"cached": 24
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Translate this to conversational French: I'm hungry",
|
||||
"display": "Translate this to conversational {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "French",
|
||||
"body": "I'm hungry"
|
||||
},
|
||||
"response": {
|
||||
"output": "J'ai faim.",
|
||||
"tokenUsage": {
|
||||
"cached": 25
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Rephrase this in Pirate: Hello world",
|
||||
"display": "Rephrase this in {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "Pirate",
|
||||
"body": "Hello world"
|
||||
},
|
||||
"response": {
|
||||
"output": "Ahoy thar, world!",
|
||||
"tokenUsage": {
|
||||
"cached": 23
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Translate this to conversational Pirate: Hello world",
|
||||
"display": "Translate this to conversational {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "Pirate",
|
||||
"body": "Hello world"
|
||||
},
|
||||
"response": {
|
||||
"output": "Ahoy thar world!",
|
||||
"tokenUsage": {
|
||||
"cached": 23
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Rephrase this in Pirate: I'm hungry",
|
||||
"display": "Rephrase this in {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "Pirate",
|
||||
"body": "I'm hungry"
|
||||
},
|
||||
"response": {
|
||||
"output": "Arrr, me belly be empty and yearnin' for grub.",
|
||||
"tokenUsage": {
|
||||
"cached": 33
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"prompt": {
|
||||
"raw": "Translate this to conversational Pirate: I'm hungry",
|
||||
"display": "Translate this to conversational {{language}}: {{body}}"
|
||||
},
|
||||
"vars": {
|
||||
"language": "Pirate",
|
||||
"body": "I'm hungry"
|
||||
},
|
||||
"response": {
|
||||
"output": "Arrr, me belly be rumblin'! I be needin' some grub!",
|
||||
"tokenUsage": {
|
||||
"cached": 39
|
||||
}
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"successes": 8,
|
||||
"failures": 0,
|
||||
"tokenUsage": {
|
||||
"total": 0,
|
||||
"prompt": 0,
|
||||
"completion": 0,
|
||||
"cached": 206
|
||||
}
|
||||
},
|
||||
"table": {
|
||||
"head": {
|
||||
"prompts": [
|
||||
"Rephrase this in {{language}}: {{body}}",
|
||||
"Translate this to conversational {{language}}: {{body}}"
|
||||
],
|
||||
"vars": ["body", "language"]
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"outputs": ["Bonjour le monde", "Bonjour le monde"],
|
||||
"vars": ["Hello world", "French"]
|
||||
},
|
||||
{
|
||||
"outputs": ["J'ai faim.", "J'ai faim."],
|
||||
"vars": ["I'm hungry", "French"]
|
||||
},
|
||||
{
|
||||
"outputs": ["Ahoy thar, world!", "Ahoy thar world!"],
|
||||
"vars": ["Hello world", "Pirate"]
|
||||
},
|
||||
{
|
||||
"outputs": [
|
||||
"Arrr, me belly be empty and yearnin' for grub.",
|
||||
"Arrr, me belly be rumblin'! I be needin' some grub!"
|
||||
],
|
||||
"vars": ["I'm hungry", "Pirate"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: A translator built with LLM (using Excel file)
|
||||
prompts:
|
||||
- file://prompts.txt
|
||||
providers:
|
||||
- openai:gpt-4.1-mini
|
||||
tests: file://tests.xlsx
|
||||
@@ -0,0 +1,9 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: A translator built with LLM
|
||||
prompts:
|
||||
- file://prompts.txt
|
||||
providers:
|
||||
- openai:gpt-4.1-mini
|
||||
tests: file://tests.csv
|
||||
# Alternative: Use Excel file instead (requires `npm install read-excel-file`)
|
||||
# tests: file://tests.xlsx
|
||||
@@ -0,0 +1,15 @@
|
||||
You are a skilled translator and language expert. Follow these style requirements:
|
||||
- Tone: {{ (style_config | load).tone }}
|
||||
- Length: {{ (style_config | load).length }}
|
||||
|
||||
Task: Rephrase the following text in {{language}}:
|
||||
"{{body}}"
|
||||
|
||||
Ensure your response matches the specified style.
|
||||
---
|
||||
You are a conversational language assistant. Follow the style configuration: {{style_config}}.
|
||||
|
||||
Task: Translate this text to {{language}} in a natural, conversational way:
|
||||
"{{body}}"
|
||||
|
||||
Make sure to maintain the intended tone while keeping it casual and friendly.
|
||||
@@ -0,0 +1,5 @@
|
||||
language,body,style_config,__expected
|
||||
French,"Hello world","{""tone"":""formal"",""length"":""brief""}","icontains:bonjour"
|
||||
French,"I'm hungry","{""tone"":""casual"",""length"":""brief""}","icontains:faim"
|
||||
Pirate,"Hello world","{""tone"":""authentic"",""length"":""moderate""}","icontains:Ahoy"
|
||||
Pirate,"I'm hungry","{""tone"":""authentic"",""length"":""moderate""}","icontains:grub"
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user