promptfoo 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -40
- package/dist/assertions.d.ts +2 -2
- package/dist/assertions.d.ts.map +1 -1
- package/dist/assertions.js +186 -44
- package/dist/assertions.js.map +1 -1
- package/dist/cache.js +9 -9
- package/dist/cache.js.map +1 -1
- package/dist/evaluator.d.ts +1 -1
- package/dist/evaluator.d.ts.map +1 -1
- package/dist/evaluator.js +30 -23
- package/dist/evaluator.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/dist/main.js +49 -44
- package/dist/main.js.map +1 -1
- package/dist/providers/localai.js +11 -11
- package/dist/providers/localai.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +30 -21
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers.d.ts +3 -3
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +15 -15
- package/dist/providers.js.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/util.d.ts +4 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +49 -18
- package/dist/util.js.map +1 -1
- package/dist/web/client/assets/index-15dfcd18.js +172 -0
- package/dist/web/client/assets/index-87905193.css +1 -0
- package/dist/web/client/index.html +2 -2
- package/dist/web/server.js +9 -9
- package/dist/web/server.js.map +1 -1
- package/package.json +3 -1
- package/src/assertions.ts +249 -38
- package/src/cache.ts +2 -2
- package/src/evaluator.ts +25 -18
- package/src/index.ts +13 -8
- package/src/main.ts +28 -15
- package/src/providers/localai.ts +3 -3
- package/src/providers/openai.ts +16 -8
- package/src/providers.ts +3 -3
- package/src/types.ts +24 -3
- package/src/util.ts +48 -17
- package/src/web/client/package-lock.json +5729 -0
- package/src/web/client/src/ResultsTable.css +35 -4
- package/src/web/client/src/ResultsTable.tsx +150 -70
- package/src/web/client/src/ResultsView.tsx +83 -18
- package/src/web/client/src/index.css +6 -0
- package/src/web/client/src/types.ts +2 -0
- package/src/web/server.ts +3 -3
- package/dist/web/client/assets/index-207192fc.css +0 -1
- package/dist/web/client/assets/index-8751749f.js +0 -172
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# promptfoo:
|
|
1
|
+
# promptfoo: test your prompts
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.com/package/promptfoo)
|
|
4
|
-

|
|
4
|
+
[](https://github.com/typpo/promptfoo/actions/workflows/main.yml)
|
|
5
5
|
|
|
6
|
-
`promptfoo`
|
|
6
|
+
`promptfoo` is a tool for testing and evaluating LLM prompt quality.
|
|
7
7
|
|
|
8
8
|
With promptfoo, you can:
|
|
9
9
|
|
|
10
|
-
- **
|
|
10
|
+
- **Systematically test prompts** against predefined test cases
|
|
11
11
|
- **Evaluate quality and catch regressions** by comparing LLM outputs side-by-side
|
|
12
12
|
- **Speed up evaluations** with caching and concurrent tests
|
|
13
|
-
- **
|
|
14
|
-
- Use as a
|
|
13
|
+
- **Score outputs automatically** by defining "expectations"
|
|
14
|
+
- Use as a CLI, or integrate into your workflow as a library
|
|
15
15
|
- Use OpenAI models, open-source models like Llama and Vicuna, or integrate custom API providers for any LLM API
|
|
16
16
|
|
|
17
17
|
The goal: **test-driven prompt engineering**, rather than trial-and-error.
|
|
@@ -22,11 +22,11 @@ promptfoo produces matrix views that let you quickly evaluate outputs across man
|
|
|
22
22
|
|
|
23
23
|
Here's an example of a side-by-side comparison of multiple prompts and inputs:
|
|
24
24
|
|
|
25
|
-

|
|
26
26
|
|
|
27
27
|
It works on the command line too:
|
|
28
28
|
|
|
29
|
-

|
|
30
30
|
|
|
31
31
|
## Workflow
|
|
32
32
|
|
|
@@ -61,41 +61,51 @@ The YAML configuration format runs each prompt through a series of example input
|
|
|
61
61
|
See the [Configuration docs](https://www.promptfoo.dev/docs/configuration/guide) for a detailed guide.
|
|
62
62
|
|
|
63
63
|
```yaml
|
|
64
|
-
prompts: [
|
|
65
|
-
providers: [openai:gpt-3.5-turbo]
|
|
64
|
+
prompts: [prompt1.txt, prompt2.txt]
|
|
65
|
+
providers: [openai:gpt-3.5-turbo, localai:chat:vicuna]
|
|
66
|
+
defaultTest:
|
|
67
|
+
assert:
|
|
66
68
|
tests:
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
vars:
|
|
81
|
-
var1: new value
|
|
82
|
-
var2: another value
|
|
83
|
-
var3: third value
|
|
84
|
-
|
|
85
|
-
- description: Third test case - other types of automatic review
|
|
86
|
-
vars:
|
|
87
|
-
var1: yet another value
|
|
88
|
-
var2: and another
|
|
89
|
-
var3: dear llm, please output your response in json format
|
|
90
|
-
assert:
|
|
91
|
-
- type: contains-json
|
|
92
|
-
- type: similarity
|
|
93
|
-
value: ensures that output is semantically similar to this text
|
|
69
|
+
- vars:
|
|
70
|
+
language: French
|
|
71
|
+
input: Hello world
|
|
72
|
+
assert:
|
|
73
|
+
- type: contains-json
|
|
74
|
+
- type: javascript
|
|
75
|
+
value: output.statsWith('Bonjour')
|
|
76
|
+
- vars:
|
|
77
|
+
language: German
|
|
78
|
+
input: How's it going?
|
|
79
|
+
- type: similar
|
|
80
|
+
value: was geht
|
|
81
|
+
threshold: 0.6 # cosine similarity
|
|
94
82
|
- type: llm-rubric
|
|
95
|
-
value:
|
|
83
|
+
value: does not describe self as an AI, model, or chatbot
|
|
96
84
|
```
|
|
97
85
|
|
|
98
|
-
###
|
|
86
|
+
### Supported assertion types
|
|
87
|
+
|
|
88
|
+
See [Test assertions](https://promptfoo.dev/docs/configuration/expected-outputs) for full details.
|
|
89
|
+
|
|
90
|
+
| Assertion Type | Returns true if... |
|
|
91
|
+
| --------------- | ------------------------------------------------------------------------- |
|
|
92
|
+
| `equals` | output matches exactly |
|
|
93
|
+
| `contains` | output contains substring |
|
|
94
|
+
| `icontains` | output contains substring, case insensitive |
|
|
95
|
+
| `regex` | output matches regex |
|
|
96
|
+
| `contains-some` | output contains some in list of substrings |
|
|
97
|
+
| `contains-all` | output contains all list of substrings |
|
|
98
|
+
| `is-json` | output is valid json |
|
|
99
|
+
| `contains-json` | output contains valid json |
|
|
100
|
+
| `javascript` | provided Javascript function validates the output |
|
|
101
|
+
| `webhook` | provided webhook returns `{pass: true}` |
|
|
102
|
+
| `similar` | embeddings and cosine similarity are above a threshold |
|
|
103
|
+
| `llm-rubric` | LLM output matches a given rubric, using a Language Model to grade output |
|
|
104
|
+
| `rouge-n` | Rouge-N score is above a given threshold |
|
|
105
|
+
|
|
106
|
+
Every test type can be negated by prepending `not-`. For example, `not-equals` or `not-regex`.
|
|
107
|
+
|
|
108
|
+
### Tests from spreadsheet
|
|
99
109
|
|
|
100
110
|
Some people prefer to configure their LLM tests in a CSV. In that case, the config is pretty simple:
|
|
101
111
|
|
|
@@ -190,7 +200,7 @@ You can also use `promptfoo` as a library in your project by importing the `eval
|
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
interface Assertion {
|
|
193
|
-
type:
|
|
203
|
+
type: string;
|
|
194
204
|
value?: string;
|
|
195
205
|
threshold?: number; // For similarity assertions
|
|
196
206
|
provider?: ApiProvider; // For assertions that require an LLM provider
|
package/dist/assertions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Assertion, GradingConfig, GradingResult, AtomicTestCase } from './types
|
|
1
|
+
import type { Assertion, GradingConfig, GradingResult, AtomicTestCase } from './types';
|
|
2
2
|
export declare function runAssertions(test: AtomicTestCase, output: string): Promise<GradingResult>;
|
|
3
3
|
export declare function runAssertion(assertion: Assertion, test: AtomicTestCase, output: string): Promise<GradingResult>;
|
|
4
|
-
export declare function matchesSimilarity(expected: string, output: string, threshold: number): Promise<GradingResult>;
|
|
4
|
+
export declare function matchesSimilarity(expected: string, output: string, threshold: number, inverse?: boolean): Promise<GradingResult>;
|
|
5
5
|
export declare function matchesLlmRubric(expected: string, output: string, options?: GradingConfig): Promise<GradingResult>;
|
|
6
6
|
export declare function assertionFromString(expected: string): Assertion;
|
|
7
7
|
declare const _default: {
|
package/dist/assertions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,SAAS,EAET,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAC;AA+BjB,wBAAsB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAyBhG;AAED,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,CA6MxB;AAoBD,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,OAAe,GACvB,OAAO,CAAC,aAAa,CAAC,CA6CxB;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,aAAa,CAAC,CAgDxB;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CA+D/D;;;;;AAED,wBAGE"}
|
package/dist/assertions.js
CHANGED
|
@@ -4,14 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.assertionFromString = exports.matchesLlmRubric = exports.matchesSimilarity = exports.runAssertion = exports.runAssertions = void 0;
|
|
7
|
+
const rouge_1 = __importDefault(require("rouge"));
|
|
7
8
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
8
9
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
10
|
+
const openai_1 = require("./providers/openai");
|
|
11
|
+
const util_1 = require("./util");
|
|
12
|
+
const providers_1 = require("./providers");
|
|
13
|
+
const prompts_1 = require("./prompts");
|
|
13
14
|
const SIMILAR_REGEX = /similar(?::|\((\d+(\.\d+)?)\):)/;
|
|
14
15
|
const DEFAULT_SEMANTIC_SIMILARITY_THRESHOLD = 0.8;
|
|
16
|
+
function handleRougeScore(baseType, assertion, expected, output, inverted) {
|
|
17
|
+
const fnName = baseType[baseType.length - 1];
|
|
18
|
+
const rougeMethod = rouge_1.default[fnName];
|
|
19
|
+
const score = rougeMethod(output, expected);
|
|
20
|
+
console.log(output, expected, score);
|
|
21
|
+
const pass = score >= (assertion.threshold || 0.75) != inverted;
|
|
22
|
+
return {
|
|
23
|
+
pass,
|
|
24
|
+
reason: pass
|
|
25
|
+
? `${baseType.toUpperCase()} score ${score} is greater than or equal to threshold ${assertion.threshold || 0.75}`
|
|
26
|
+
: `${baseType.toUpperCase()} score ${score} is less than threshold ${assertion.threshold || 0.75}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
async function runAssertions(test, output) {
|
|
16
30
|
const tokensUsed = {
|
|
17
31
|
total: 0,
|
|
@@ -37,56 +51,159 @@ async function runAssertions(test, output) {
|
|
|
37
51
|
exports.runAssertions = runAssertions;
|
|
38
52
|
async function runAssertion(assertion, test, output) {
|
|
39
53
|
let pass = false;
|
|
40
|
-
|
|
54
|
+
(0, tiny_invariant_1.default)(assertion.type, `Assertion must have a type: ${JSON.stringify(assertion)}`);
|
|
55
|
+
const inverse = assertion.type.startsWith('not-');
|
|
56
|
+
const baseType = inverse ? assertion.type.slice(4) : assertion.type;
|
|
57
|
+
if (baseType === 'equals') {
|
|
41
58
|
pass = assertion.value === output;
|
|
42
59
|
return {
|
|
43
60
|
pass,
|
|
44
61
|
reason: pass ? 'Assertion passed' : `Expected output "${assertion.value}"`,
|
|
45
62
|
};
|
|
46
63
|
}
|
|
47
|
-
if (
|
|
64
|
+
if (baseType === 'is-json') {
|
|
48
65
|
try {
|
|
49
66
|
JSON.parse(output);
|
|
50
|
-
|
|
67
|
+
pass = !inverse;
|
|
51
68
|
}
|
|
52
69
|
catch (err) {
|
|
53
|
-
|
|
54
|
-
pass: false,
|
|
55
|
-
reason: `Expected output to be valid JSON, but it isn't.\nError: ${err}`,
|
|
56
|
-
};
|
|
70
|
+
pass = inverse;
|
|
57
71
|
}
|
|
72
|
+
return { pass, reason: pass ? 'Assertion passed' : 'Expected output to be valid JSON' };
|
|
73
|
+
}
|
|
74
|
+
if (baseType === 'contains') {
|
|
75
|
+
(0, tiny_invariant_1.default)(assertion.value, '"contains" assertion type must have a string value');
|
|
76
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"contains" assertion type must have a string value');
|
|
77
|
+
pass = output.includes(assertion.value) !== inverse;
|
|
78
|
+
return {
|
|
79
|
+
pass,
|
|
80
|
+
reason: pass
|
|
81
|
+
? 'Assertion passed'
|
|
82
|
+
: `Expected output to ${inverse ? 'not ' : ''}contain "${assertion.value}"`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (baseType === 'contains-any') {
|
|
86
|
+
(0, tiny_invariant_1.default)(assertion.value, '"contains-any" assertion type must have a value');
|
|
87
|
+
(0, tiny_invariant_1.default)(Array.isArray(assertion.value), '"contains-any" assertion type must have an array value');
|
|
88
|
+
pass = assertion.value.some((value) => output.includes(value)) !== inverse;
|
|
89
|
+
return {
|
|
90
|
+
pass,
|
|
91
|
+
reason: pass
|
|
92
|
+
? 'Assertion passed'
|
|
93
|
+
: `Expected output to ${inverse ? 'not ' : ''}contain one of "${assertion.value.join(', ')}"`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (baseType === 'contains-all') {
|
|
97
|
+
(0, tiny_invariant_1.default)(assertion.value, '"contains-all" assertion type must have a value');
|
|
98
|
+
(0, tiny_invariant_1.default)(Array.isArray(assertion.value), '"contains-all" assertion type must have an array value');
|
|
99
|
+
pass = assertion.value.every((value) => output.includes(value)) !== inverse;
|
|
100
|
+
return {
|
|
101
|
+
pass,
|
|
102
|
+
reason: pass
|
|
103
|
+
? 'Assertion passed'
|
|
104
|
+
: `Expected output to ${inverse ? 'not ' : ''}contain all of "${assertion.value.join(', ')}"`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (baseType === 'regex') {
|
|
108
|
+
(0, tiny_invariant_1.default)(assertion.value, '"regex" assertion type must have a string value');
|
|
109
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"contains" assertion type must have a string value');
|
|
110
|
+
const regex = new RegExp(assertion.value);
|
|
111
|
+
pass = regex.test(output) !== inverse;
|
|
112
|
+
return {
|
|
113
|
+
pass,
|
|
114
|
+
reason: pass
|
|
115
|
+
? 'Assertion passed'
|
|
116
|
+
: `Expected output to ${inverse ? 'not ' : ''}match regex "${assertion.value}"`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (baseType === 'icontains') {
|
|
120
|
+
(0, tiny_invariant_1.default)(assertion.value, '"icontains" assertion type must have a string value');
|
|
121
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"icontains" assertion type must have a string value');
|
|
122
|
+
pass = output.toLowerCase().includes(assertion.value.toLowerCase()) !== inverse;
|
|
123
|
+
return {
|
|
124
|
+
pass,
|
|
125
|
+
reason: pass
|
|
126
|
+
? 'Assertion passed'
|
|
127
|
+
: `Expected output to ${inverse ? 'not ' : ''}contain "${assertion.value}"`,
|
|
128
|
+
};
|
|
58
129
|
}
|
|
59
|
-
if (
|
|
60
|
-
|
|
130
|
+
if (baseType === 'contains-json') {
|
|
131
|
+
pass = containsJSON(output) !== inverse;
|
|
61
132
|
return {
|
|
62
133
|
pass,
|
|
63
|
-
reason: pass
|
|
134
|
+
reason: pass
|
|
135
|
+
? 'Assertion passed'
|
|
136
|
+
: `Expected output to ${inverse ? 'not ' : ''}contain valid JSON`,
|
|
64
137
|
};
|
|
65
138
|
}
|
|
66
|
-
if (
|
|
139
|
+
if (baseType === 'javascript') {
|
|
67
140
|
try {
|
|
68
|
-
const customFunction = new Function('output', `return ${assertion.value}`);
|
|
69
|
-
|
|
141
|
+
const customFunction = new Function('output', 'context', `return ${assertion.value}`);
|
|
142
|
+
const context = {
|
|
143
|
+
vars: test.vars || {},
|
|
144
|
+
};
|
|
145
|
+
pass = customFunction(output, context) !== inverse;
|
|
70
146
|
}
|
|
71
147
|
catch (err) {
|
|
72
148
|
return {
|
|
73
149
|
pass: false,
|
|
74
|
-
reason: `Custom function threw error: ${err.message}
|
|
150
|
+
reason: `Custom function threw error: ${err.message}
|
|
151
|
+
${assertion.value}`,
|
|
75
152
|
};
|
|
76
153
|
}
|
|
77
154
|
return {
|
|
78
155
|
pass,
|
|
79
|
-
reason: pass
|
|
156
|
+
reason: pass
|
|
157
|
+
? 'Assertion passed'
|
|
158
|
+
: `Custom function returned ${inverse ? 'true' : 'false'}
|
|
159
|
+
${assertion.value}`,
|
|
80
160
|
};
|
|
81
161
|
}
|
|
82
|
-
if (
|
|
162
|
+
if (baseType === 'similar') {
|
|
83
163
|
(0, tiny_invariant_1.default)(assertion.value, 'Similarity assertion must have a string value');
|
|
84
|
-
|
|
164
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"contains" assertion type must have a string value');
|
|
165
|
+
return matchesSimilarity(assertion.value, output, assertion.threshold || 0.75, inverse);
|
|
85
166
|
}
|
|
86
|
-
if (
|
|
167
|
+
if (baseType === 'llm-rubric') {
|
|
87
168
|
(0, tiny_invariant_1.default)(assertion.value, 'Similarity assertion must have a string value');
|
|
169
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"contains" assertion type must have a string value');
|
|
88
170
|
return matchesLlmRubric(assertion.value, output, test.options);
|
|
89
171
|
}
|
|
172
|
+
if (baseType === 'webhook') {
|
|
173
|
+
(0, tiny_invariant_1.default)(assertion.value, '"webhook" assertion type must have a URL value');
|
|
174
|
+
(0, tiny_invariant_1.default)(typeof assertion.value === 'string', '"webhook" assertion type must have a URL value');
|
|
175
|
+
try {
|
|
176
|
+
const context = {
|
|
177
|
+
vars: test.vars || {},
|
|
178
|
+
};
|
|
179
|
+
const response = await (0, util_1.fetchWithTimeout)(assertion.value, {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: {
|
|
182
|
+
'Content-Type': 'application/json',
|
|
183
|
+
},
|
|
184
|
+
body: JSON.stringify({ output, context }),
|
|
185
|
+
}, process.env.WEBHOOK_TIMEOUT ? parseInt(process.env.WEBHOOK_TIMEOUT, 10) : 5000);
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
throw new Error(`Webhook response status: ${response.status}`);
|
|
188
|
+
}
|
|
189
|
+
const jsonResponse = await response.json();
|
|
190
|
+
pass = jsonResponse.pass !== inverse;
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
return {
|
|
194
|
+
pass: false,
|
|
195
|
+
reason: `Webhook error: ${err.message}`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
pass,
|
|
200
|
+
reason: pass ? 'Assertion passed' : `Webhook returned ${inverse ? 'true' : 'false'}`,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (baseType === 'rouge-n') {
|
|
204
|
+
(0, tiny_invariant_1.default)(assertion.value, '"rouge" assertion type must a value (string or string array)');
|
|
205
|
+
return handleRougeScore(baseType, assertion, assertion.value, output, inverse);
|
|
206
|
+
}
|
|
90
207
|
throw new Error('Unknown assertion type: ' + assertion.type);
|
|
91
208
|
}
|
|
92
209
|
exports.runAssertion = runAssertion;
|
|
@@ -105,9 +222,9 @@ function containsJSON(str) {
|
|
|
105
222
|
return false;
|
|
106
223
|
}
|
|
107
224
|
}
|
|
108
|
-
async function matchesSimilarity(expected, output, threshold) {
|
|
109
|
-
const expectedEmbedding = await
|
|
110
|
-
const outputEmbedding = await
|
|
225
|
+
async function matchesSimilarity(expected, output, threshold, inverse = false) {
|
|
226
|
+
const expectedEmbedding = await openai_1.DefaultEmbeddingProvider.callEmbeddingApi(expected);
|
|
227
|
+
const outputEmbedding = await openai_1.DefaultEmbeddingProvider.callEmbeddingApi(output);
|
|
111
228
|
const tokensUsed = {
|
|
112
229
|
total: (expectedEmbedding.tokenUsage?.total || 0) + (outputEmbedding.tokenUsage?.total || 0),
|
|
113
230
|
prompt: (expectedEmbedding.tokenUsage?.prompt || 0) + (outputEmbedding.tokenUsage?.prompt || 0),
|
|
@@ -128,17 +245,20 @@ async function matchesSimilarity(expected, output, threshold) {
|
|
|
128
245
|
tokensUsed,
|
|
129
246
|
};
|
|
130
247
|
}
|
|
131
|
-
const similarity = (0,
|
|
132
|
-
|
|
248
|
+
const similarity = (0, util_1.cosineSimilarity)(expectedEmbedding.embedding, outputEmbedding.embedding);
|
|
249
|
+
const pass = inverse ? similarity <= threshold : similarity >= threshold;
|
|
250
|
+
const greaterThanReason = `Similarity ${similarity} is greater than threshold ${threshold}`;
|
|
251
|
+
const lessThanReason = `Similarity ${similarity} is less than threshold ${threshold}`;
|
|
252
|
+
if (pass) {
|
|
133
253
|
return {
|
|
134
|
-
pass:
|
|
135
|
-
reason:
|
|
254
|
+
pass: true,
|
|
255
|
+
reason: inverse ? lessThanReason : greaterThanReason,
|
|
136
256
|
tokensUsed,
|
|
137
257
|
};
|
|
138
258
|
}
|
|
139
259
|
return {
|
|
140
|
-
pass:
|
|
141
|
-
reason:
|
|
260
|
+
pass: false,
|
|
261
|
+
reason: inverse ? greaterThanReason : lessThanReason,
|
|
142
262
|
tokensUsed,
|
|
143
263
|
};
|
|
144
264
|
}
|
|
@@ -147,13 +267,13 @@ async function matchesLlmRubric(expected, output, options) {
|
|
|
147
267
|
if (!options) {
|
|
148
268
|
throw new Error('Cannot grade output without grading config. Specify --grader option or grading config.');
|
|
149
269
|
}
|
|
150
|
-
const prompt = nunjucks_1.default.renderString(options.rubricPrompt ||
|
|
270
|
+
const prompt = nunjucks_1.default.renderString(options.rubricPrompt || prompts_1.DEFAULT_GRADING_PROMPT, {
|
|
151
271
|
content: output,
|
|
152
272
|
rubric: expected,
|
|
153
273
|
});
|
|
154
|
-
let provider = options.provider ||
|
|
274
|
+
let provider = options.provider || openai_1.DefaultGradingProvider;
|
|
155
275
|
if (typeof provider === 'string') {
|
|
156
|
-
provider = await (0,
|
|
276
|
+
provider = await (0, providers_1.loadApiProvider)(provider);
|
|
157
277
|
}
|
|
158
278
|
const resp = await provider.callApi(prompt);
|
|
159
279
|
if (resp.error || !resp.output) {
|
|
@@ -190,16 +310,7 @@ async function matchesLlmRubric(expected, output, options) {
|
|
|
190
310
|
}
|
|
191
311
|
exports.matchesLlmRubric = matchesLlmRubric;
|
|
192
312
|
function assertionFromString(expected) {
|
|
193
|
-
|
|
194
|
-
if (match) {
|
|
195
|
-
const threshold = parseFloat(match[1]) || DEFAULT_SEMANTIC_SIMILARITY_THRESHOLD;
|
|
196
|
-
const rest = expected.replace(SIMILAR_REGEX, '').trim();
|
|
197
|
-
return {
|
|
198
|
-
type: 'similar',
|
|
199
|
-
value: rest,
|
|
200
|
-
threshold,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
313
|
+
// Legacy options
|
|
203
314
|
if (expected.startsWith('fn:') || expected.startsWith('eval:')) {
|
|
204
315
|
// TODO(1.0): delete eval: legacy option
|
|
205
316
|
const sliceLength = expected.startsWith('fn:') ? 'fn:'.length : 'eval:'.length;
|
|
@@ -215,11 +326,42 @@ function assertionFromString(expected) {
|
|
|
215
326
|
value: expected.slice(6),
|
|
216
327
|
};
|
|
217
328
|
}
|
|
329
|
+
// New options
|
|
330
|
+
const assertionRegex = /^(not-)?(equals|contains|contains-any|contains-all|regex|icontains):(.+)$/;
|
|
331
|
+
const regexMatch = expected.match(assertionRegex);
|
|
332
|
+
if (regexMatch) {
|
|
333
|
+
const [_, notPrefix, type, value] = regexMatch;
|
|
334
|
+
const fullType = notPrefix ? `not-${type}` : type;
|
|
335
|
+
if (type === 'contains-any' || type === 'contains-all') {
|
|
336
|
+
return {
|
|
337
|
+
type: fullType,
|
|
338
|
+
value: value.split(',').map((s) => s.trim()),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
return {
|
|
343
|
+
type: fullType,
|
|
344
|
+
value,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// Options that require some special handling
|
|
349
|
+
const match = expected.match(SIMILAR_REGEX);
|
|
350
|
+
if (match) {
|
|
351
|
+
const threshold = parseFloat(match[1]) || DEFAULT_SEMANTIC_SIMILARITY_THRESHOLD;
|
|
352
|
+
const rest = expected.replace(SIMILAR_REGEX, '').trim();
|
|
353
|
+
return {
|
|
354
|
+
type: 'similar',
|
|
355
|
+
value: rest,
|
|
356
|
+
threshold,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
218
359
|
if (expected === 'is-json' || expected === 'contains-json') {
|
|
219
360
|
return {
|
|
220
361
|
type: expected,
|
|
221
362
|
};
|
|
222
363
|
}
|
|
364
|
+
// Default to equality
|
|
223
365
|
return {
|
|
224
366
|
type: 'equals',
|
|
225
367
|
value: expected,
|
package/dist/assertions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAuC;AACvC,wDAAgC;AAEhC,qDAAyF;AACzF,uCAA6C;AAC7C,iDAAiD;AACjD,6CAAsD;AAItD,MAAM,aAAa,GAAG,iCAAiC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AAI,EAAE,CAAC;aAC7C,CAAC;SACH;aAAM;YACL,OAAO;gBACL,IAAI,EAAE,QAAyB;gBAC/B,KAAK;aACN,CAAC;SACH;KACF;IAED,6CAA6C;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC5C,IAAI,KAAK,EAAE;QACT,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,qCAAqC,CAAC;QAChF,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,OAAO;YACL,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,IAAI;YACX,SAAS;SACV,CAAC;KACH;IAED,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,eAAe,EAAE;QAC1D,OAAO;YACL,IAAI,EAAE,QAAQ;SACf,CAAC;KACH;IAED,sBAAsB;IACtB,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;KAChB,CAAC;AACJ,CAAC;AA/DD,kDA+DC;AAED,kBAAe;IACb,iBAAiB;IACjB,gBAAgB;CACjB,CAAC"}
|
package/dist/cache.js
CHANGED
|
@@ -8,8 +8,8 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const cache_manager_1 = __importDefault(require("cache-manager"));
|
|
10
10
|
const cache_manager_fs_hash_1 = __importDefault(require("cache-manager-fs-hash"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
12
|
+
const util_1 = require("./util");
|
|
13
13
|
let cacheInstance;
|
|
14
14
|
let enabled = typeof process.env.PROMPTFOO_CACHE_ENABLED === 'undefined'
|
|
15
15
|
? true
|
|
@@ -17,9 +17,9 @@ let enabled = typeof process.env.PROMPTFOO_CACHE_ENABLED === 'undefined'
|
|
|
17
17
|
const cacheType = process.env.PROMPTFOO_CACHE_TYPE || (process.env.NODE_ENV === 'test' ? 'memory' : 'disk');
|
|
18
18
|
function getCache() {
|
|
19
19
|
if (!cacheInstance) {
|
|
20
|
-
const cachePath = process.env.PROMPTFOO_CACHE_PATH || node_path_1.default.join((0,
|
|
20
|
+
const cachePath = process.env.PROMPTFOO_CACHE_PATH || node_path_1.default.join((0, util_1.getConfigDirectoryPath)(), 'cache');
|
|
21
21
|
if (!node_fs_1.default.existsSync(cachePath)) {
|
|
22
|
-
|
|
22
|
+
logger_1.default.info(`Creating cache folder at ${cachePath}.`);
|
|
23
23
|
node_fs_1.default.mkdirSync(cachePath, { recursive: true });
|
|
24
24
|
}
|
|
25
25
|
cacheInstance = cache_manager_1.default.caching({
|
|
@@ -37,7 +37,7 @@ function getCache() {
|
|
|
37
37
|
}
|
|
38
38
|
async function fetchJsonWithCache(url, options = {}, timeout) {
|
|
39
39
|
if (!enabled) {
|
|
40
|
-
const resp = await (0,
|
|
40
|
+
const resp = await (0, util_1.fetchWithTimeout)(url, options, timeout);
|
|
41
41
|
return {
|
|
42
42
|
cached: false,
|
|
43
43
|
data: await resp.json(),
|
|
@@ -50,18 +50,18 @@ async function fetchJsonWithCache(url, options = {}, timeout) {
|
|
|
50
50
|
// Try to get the cached response
|
|
51
51
|
const cachedResponse = await cache.get(cacheKey);
|
|
52
52
|
if (cachedResponse) {
|
|
53
|
-
|
|
53
|
+
logger_1.default.debug(`Returning cached response for ${url}: ${cachedResponse}`);
|
|
54
54
|
return {
|
|
55
55
|
cached: true,
|
|
56
56
|
data: JSON.parse(cachedResponse),
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
// Fetch the actual data and store it in the cache
|
|
60
|
-
const response = await (0,
|
|
60
|
+
const response = await (0, util_1.fetchWithTimeout)(url, options, timeout);
|
|
61
61
|
try {
|
|
62
62
|
const data = await response.json();
|
|
63
63
|
if (response.ok) {
|
|
64
|
-
|
|
64
|
+
logger_1.default.debug(`Storing ${url} response in cache: ${data}`);
|
|
65
65
|
await cache.set(cacheKey, JSON.stringify(data));
|
|
66
66
|
}
|
|
67
67
|
return {
|
|
@@ -79,7 +79,7 @@ function enableCache() {
|
|
|
79
79
|
}
|
|
80
80
|
exports.enableCache = enableCache;
|
|
81
81
|
function disableCache() {
|
|
82
|
-
|
|
82
|
+
logger_1.default.info('Cache is disabled.');
|
|
83
83
|
enabled = false;
|
|
84
84
|
}
|
|
85
85
|
exports.disableCache = disableCache;
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,kEAAyC;AACzC,kFAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,kEAAyC;AACzC,kFAA4C;AAE5C,sDAA8B;AAC9B,iCAAkE;AAKlE,IAAI,aAAgC,CAAC;AAErC,IAAI,OAAO,GACT,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,WAAW;IACxD,CAAC,CAAC,IAAI;IACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAEnD,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5F,SAAS,QAAQ;IACf,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,mBAAI,CAAC,IAAI,CAAC,IAAA,6BAAsB,GAAE,EAAE,OAAO,CAAC,CAAC;QAC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aluateOptions, EvaluateSummary, TestSuite } from './types';
|
|
2
2
|
export declare function evaluate(testSuite: TestSuite, options: EvaluateOptions): Promise<EvaluateSummary>;
|
|
3
3
|
//# sourceMappingURL=evaluator.d.ts.map
|
package/dist/evaluator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,eAAe,EAGf,eAAe,EAEf,SAAS,EAIV,MAAM,
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,eAAe,EAGf,eAAe,EAEf,SAAS,EAIV,MAAM,SAAS,CAAC;AA6VjB,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,4BAGtE"}
|