Skip to content

Commit

Permalink
Merge pull request #88 from token-js/pate/minimize-bundle-size
Browse files Browse the repository at this point in the history
maint: Minimize bundle size by only distributing as CommonJS
  • Loading branch information
RPate97 authored Jul 16, 2024
2 parents a8d8cf5 + ba35d6b commit 0cc5d05
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-clocks-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'token.js': minor
---

Minimize bundle size
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
"version": "0.2.3",
"description": "Integrate 9 LLM providers with a single Typescript SDK using OpenAIs format.",
"main": "dist/index.cjs",
"module": "dist/index.js",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist/*"
],
Expand Down
10 changes: 10 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const build = async () => {
platform: 'node',
treeShaking: true,
tsconfig: 'tsconfig.json',
external: [
'@anthropic-ai/sdk',
'@aws-sdk/client-bedrock-runtime',
'@google/generative-ai',
'chalk',
'axios',
'cohere-ai',
'mime-types',
'openai',
],
}),
])
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/example.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dotenv = require('dotenv')

const { TokenJS } = require('./dist/index.cjs')
const { TokenJS } = require('../dist/index.cjs')

dotenv.config()

Expand Down
8 changes: 4 additions & 4 deletions scripts/example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as dotenv from 'dotenv'
import { OpenAI } from 'openai'

import { TokenJS } from '../src'
import { TokenJS } from '../dist/index.cjs'
dotenv.config()

const messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [
Expand All @@ -15,15 +15,15 @@ const callLLM = async () => {
const tokenjs = new TokenJS()
const result = await tokenjs.chat.completions.create({
// stream: true,
provider: 'openai',
model: 'gpt-4o',
provider: 'gemini',
model: 'gemini-1.5-pro',
messages,
})

console.log(result.choices)

// for await (const part of result) {
// process.stdout.write(part.choices[0]?.delta?.content || "");
// process.stdout.write(part.choices[0]?.delta?.content || "");
// }
}

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"sourceMap": true,
"esModuleInterop": true,
"composite": true,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
Expand All @@ -19,6 +18,9 @@
"rootDir": "./src",
"outDir": "./dist",
"skipLibCheck": true,
"declaration": true,
"declarationDir": "./dist",
"emitDeclarationOnly": true
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit 0cc5d05

Please sign in to comment.