Skip to content

Commit

Permalink
Add a manifest of all autoevals in typescript and fix export error (#43)
Browse files Browse the repository at this point in the history
The manifest includes a list of all autoevaluators, that currently must
be kept up-to-date manually.

The export fix clarifies the export as `export type`, because
`index.mjs` from `@braintrust/core` is actually empty.
  • Loading branch information
ankrgyl authored Dec 18, 2023
1 parent 093f5a4 commit 728eb24
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
3 changes: 2 additions & 1 deletion js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* @module autoevals
*/

export { Score, ScorerArgs, Scorer } from "@braintrust/core";
export type { Score, ScorerArgs, Scorer } from "@braintrust/core";
export * from "./llm";
export * from "./string";
export * from "./number";
export * from "./json";
export * from "./templates";
export { Evaluators } from "./manifest";
6 changes: 5 additions & 1 deletion js/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export async function OpenAIClassifier<RenderArgs, Output>(
openAiApiKey,
openAiOrganizationId,
openAiBaseUrl,
openAiDefaultHeaders,
openAiDangerouslyAllowBrowser,
...remaining
} = args;

Expand Down Expand Up @@ -118,7 +120,7 @@ export async function OpenAIClassifier<RenderArgs, Output>(

const messages: ChatCompletionMessageParam[] = messagesArg.map((m) => ({
...m,
content: m.content && mustache.render(m.content as string, renderArgs),
content: m.content ? mustache.render(m.content as string, renderArgs) : "",
}));

try {
Expand All @@ -135,6 +137,8 @@ export async function OpenAIClassifier<RenderArgs, Output>(
openAiApiKey,
openAiOrganizationId,
openAiBaseUrl,
openAiDefaultHeaders,
openAiDangerouslyAllowBrowser,
}
);

Expand Down
43 changes: 43 additions & 0 deletions js/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Scorer } from "@braintrust/core";
import { JSONDiff } from "./json";
import {
Battle,
ClosedQA,
Factuality,
Humor,
Possible,
Security,
Sql,
Summary,
Translation,
} from "./llm";
import { NumericDiff } from "./number";
import { EmbeddingSimilarity, Levenshtein } from "./string";

export const Evaluators: {
label: string;
methods: Scorer<any, any>[];
}[] = [
{
label: "Model-based classification",
methods: [
Battle,
ClosedQA,
Humor,
Factuality,
Possible,
Security,
Sql,
Summary,
Translation,
],
},
{
label: "Embeddings",
methods: [EmbeddingSimilarity],
},
{
label: "Heuristic",
methods: [JSONDiff, Levenshtein, NumericDiff],
},
];
12 changes: 11 additions & 1 deletion js/oai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,27 @@ export interface OpenAIAuth {
openAiApiKey?: string;
openAiOrganizationId?: string;
openAiBaseUrl?: string;
openAiDefaultHeaders?: Record<string, string>;
openAiDangerouslyAllowBrowser?: boolean;
}

const PROXY_URL = "https://braintrustproxy.com/v1";

export function buildOpenAIClient(options: OpenAIAuth): OpenAI {
const { openAiApiKey, openAiOrganizationId, openAiBaseUrl } = options;
const {
openAiApiKey,
openAiOrganizationId,
openAiBaseUrl,
openAiDefaultHeaders,
openAiDangerouslyAllowBrowser,
} = options;

return new OpenAI({
apiKey: openAiApiKey || Env.OPENAI_API_KEY,
organization: openAiOrganizationId,
baseURL: openAiBaseUrl || PROXY_URL,
defaultHeaders: openAiDefaultHeaders,
dangerouslyAllowBrowser: openAiDangerouslyAllowBrowser,
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"js-levenshtein": "^1.1.6",
"js-yaml": "^4.1.0",
"mustache": "^4.2.0",
"openai": "^4.12.1",
"openai": "^4.23.0",
"tsx": "^3.12.7"
}
}

0 comments on commit 728eb24

Please sign in to comment.