Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/evals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Evals
Comment thread
vercel[bot] marked this conversation as resolved.
Resolved

on:
pull_request:
branches: [main, test]

permissions:
contents: read
pull-requests: write

jobs:
evals:
runs-on: ubuntu-latest
timeout-minutes: 11
env:
PRIVY_PROJECT_SECRET: ${{ secrets.PRIVY_PROJECT_SECRET }}
# Note: COMPOSIO_API_KEY intentionally omitted - @composio packages
# are incompatible with Braintrust's bundler (createRequire issue)
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: pnpm install

- name: Run Evals
uses: braintrustdata/eval-action@v1
with:
api_key: ${{ secrets.BRAINTRUST_API_KEY }}
runtime: node
paths: "evals/"
package_manager: pnpm
23 changes: 23 additions & 0 deletions evals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Recoup Evaluation System

This directory contains our **Braintrust-based evaluation framework** for testing and improving our AI systems.

## 🚀 Quick Start

### Prerequisites

- Node.js >= 18
- Braintrust API key in `.env` file: `BRAINTRUST_API_KEY=your_key_here`

### Running Evaluations

```bash
# Run all evaluation scripts
pnpm eval

# Run specific evaluation
pnpm eval evals/first-week-album-sales.eval.ts

# Or use npx directly with external packages flag
npx braintrust eval --external-packages playwright playwright-core chromium-bidi @browserbasehq/stagehand
```
103 changes: 103 additions & 0 deletions evals/catalog-opportunity-analysis.eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Eval } from "braintrust";
import { callChatFunctions } from "@/lib/evals";
import { CatalogAvailability } from "@/lib/evals/scorers/CatalogAvailability";

/**
* Catalog Opportunity Analysis Evaluation
*
* This evaluation tests whether the AI system can effectively analyze catalog opportunities
* and provide relevant song recommendations for specific use cases like playlists, sync opportunities,
* or thematic collections. It focuses on the system's ability to understand context and suggest
* appropriate songs from the catalog.
*
* Run: npx braintrust eval evals/catalog-opportunity-analysis.eval.ts
*/

const expected = `Here are some great Halloween-themed songs perfect for a Peloton Halloween playlist:
- Lord Infamous & II-Tone - "Helloween"
- th1rt3en & Pharoahe Monch – "The Exorcist"
- DC The Don – "Zombieland"
- DC The Don – "Freddy Krueger"

These songs provide the perfect spooky atmosphere while maintaining the high-energy vibe needed for Peloton workouts. The mix includes both classic Halloween hits and darker, more intense tracks that will keep riders motivated during their Halloween-themed rides.`;

Eval("Catalog Opportunity Analysis Evaluation", {
data: () => [
{
input: "Peloton needs songs for a Halloween playlist",
expected,
metadata: {
category: "playlist_recommendation",
use_case: "peloton_halloween",
expected_tool_usage: true,
data_type: "catalog_analysis",
requires_web_search: true,
target_platform: "peloton",
theme: "halloween",
},
},
{
input: "Brands need Christmas Songs for Sync",
expected,
metadata: {
category: "sync_licensing",
use_case: "brand_christmas_sync",
expected_tool_usage: true,
data_type: "catalog_analysis",
requires_web_search: true,
target_platform: "brand_sync",
theme: "christmas",
},
},
{
input: "Spotify needs songs for a LGBTQ+ Valentines Mix",
expected,
metadata: {
category: "playlist_recommendation",
use_case: "spotify_lgbtq_valentines",
expected_tool_usage: true,
data_type: "catalog_analysis",
requires_web_search: true,
target_platform: "spotify",
theme: "lgbtq_valentines",
},
},
{
input: "Spotify needs songs for Black History Month",
expected,
metadata: {
category: "playlist_recommendation",
use_case: "spotify_black_history_month",
expected_tool_usage: true,
data_type: "catalog_analysis",
requires_web_search: true,
target_platform: "spotify",
theme: "black_history_month",
},
},
{
input: "Apple needs songs for International Women's Day",
expected,
metadata: {
category: "playlist_recommendation",
use_case: "apple_international_womens_day",
expected_tool_usage: true,
data_type: "catalog_analysis",
requires_web_search: true,
target_platform: "apple",
theme: "international_womens_day",
},
},
],

task: async (input: string): Promise<string> => {
try {
const response = await callChatFunctions(input);
return response;
} catch (error) {
return `Error: ${error instanceof Error ? error.message : "Function call failed"}`;
}
},

scores: [CatalogAvailability],
});
31 changes: 31 additions & 0 deletions evals/catalog-songs-count.eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Eval } from "braintrust";
import { Factuality, AnswerCorrectness } from "autoevals";
import {
callChatFunctionsWithResult,
extractTextFromResult,
} from "@/lib/evals";
import getCatalogSongsCountData from "@/lib/evals/getCatalogSongsCountData";

/**
* Catalog Songs Count Evaluation
*
* This evaluation tests whether your AI system properly uses tool calls
* to fetch catalog data and return accurate song counts instead of defaulting
* to "I don't have access" responses.
*
* Run: npx braintrust eval evals/catalog-songs-count.eval.ts
*/
Eval("Catalog Songs Count Evaluation", {
data: getCatalogSongsCountData,
task: async (input: string): Promise<string> => {
try {
const response = await callChatFunctionsWithResult(input);
const output = extractTextFromResult(response);
return output;
} catch (error) {
return `Error: ${error instanceof Error ? error.message : "Function call failed"}`;
}
},

scores: [AnswerCorrectness, Factuality],
});
76 changes: 76 additions & 0 deletions evals/first-week-album-sales.eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Eval } from "braintrust";
import { Factuality } from "autoevals";
import { callChatFunctions } from "@/lib/evals";

/**
* Album Sales Tool Call Evaluation
*
* This evaluation tests whether your AI system properly uses tool calls
* to fetch album sales data instead of defaulting to "I don't have access" responses.
*
* Run: npx braintrust eval evals/first-week-album-sales.eval.ts
*/

Eval("First Week Album Sales Evaluation", {
data: () => [
{
input:
"how many albums did Halsey The Great Impersonator sell the first week of release",
expected:
"Halsey's album 'The Great Impersonator' sold between 93,000 and 100,000 copies in its first week of release. It debuted at No. 2 on the Billboard 200 chart.",
metadata: {
artist: "Halsey",
album: "The Great Impersonator",
expected_tool_usage: true,
data_type: "first_week_album_sales",
},
},
{
input:
"what were the first week sales for Taylor Swift's Midnights album?",
expected:
"Taylor Swift's Midnights sold 1.578 million equivalent album units in its first week in the United States, which included between 1 million and 1.5 million pure album sales. This marked the biggest sales week for any album since Adele's 25 in 2015 and the best sales week for a vinyl album in the modern tracking era.",
metadata: {
artist: "Taylor Swift",
album: "Midnights",
expected_tool_usage: true,
data_type: "first_week_album_sales",
},
},
{
input:
"how many copies did Drake's Certified Lover Boy sell in the first week",
expected:
"Drake's 'Certified Lover Boy' sold approximately 613,000 album-equivalent units in its first week, securing the #1 spot on the Billboard 200 chart.",
metadata: {
artist: "Drake",
album: "Certified Lover Boy",
expected_tool_usage: true,
data_type: "first_week_album_sales",
},
},
{
input:
"what are the first week streaming numbers for Bad Bunny's Un Verano Sin Ti",
expected:
"In its first week of release in the United States, Bad Bunny's album Un Verano Sin Ti garnered over 355 million on-demand streams and 274,000 album-equivalent units, the most for any album that year and the largest streaming week for a Latin album ever at that time. The album also set a record for the biggest debut for a Latin album in Spotify's history.",
metadata: {
artist: "Bad Bunny",
album: "Un Verano Sin Ti",
expected_tool_usage: true,
data_type: "first_week_streaming_numbers",
},
},
],

task: async (input: string): Promise<string> => {
try {
const response = await callChatFunctions(input);
return response;
} catch (error) {
return `Error: ${error instanceof Error ? error.message : "Function call failed"}`;
}
},

scores: [Factuality],
});
68 changes: 68 additions & 0 deletions evals/memory-tools.eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Eval } from "braintrust";
import {
callChatFunctionsWithResult,
extractTextFromResult,
createToolsCalledScorer,
} from "@/lib/evals";

/**
* Memory & Storage Tools Evaluation
*
* This evaluation tests whether the AI properly uses memory/storage tools when
* asked to save information. The AI should:
* 1. Use write_file to save to artist's file storage
* 2. Use create_knowledge_base to save to artist's knowledge base
* 3. NOT just use generate_txt_file (which doesn't persist properly)
* 4. Keep saved content concise with high signal, low noise
*
* Test cases:
* - "Can I save all this info somewhere?" - Should use write_file or create_knowledge_base
*
* Required Tools: write_file, create_knowledge_base
* Penalized Tools: generate_txt_file (when used alone without write_file)
*
* Run: npx braintrust eval evals/memory-tools.eval.ts
*/

const REQUIRED_TOOLS = ["write_file", "create_knowledge_base"];

const PENALIZED_TOOLS = ["generate_txt_file"];

Eval("Memory & Storage Tools Evaluation", {
data: () => [
{
input: "Can I save all this info somewhere?",
expected:
"Confirmation that info was saved using write_file or create_knowledge_base (not just generate_txt_file)",
metadata: {
artist: "Unknown",
platform: "n/a",
request_type: "save_information",
expected_tool_usage: true,
requiredTools: REQUIRED_TOOLS,
penalizedTools: PENALIZED_TOOLS,
},
},
],

task: async (input: string) => {
try {
const result = await callChatFunctionsWithResult(input);
const output = extractTextFromResult(result);
const toolCalls =
result.toolCalls?.map((tc) => ({
toolName: tc.toolName,
args: {},
})) || [];

return { output, toolCalls };
} catch (error) {
return {
output: `Error: ${error instanceof Error ? error.message : "Function call failed"}`,
toolCalls: [],
};
}
},

scores: [createToolsCalledScorer(REQUIRED_TOOLS, PENALIZED_TOOLS)],
});
45 changes: 45 additions & 0 deletions evals/monthly-listeners-tracking.eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Eval } from "braintrust";
import { AnswerSimilarity } from "autoevals";
import { callChatFunctions } from "@/lib/evals";
import { EVAL_ARTISTS } from "@/lib/consts";
import { getDynamicDates } from "@/lib/evals/getMonthlyListenersDates";

/**
* Monthly Listeners Tracking Evaluation
*
* This evaluation tests whether Recoup properly sets up monthly listener reporting
* for artists when users request tracking data between specific dates.
*
* Run: npx braintrust eval evals/monthly-listeners-tracking.eval.ts
*/
Eval("Monthly Listeners Tracking Evaluation", {
data: () => {
const { startDateFormatted, endDateFormatted } = getDynamicDates();

const testCases = EVAL_ARTISTS.map((artist) => ({
input: `what is the increase for ${artist} monthlies from ${startDateFormatted} to ${endDateFormatted}`,
expected: `I've set up a monthlies tracking for ${artist}. would you like to receive the updated list in your email?`,
metadata: {
artist,
start_date: startDateFormatted,
end_date: endDateFormatted,
expected_tool_usage: true,
data_type: "monthly_listeners_tracking",
tracking_setup: true,
},
}));

return testCases;
},

task: async (input: string): Promise<string> => {
try {
const response = await callChatFunctions(input);
return response;
} catch (error) {
return `Error: ${error instanceof Error ? error.message : "Function call failed"}`;
}
},

scores: [AnswerSimilarity],
});
Loading