Skip to content

Commit

Permalink
Update bundling to resemble sdk and proxy (#40)
Browse files Browse the repository at this point in the history
Remove `nodenext` and use `tsup` to bundle
  • Loading branch information
ankrgyl authored Dec 16, 2023
1 parent e6b7f70 commit 4693e10
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 96 deletions.
10 changes: 5 additions & 5 deletions js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/

export { Score, ScorerArgs, Scorer } from "@braintrust/core";
export * from "./llm.js";
export * from "./string.js";
export * from "./number.js";
export * from "./json.js";
export * from "./templates.js";
export * from "./llm";
export * from "./string";
export * from "./number";
export * from "./json";
export * from "./templates";
6 changes: 3 additions & 3 deletions js/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as yaml from "js-yaml";
import mustache from "mustache";

import { Score, Scorer, ScorerArgs } from "@braintrust/core";
import { ChatCache, OpenAIAuth, cachedChatCompletion } from "./oai.js";
import { templates } from "./templates.js";
import { ChatCache, OpenAIAuth, cachedChatCompletion } from "./oai";
import { templates } from "./templates";
import {
ChatCompletionCreateParams,
ChatCompletionMessage,
ChatCompletionMessageParam,
} from "openai/resources/index.mjs";
} from "openai/resources";

const NO_COT_SUFFIX =
"Answer the question by calling `select_choice` with a single choice from {{__choices}}.";
Expand Down
6 changes: 3 additions & 3 deletions js/oai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
ChatCompletion,
ChatCompletionCreateParams,
ChatCompletionMessageParam,
} from "openai/resources/index.mjs";
} from "openai/resources";
import { OpenAI } from "openai";

import { Env } from "./env.js";
import { currentSpanTraced, SpanLogFn } from "./util.js";
import { Env } from "./env";
import { currentSpanTraced, SpanLogFn } from "./util";

export interface CachedLLMParams {
model: string;
Expand Down
6 changes: 3 additions & 3 deletions js/string.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Scorer } from "@braintrust/core";
import levenshtein from "js-levenshtein";
import { OpenAIAuth, buildOpenAIClient } from "./oai.js";
import { CreateEmbeddingResponse } from "openai/resources/embeddings.mjs";
import { SpanLogFn, currentSpanTraced } from "./util.js";
import { OpenAIAuth, buildOpenAIClient } from "./oai";
import { CreateEmbeddingResponse } from "openai/resources/embeddings";
import { SpanLogFn, currentSpanTraced } from "./util";
import { OpenAI } from "openai";
import cossim from "compute-cosine-similarity";

Expand Down
4 changes: 2 additions & 2 deletions node/llm.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatCompletionMessage } from "openai/resources/index.mjs";
import { ChatCompletionMessageParam } from "openai/resources";
import {
Battle,
LLMClassifierFromTemplate,
Expand All @@ -18,7 +18,7 @@ test("openai", async () => {
return grade.match(/Winner: (\d+)/)![1];
};

const messages: ChatCompletionMessage[] = [
const messages: ChatCompletionMessageParam[] = [
{
role: "system",
content: `You are a technical project manager who helps software engineers generate better titles for their GitHub issues.
Expand Down
32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@
"name": "autoevals",
"version": "0.0.0",
"description": "Universal library for evaluating AI models",
"main": "jsdist/bundle.js",
"types": "jsdist/index.d.ts",
"type": "module",
"main": "./jsdist/index.js",
"module": "./jsdist/index.mjs",
"types": "./jsdist/index.d.ts",
"exports": {
"node": {
"types": "./jsdist/node.d.ts",
"import": "./jsdist/node.js",
"require": "./jsdist/node.cjs"
},
"browser": {
"./package.json": "./package.json",
".": {
"types": "./jsdist/index.d.ts",
"import": "./jsdist/bundle.js",
"require": "./jsdist/bundle.cjs"
},
"default": {
"types": "./jsdist/index.d.ts",
"import": "./jsdist/bundle.js",
"require": "./jsdist/bundle.cjs"
"import": "./jsdist/index.mjs",
"module": "./jsdist/index.mjs",
"require": "./jsdist/index.js"
}
},
"files": [
"jsdist/**/*"
],
"scripts": {
"build": "tsc && tsx scripts/bundle-js.ts",
"watch": "tsc --watch",
"build": "tsup",
"watch": "tsup --watch",
"docs": "npx typedoc --options typedoc.json js/index.ts",
"test": "jest",
"prepublishOnly": "../scripts/node_prepublish_autoevals.py",
Expand All @@ -40,6 +35,7 @@
"jest": "^29.6.1",
"jest-text-transformer": "^1.0.4",
"ts-jest": "^29.1.1",
"tsup": "^8.0.1",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.1.6"
Expand Down
57 changes: 0 additions & 57 deletions scripts/bundle-js.ts

This file was deleted.

8 changes: 3 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"compilerOptions": {
"incremental": true,
"declaration": true,
"outDir": "./jsdist",
"lib": ["es6"],
"module": "NodeNext",
"target": "es6",
"moduleResolution": "nodenext",
"lib": ["es2015", "dom"],
"target": "ES2018",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
Expand Down
13 changes: 13 additions & 0 deletions tsup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "tsup";

export default defineConfig([
{
entry: ["js/index.ts"],
format: ["cjs", "esm"],
outDir: "jsdist",
dts: true,
loader: {
".yaml": "text",
},
},
]);

0 comments on commit 4693e10

Please sign in to comment.