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
@@ -0,0 +1,97 @@
# eval-max-score-selection (Max-Score Selection)
You can run this example with:
```bash
npx promptfoo@latest init --example eval-max-score-selection
cd eval-max-score-selection
```
This example demonstrates the `max-score` assertion type for objective output selection based on aggregated scores from other assertions.
## Overview
The `max-score` assertion provides a deterministic way to select the best output from multiple providers by:
- Aggregating scores from other assertions (correctness, quality, documentation, etc.)
- Applying configurable weights to different assertion types
- Selecting the output with the highest weighted score
- Providing objective, reproducible selection criteria
## Key Differences from `select-best`
- **Objective**: Uses quantifiable scores rather than LLM judgment
- **Deterministic**: Same inputs always produce same selection
- **Transparent**: Clear scoring methodology based on weighted assertions
- **Cost-effective**: No additional LLM calls for selection
## Configuration
```yaml
- type: max-score
value:
method: average # 'average' (default) or 'sum'
weights:
python: 3 # Weight for Python code correctness tests
llm-rubric: 1 # Weight for LLM-evaluated quality rubrics
javascript: 2 # Weight for JavaScript tests
contains: 0.5 # Weight for simple string matching
threshold: 0.7 # Optional minimum score threshold
```
### Options
- **method**: How to aggregate scores
- `average` (default): Weighted average of assertion scores
- `sum`: Weighted sum of assertion scores
- **weights**: Map of assertion types to their weights (default: 1.0)
- **threshold**: Minimum score required for selection (optional)
## Usage
### Basic Example
```bash
# Run the main example (requires API keys for OpenAI/Anthropic)
npx promptfoo@latest eval
```
## How It Works
1. **Multiple Outputs Generated**: Each provider generates a solution
2. **Assertions Evaluated**: All assertions run on each output:
- Python tests verify correctness (pass=1, fail=0)
- LLM rubrics evaluate quality aspects (0-1 score)
- Other assertions contribute their scores
3. **Scores Aggregated**: Max-score calculates weighted score for each output
4. **Best Selected**: Output with highest score is marked as passing
5. **Results Shown**: Clear indication of which output won and why
## Example Scoring
Given three outputs with these assertion results:
- Output A: python=1.0, documentation=0.5, efficiency=0.7
- Output B: python=1.0, documentation=0.9, efficiency=0.8
- Output C: python=0.0, documentation=1.0, efficiency=1.0
With weights: python=3, llm-rubric=1
- Output A: (3×1.0 + 1×0.5 + 1×0.7) / 5 = 0.84
- Output B: (3×1.0 + 1×0.9 + 1×0.8) / 5 = 0.94 ✓ (selected)
- Output C: (3×0.0 + 1×1.0 + 1×1.0) / 5 = 0.40
## When to Use max-score
Use `max-score` when:
- You have objective criteria (tests, metrics)
- You want reproducible results
- You need to weight different aspects differently
- You want to avoid additional API costs
Use `select-best` when:
- You need subjective judgment
- The criteria are hard to quantify
- You want nuanced evaluation of quality
@@ -0,0 +1,71 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Max-score assertion for objective output selection
# This example demonstrates how max-score can objectively select the best implementation
# based on weighted scores from multiple assertions (correctness, documentation, efficiency)
prompts:
- 'Generate a Python function to {{task}}'
- 'Write an efficient Python function to {{task}}'
- 'Create a well-documented Python function to {{task}}'
providers:
- openai:o4-mini
- anthropic:claude-sonnet-4-20250514
- google:gemini-2.5-flash
tests:
- vars:
task: 'merge two sorted lists into one sorted list'
assert:
# Correctness test
- type: python
value: |
# Test the merge function
list1 = [1, 3, 5, 7, 9]
list2 = [2, 4, 6, 8, 10]
result = merge_sorted_lists(list1, list2)
assert result == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], f"Expected [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], got {result}"
# Test with empty lists
assert merge_sorted_lists([], [1, 2, 3]) == [1, 2, 3]
assert merge_sorted_lists([1, 2, 3], []) == [1, 2, 3]
assert merge_sorted_lists([], []) == []
# Documentation test
- type: llm-rubric
value: 'Code includes a clear docstring explaining parameters, return value, and complexity'
# Code structure and efficiency
- type: llm-rubric
value: 'The implementation uses an efficient algorithm (O(m+n) time complexity) and follows Python best practices'
# Max-score selects the best implementation objectively
- type: max-score
value:
weights:
python: 3 # Correctness is most important
llm-rubric: 1.5 # Documentation and code quality weighted together
- vars:
task: 'check if a string is a palindrome (ignoring case and spaces)'
assert:
# Correctness
- type: python
value: |
assert is_palindrome("racecar") == True
assert is_palindrome("A man a plan a canal Panama") == True
assert is_palindrome("race a car") == False
assert is_palindrome("hello") == False
assert is_palindrome("") == True
# Edge case handling
- type: llm-rubric
value: 'Handles edge cases like empty strings and single characters correctly'
# Efficiency
- type: llm-rubric
value: 'Uses an efficient algorithm (O(n) time complexity)'
# Simple max-score (all assertions equally weighted)
- type: max-score