MCPcopy
hub / github.com/promptfoo/promptfoo / evaluateWithSource

Function evaluateWithSource

src/evaluate.ts:317–376  ·  view source on GitHub ↗
(
  testSuite: EvaluateTestSuite,
  options: InternalEvaluateOptions = {},
)

Source from the content-addressed store, hash-verified

315}
316
317export async function evaluateWithSource(
318 testSuite: EvaluateTestSuite,
319 options: InternalEvaluateOptions = {},
320) {
321 const { author: suiteAuthor, ...testSuiteConfig } = testSuite;
322
323 if (testSuiteConfig.writeLatestResults) {
324 await runDbMigrations();
325 }
326
327 const loadedProviders = await loadApiProviders(testSuiteConfig.providers, {
328 env: testSuiteConfig.env,
329 });
330 const providerMap = buildConfiguredProviderMap(loadedProviders);
331 const constructedTestSuite = await createRuntimeTestSuite(testSuiteConfig, loadedProviders);
332 await resolveNestedProviders(testSuiteConfig, constructedTestSuite, providerMap);
333
334 const parsedProviderPromptMap = readProviderPromptMap(
335 testSuiteConfig,
336 constructedTestSuite.prompts,
337 );
338 const unifiedConfig = createSerializableUnifiedConfig(
339 testSuiteConfig,
340 constructedTestSuite.prompts,
341 );
342 const author = getAuthor(suiteAuthor);
343 const evalRecord = testSuiteConfig.writeLatestResults
344 ? await Eval.create(unifiedConfig, constructedTestSuite.prompts, { author })
345 : new Eval(unifiedConfig, { author });
346
347 const ret = await cache.withCacheEnabled(options.cache === false ? false : undefined, () =>
348 doEvaluate(
349 {
350 ...constructedTestSuite,
351 providerPromptMap: parsedProviderPromptMap,
352 },
353 evalRecord,
354 {
355 isRedteam: Boolean(testSuiteConfig.redteam),
356 ...options,
357 },
358 ),
359 );
360
361 await maybeShareEval(testSuiteConfig, ret);
362 if (testSuiteConfig.outputPath) {
363 const outputPaths =
364 typeof testSuiteConfig.outputPath === 'string'
365 ? [testSuiteConfig.outputPath]
366 : testSuiteConfig.outputPath;
367 warnOnDegradedJsonlRecovery(evalRecord, outputPaths);
368 // writeMultipleOutputs maps each path through writeOutput, so it covers the single-path
369 // case too — matching the doEval call site in src/node/doEval.ts.
370 if (outputPaths.length) {
371 await writeMultipleOutputs(outputPaths, evalRecord, null);
372 }
373 }
374

Callers 2

evaluateFunction · 0.90
eval.tsFile · 0.85

Calls 12

runDbMigrationsFunction · 0.90
loadApiProvidersFunction · 0.90
readProviderPromptMapFunction · 0.90
getAuthorFunction · 0.90
createRuntimeTestSuiteFunction · 0.85
resolveNestedProvidersFunction · 0.85
maybeShareEvalFunction · 0.85
writeMultipleOutputsFunction · 0.85
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…