0d3cb498a3
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
135 lines
3.0 KiB
JavaScript
135 lines
3.0 KiB
JavaScript
import fs from 'node:fs';
|
|
|
|
import promptfoo from 'promptfoo';
|
|
|
|
const prompts = [
|
|
// Prompts can be raw text...
|
|
'Write a haiku about: {{body}}',
|
|
|
|
// Or message arrays...
|
|
[
|
|
{
|
|
role: 'system',
|
|
content: 'You are speaking to a time traveler. Begin your conversation.',
|
|
},
|
|
{
|
|
role: 'user',
|
|
content: '{{body}}',
|
|
},
|
|
],
|
|
|
|
// Or files
|
|
'file://prompt.txt',
|
|
|
|
// Or functions
|
|
(vars) => {
|
|
const genres = ['fantasy', 'sci-fi', 'mystery', 'horror'];
|
|
const characters = {
|
|
fantasy: 'wizard',
|
|
'sci-fi': 'alien',
|
|
mystery: 'detective',
|
|
horror: 'ghost',
|
|
};
|
|
const genre = genres[Math.floor(Math.random() * genres.length)];
|
|
const character = characters[genre];
|
|
return [
|
|
{
|
|
role: 'system',
|
|
content: `You have encountered a ${character} in a ${genre} setting. Engage with the character using the knowledge typical for that genre.`,
|
|
},
|
|
{
|
|
role: 'user',
|
|
content: '{{body}}',
|
|
},
|
|
];
|
|
},
|
|
];
|
|
|
|
const customFunction = (prompt, context) => {
|
|
// Call an LLM API in this function, or any other logic.
|
|
console.log(`Prompt: ${prompt}, vars: ${JSON.stringify(context.vars)}`);
|
|
return {
|
|
output: '<LLM output>',
|
|
};
|
|
};
|
|
customFunction.label = 'My custom function';
|
|
|
|
const providers = [
|
|
// Call the OpenAI API GPT 4o Mini
|
|
'openai:gpt-4.1-mini',
|
|
|
|
// Or use a custom function.
|
|
customFunction,
|
|
];
|
|
|
|
const tests = [
|
|
{
|
|
vars: {
|
|
body: 'Hello world',
|
|
},
|
|
},
|
|
{
|
|
vars: {
|
|
body: "I'm hungry",
|
|
},
|
|
assert: [
|
|
{
|
|
type: 'javascript',
|
|
value: (output) => {
|
|
// Logic for checking LLM output goes here...
|
|
const pass = output.includes('foo bar');
|
|
return {
|
|
pass,
|
|
score: pass ? 1.0 : 0.0,
|
|
reason: pass ? 'Output contained substring' : 'Output did not contain substring',
|
|
};
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
vars: {
|
|
body: 'Tell me a joke',
|
|
},
|
|
options: {
|
|
// Transform functions can be passed directly when using the node package.
|
|
transform: (output) => output.toLowerCase(),
|
|
},
|
|
assert: [
|
|
{
|
|
type: 'contains',
|
|
value: 'joke',
|
|
// Per-assertion transforms also accept functions.
|
|
transform: (output) => output.trim(),
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
(async () => {
|
|
const evalRecord = await promptfoo.evaluate({
|
|
prompts,
|
|
providers,
|
|
tests,
|
|
|
|
// Persist results locally so they are visible in the promptfoo viewer
|
|
writeLatestResults: true,
|
|
|
|
// Uncomment to enable sharing (requires cloud account or self-hosted server)
|
|
// sharing: true,
|
|
});
|
|
const results = await evalRecord.toEvaluateSummary();
|
|
|
|
console.log('RESULTS:');
|
|
const resultsString = JSON.stringify(results, null, 2);
|
|
console.log(resultsString);
|
|
|
|
// Display shareable URL if available
|
|
if (results.shareableUrl) {
|
|
console.log('\nView results online:', results.shareableUrl);
|
|
}
|
|
|
|
fs.writeFileSync('output.json', resultsString);
|
|
console.log('Wrote output.json');
|
|
})();
|