MCPcopy
hub / github.com/promptfoo/promptfoo / create

Method create

test/factories/evalFactory.ts:20–92  ·  view source on GitHub ↗
(options?: CreateEvalOptions)

Source from the content-addressed store, hash-verified

18
19export default class EvalFactory {
20 static async create(options?: CreateEvalOptions) {
21 const eval_ = await Eval.create(
22 {
23 providers: [{ id: 'test-provider' }],
24 prompts: ['What is the capital of {{state}}?'],
25 tests: [
26 { vars: { state: 'colorado' }, assert: [{ type: 'contains', value: 'Denver' }] },
27 { vars: { state: 'california' }, assert: [{ type: 'contains', value: 'Sacramento' }] },
28 ],
29 },
30 [
31 { raw: 'What is the capital of california?', label: 'What is the capital of {{state}}?' },
32 { raw: 'What is the capital of colorado?', label: 'What is the capital of {{state}}?' },
33 ],
34 { id: randomUUID() },
35 );
36 await eval_.addPrompts([
37 {
38 raw: 'What is the capital of california?',
39 label: 'What is the capital of {{state}}?',
40 provider: 'test-provider',
41 metrics: {
42 score: 1,
43 testPassCount: 1,
44 testFailCount: 1,
45 testErrorCount: 0,
46 assertPassCount: 1,
47 assertFailCount: 1,
48 totalLatencyMs: 200,
49 tokenUsage: { total: 20, prompt: 10, completion: 10, cached: 0 },
50 namedScores: {},
51 namedScoresCount: {},
52 redteam: {
53 pluginPassCount: {},
54 pluginFailCount: {},
55 strategyPassCount: {},
56 strategyFailCount: {},
57 },
58 cost: 0.007,
59 },
60 },
61 ]);
62
63 // If no options are provided, create the default test results
64 if (!options || options.numResults === undefined) {
65 await this.addDefaultResults(eval_);
66 return eval_;
67 }
68
69 // Generate the specified number of test results with the requested characteristics
70 const numResults = options.numResults === 0 ? 0 : options.numResults || 2;
71 const resultTypes = options.resultTypes || ['success'];
72 const withHighlights = options.withHighlights || false;
73 const withNamedScores = options.withNamedScores || false;
74 const searchableContent = options.searchableContent || '';
75
76 for (let i = 0; i < numResults; i++) {
77 // Cycle through the result types

Callers 15

registry.test.tsFile · 0.45
moderation.test.tsFile · 0.45
messages.test.tsFile · 0.45
aws.test.tsFile · 0.45
utils.test.tsFile · 0.45
basic.test.tsFile · 0.45
routing.test.tsFile · 0.45

Calls 3

addDefaultResultsMethod · 0.95
addCustomResultMethod · 0.95
addPromptsMethod · 0.80

Tested by 6

runConcurrencyProbeFunction · 0.36
createTestAuditFunction · 0.36
createEvalWithResultsFunction · 0.36
createEvalWithPromptsFunction · 0.36
encodeOTLPRequestFunction · 0.36
encodeOTLPRequestFunction · 0.36