From 9ee436a7f38791914df99a557cc5ddb90dd4c457 Mon Sep 17 00:00:00 2001 From: Saikat Mitra Date: Wed, 22 May 2024 15:23:45 +0530 Subject: [PATCH] fix: review comments --- .changeset/thin-phones-destroy.md | 8 ++++++++ apps/web/components/run-config-view.tsx | 1 - examples/spider-using-ts/.gitignore | 2 +- examples/spider-using-ts/db.ts | 11 ++++++----- examples/using-js-config/package.json | 2 +- packages/types/src/index.ts | 22 ++++++---------------- 6 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 .changeset/thin-phones-destroy.md diff --git a/.changeset/thin-phones-destroy.md b/.changeset/thin-phones-destroy.md new file mode 100644 index 00000000..d0cf624c --- /dev/null +++ b/.changeset/thin-phones-destroy.md @@ -0,0 +1,8 @@ +--- +"empiricalrun": minor +"@empiricalrun/scorer": minor +"@empiricalrun/types": minor +"web": patch +--- + +feat: add support for js/ts scripts as scorers diff --git a/apps/web/components/run-config-view.tsx b/apps/web/components/run-config-view.tsx index 9c0aa8d3..fc3725df 100644 --- a/apps/web/components/run-config-view.tsx +++ b/apps/web/components/run-config-view.tsx @@ -16,7 +16,6 @@ enum RunConfigTab { const defaultTabMap: Record = { model: RunConfigTab.prompt, "py-script": RunConfigTab.parameters, - "js-script": RunConfigTab.parameters, assistant: RunConfigTab.instructions, }; diff --git a/examples/spider-using-ts/.gitignore b/examples/spider-using-ts/.gitignore index 0eff3853..4ea01415 100644 --- a/examples/spider-using-ts/.gitignore +++ b/examples/spider-using-ts/.gitignore @@ -1,4 +1,4 @@ # Ignore outputs from Empirical .empiricalrun -db \ No newline at end of file +db_files \ No newline at end of file diff --git a/examples/spider-using-ts/db.ts b/examples/spider-using-ts/db.ts index badb60f8..add0f706 100644 --- a/examples/spider-using-ts/db.ts +++ b/examples/spider-using-ts/db.ts @@ -12,8 +12,8 @@ async function createDatabase( con: sqlite3.Database, dbName: string, ): Promise { - return new Promise((resolve, reject) => { - const schemaScript = loadJson("./schema.json")[dbName]; + return new Promise((resolve) => { + const schemaScript = dbSchemas[dbName]; const createScript = loadJson("./create.json")[dbName]; con.serialize(() => { @@ -32,11 +32,12 @@ export async function getConnection (dbName:string): Promise { if (connectionCache.get(dbName)) { return await connectionCache.get(dbName)! } + const dbFilesDir = "db_files" const connectionPromise = new Promise(async (resolve) => { - if(!fs.existsSync("db")){ - fs.mkdirSync("db"); + if(!fs.existsSync(dbFilesDir)){ + fs.mkdirSync(dbFilesDir); } - const dbfileName = `db/${dbName}.db` + const dbfileName = `${dbFilesDir}/${dbName}.db` const con = new sqlite3.Database(dbfileName); await createDatabase(con, dbName) resolve(con) diff --git a/examples/using-js-config/package.json b/examples/using-js-config/package.json index 7c2be4d2..562b8e02 100644 --- a/examples/using-js-config/package.json +++ b/examples/using-js-config/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "devDependencies": { - "empiricalrun": "workspace:*" + "empiricalrun": "^0.13.1" } } diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 97c56570..0a6e725c 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -41,21 +41,17 @@ export interface ScriptScorer extends ScorerBase { export interface JSScriptScorerParams { inputs: Record; output: RunOutput; - options?: any; } -export interface AsyncScoringFn { +export interface JSScriptScorer { ( args: JSScriptScorerParams, - ): Promise & { score: number })>; + ): + | Score[] + | (Partial & { score: number }) + | Promise & { score: number })>; } -export interface SyncScoringFn { - (args: JSScriptScorerParams): Score[] | (Partial & { score: number }); -} - -export type JSScriptScorer = SyncScoringFn | AsyncScoringFn; - export type Scorer = LLMScorer | SyntaxScorer | ScriptScorer | JSScriptScorer; export type Prompt = string | ChatPrompt[]; @@ -106,7 +102,7 @@ export interface ModelRunConfig extends RunConfigBase { | "fireworks" | "azure-openai"; model: string; - prompt?: Prompt; + prompt: Prompt; parameters?: ModelParameters; } @@ -127,11 +123,6 @@ export interface AssistantsRunConfig extends RunConfigBase { }; } -export interface JSScriptRunConfig extends RunConfigBase { - type: "js-script"; - path: string; -} - export interface PyScriptRunConfig extends RunConfigBase { type: "py-script"; path: string; @@ -144,7 +135,6 @@ export interface PyScriptRunConfig extends RunConfigBase { export type RunConfig = | ModelRunConfig | PyScriptRunConfig - | JSScriptRunConfig | AssistantsRunConfig; export interface ScoreStats {