Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
saikatmitra91 committed May 22, 2024
1 parent 0108f4a commit 9ee436a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .changeset/thin-phones-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"empiricalrun": minor
"@empiricalrun/scorer": minor
"@empiricalrun/types": minor
"web": patch
---

feat: add support for js/ts scripts as scorers
1 change: 0 additions & 1 deletion apps/web/components/run-config-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ enum RunConfigTab {
const defaultTabMap: Record<RunConfigType, RunConfigTab> = {
model: RunConfigTab.prompt,
"py-script": RunConfigTab.parameters,
"js-script": RunConfigTab.parameters,
assistant: RunConfigTab.instructions,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/spider-using-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# Ignore outputs from Empirical
.empiricalrun
db
db_files
11 changes: 6 additions & 5 deletions examples/spider-using-ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async function createDatabase(
con: sqlite3.Database,
dbName: string,
): Promise<sqlite3.Database> {
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(() => {
Expand All @@ -32,11 +32,12 @@ export async function getConnection (dbName:string): Promise<sqlite3.Database> {
if (connectionCache.get(dbName)) {
return await connectionCache.get(dbName)!
}
const dbFilesDir = "db_files"
const connectionPromise = new Promise<sqlite3.Database>(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)
Expand Down
2 changes: 1 addition & 1 deletion examples/using-js-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"empiricalrun": "workspace:*"
"empiricalrun": "^0.13.1"
}
}
22 changes: 6 additions & 16 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,17 @@ export interface ScriptScorer extends ScorerBase {
export interface JSScriptScorerParams {
inputs: Record<string, any>;
output: RunOutput;
options?: any;
}

export interface AsyncScoringFn {
export interface JSScriptScorer {
(
args: JSScriptScorerParams,
): Promise<Score[] | (Partial<Score> & { score: number })>;
):
| Score[]
| (Partial<Score> & { score: number })
| Promise<Score[] | (Partial<Score> & { score: number })>;
}

export interface SyncScoringFn {
(args: JSScriptScorerParams): Score[] | (Partial<Score> & { score: number });
}

export type JSScriptScorer = SyncScoringFn | AsyncScoringFn;

export type Scorer = LLMScorer | SyntaxScorer | ScriptScorer | JSScriptScorer;

export type Prompt = string | ChatPrompt[];
Expand Down Expand Up @@ -106,7 +102,7 @@ export interface ModelRunConfig extends RunConfigBase {
| "fireworks"
| "azure-openai";
model: string;
prompt?: Prompt;
prompt: Prompt;
parameters?: ModelParameters;
}

Expand All @@ -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;
Expand All @@ -144,7 +135,6 @@ export interface PyScriptRunConfig extends RunConfigBase {
export type RunConfig =
| ModelRunConfig
| PyScriptRunConfig
| JSScriptRunConfig
| AssistantsRunConfig;

export interface ScoreStats {
Expand Down

0 comments on commit 9ee436a

Please sign in to comment.