Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weights & Biases integration #63

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 123 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"dependencies": {
"@anthropic-ai/sdk": "^0.5.2",
"@apidevtools/json-schema-ref-parser": "^10.1.0",
"@wandb/sdk": "^0.5.1",
"async": "^3.2.4",
"cache-manager": "^4.1.0",
"cache-manager-fs-hash": "^1.0.0",
Expand Down
51 changes: 51 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ async function main() {
'This suffix is append to every prompt',
config.defaultTest?.options?.suffix,
)
.option(
'--wandb-project',
'Enable logging to a Weights & Biases project. The project must already exist in the W&B dashboard.',
config?.commandLineOptions?.wandbProject,
)
.option(
'--wandb-name',
'Enable logging to a Weights & Biases under a run name',
config?.commandLineOptions?.wandbName,
)
.option(
'--no-write',
'Do not write results to promptfoo directory',
Expand Down Expand Up @@ -303,6 +313,27 @@ async function main() {
options.generateSuggestions = true;
}

// Other test setup
let wandb;
if (cmdObj.wandbProject || cmdObj.wandbName) {
if (!process.env.WANDB_API_KEY) {
throw new Error(
'You must set WANDB_API_KEY in your environment to use the --wandb-project or --wandb-name options',
);
}
logger.info('Enabled logging to Weights & Biases');

wandb = (await import('@wandb/sdk')).default;

await wandb.init({
project: cmdObj.wandbProject,
name: cmdObj.wandbName,
config: testSuite,
});
}

// Run it!

const summary = await evaluate(testSuite, options);

const shareableUrl = cmdObj.share ? await createShareableUrl(summary, config) : null;
Expand All @@ -321,6 +352,26 @@ async function main() {
}
}

// Outputs

if (wandb) {
logger.info('Sending everything to Weights & Biases...');

// Record all results
for (const result of summary.results) {
wandb.log({
prompt: result.prompt.raw,
vars: result.vars,
modelOutput: result.response?.output,
modelError: result.response?.error,
modelTokens: result.response?.tokenUsage,
success: result.success,
score: result.score,
});
}
await wandb.finish();
}

telemetry.maybeShowNotice();

const border = '='.repeat(process.stdout.columns - 10);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface CommandLineOptions {
share?: boolean;
progressBar?: boolean;

wandbProject?: string;
wandbName?: string;

generateSuggestions?: boolean;
promptPrefix?: string;
promptSuffix?: string;
Expand Down