Skip to content

Commit

Permalink
Update route.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
big-camel committed Jun 5, 2024
1 parent 04f12e4 commit c4ba995
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/web/nextui/src/app/api/eval/job/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import promptfoo from '@/../../../index';
import { IS_RUNNING_LOCALLY, USE_SUPABASE } from '@/constants';
import { createJob, createResult, updateJob } from '@/database';

import type { EvaluateTestSuite } from '@/../../../types';
import type { EvaluateOptions, EvaluateTestSuite } from '@/../../../types';
import evalJobs from './evalJobsStore';

export const dynamic = IS_RUNNING_LOCALLY ? 'auto' : 'force-dynamic';

async function runWithDatabase(testSuite: EvaluateTestSuite) {
interface EvaluateTestSuiteWithEvaluateOptions extends EvaluateTestSuite {
evaluateOptions?: EvaluateOptions
}
async function runWithDatabase(testSuite: EvaluateTestSuiteWithEvaluateOptions) {
const supabase = createRouteHandlerClient({ cookies });

const job = await createJob(supabase);
Expand All @@ -26,6 +28,7 @@ async function runWithDatabase(testSuite: EvaluateTestSuite) {
eventSource: 'webui',
}),
{
...testSuite.evaluateOptions,
progressCallback: (progress, total) => {
updateJob(supabase, job.id, progress, total);
console.log(`[${job.id}] ${progress}/${total}`);
Expand All @@ -41,7 +44,7 @@ async function runWithDatabase(testSuite: EvaluateTestSuite) {
}

export async function POST(req: Request) {
const testSuite = (await req.json()) as EvaluateTestSuite;
const testSuite = (await req.json()) as EvaluateTestSuiteWithEvaluateOptions;
if (IS_RUNNING_LOCALLY) {
throw new Error('This route should only be used in hosted mode');
} else if (USE_SUPABASE) {
Expand All @@ -57,6 +60,7 @@ export async function POST(req: Request) {
sharing: testSuite.sharing ?? true,
}),
{
...testSuite.evaluateOptions,
eventSource: 'web',
progressCallback: (progress, total) => {
const job = evalJobs.get(id);
Expand Down

0 comments on commit c4ba995

Please sign in to comment.