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
1 change: 1 addition & 0 deletions apps/dbagent/.env.eval.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ GOOGLE_GENERATIVE_AI_API_KEY=
# Eval variables
JUDGE_MODEL="openai:gpt-4o"
CHAT_MODEL="anthropic:claude-3-5-haiku"
EVAL_FOLDER="/my/folder"
2 changes: 1 addition & 1 deletion apps/dbagent/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ANTHROPIC_API_KEY=
GOOGLE_GENERATIVE_AI_API_KEY=

EVAL=true

EVAL_FOLDER="/my/folder"
18 changes: 14 additions & 4 deletions apps/dbagent/src/app/api/evals/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,31 @@ export async function GET(request: NextRequest) {
if (env.EVAL !== 'true') {
throw new Error('EVAL environment variable must be set to 1');
}
if (!env.EVAL_FOLDER) {
throw new Error('EVAL_FOLDER environment variable must be set');
}
const searchParams = request.nextUrl.searchParams;

const folderParam = z.string().min(1).safeParse(searchParams.get('folder'));
const folderParam = z
.string()
.min(1)
.refine((val) => !val.includes('/') && !val.includes('\\'), {
message: 'Folder cannot contain path separators'
})
.safeParse(searchParams.get('folder'));

if (!folderParam.success) {
return Response.json({ error: 'Invalid folder parameter' }, { status: 400 });
return Response.json({ error: `Invalid folder parameter: ${folderParam.error.message}` }, { status: 400 });
}

const folderPath = folderParam.data;
const absFolderPath = path.join(env.EVAL_FOLDER, folderPath);

const files = await fs.readdir(folderPath);
const files = await fs.readdir(absFolderPath);

const filesWithContents = await Promise.all(
files.map(async (file) => {
const filePath = path.join(folderPath, file);
const filePath = path.join(absFolderPath, file);
const contents = await fs.readFile(filePath, 'utf-8');
return {
fileName: path.basename(file),
Expand Down
9 changes: 7 additions & 2 deletions apps/dbagent/src/evals/lib/test-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { ExpectStatic } from 'vitest';

/* eslint no-process-env: 0 */

if (!process.env.EVAL_FOLDER) {
throw new Error('Expected process.env.EVAL_FOLDER to be defined');
}
const EVAL_FOLDER = process.env.EVAL_FOLDER;

export const getEvalId = (expect: ExpectStatic) => {
const testName = expect.getState().currentTestName;
return testNameToEvalId(testName);
Expand All @@ -17,7 +22,7 @@ export const getTestRunId = () => {
};

export const ensureTraceFolderExists = (evalId: string) => {
const traceFolder = path.join('/tmp/dbagenteval', getTestRunId(), evalId);
const traceFolder = path.join(EVAL_FOLDER, getTestRunId(), evalId);
fs.mkdirSync(traceFolder, { recursive: true });
return traceFolder;
};
Expand All @@ -28,7 +33,7 @@ export const ensureTraceFolderExistsExpect = (expect: ExpectStatic) => {
};

export const ensureTestRunTraceFolderExists = () => {
const traceFolder = path.join('/tmp/dbagenteval', getTestRunId());
const traceFolder = path.join(EVAL_FOLDER, getTestRunId());
fs.mkdirSync(traceFolder, { recursive: true });
return traceFolder;
};
Expand Down
3 changes: 2 additions & 1 deletion apps/dbagent/src/lib/env/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const schema = z.object({
MAX_PARALLEL_RUNS: z.number().default(20), // How many schedules can be run in parallel
TIMEOUT_FOR_RUNNING_SCHEDULE_SECS: z.number().default(15 * 60), // How long to wait before assuming it's dead and restart

EVAL: z.string(z.enum(['true', 'false'])).default('false')
EVAL: z.string(z.enum(['true', 'false'])).default('false'),
EVAL_FOLDER: z.string().optional()
});

const serverEnv = schema.parse(process.env);
Expand Down
Loading