Skip to content

Commit

Permalink
Upgrade js-tiktoken, use standard interface (#500)
Browse files Browse the repository at this point in the history
js-tiktoken 1.0.8 broke the import we were using to pull in just the
cl100k_base encoding. Switch to the standard `getEncoding` import
instead.
  • Loading branch information
petersalas committed Nov 18, 2023
1 parent c5501a1 commit 6f27bf8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/ai-jsx/package.json
Expand Up @@ -4,7 +4,7 @@
"repository": "fixie-ai/ai-jsx",
"bugs": "https://github.com/fixie-ai/ai-jsx/issues",
"homepage": "https://ai-jsx.com",
"version": "0.26.0",
"version": "0.26.1",
"volta": {
"extends": "../../package.json"
},
Expand Down Expand Up @@ -385,7 +385,7 @@
"cli-highlight": "^2.1.11",
"cli-spinners": "^2.9.0",
"ink": "^4.2.0",
"js-tiktoken": "^1.0.7",
"js-tiktoken": "^1.0.8",
"js-yaml": "^4.1.0",
"langchain": "^0.0.143",
"lodash": "^4.17.21",
Expand Down
5 changes: 2 additions & 3 deletions packages/ai-jsx/src/lib/openai.tsx
Expand Up @@ -22,8 +22,7 @@ import { OpenAI as OpenAIClient } from 'openai';
export { OpenAI as OpenAIClient } from 'openai';
import { FinalRequestOptions } from 'openai/core';
import { debugRepresentation } from '../core/debug.js';
import cl100k_base from 'js-tiktoken/ranks/cl100k_base';
import { Tiktoken } from 'js-tiktoken/lite';
import { getEncoding } from 'js-tiktoken';
import _ from 'lodash';

// https://platform.openai.com/docs/models/model-endpoint-compatibility
Expand Down Expand Up @@ -136,7 +135,7 @@ export function OpenAI({
}

// Preload the tokenizer to avoid a large delay on first use.
const cl100kTokenizer = new Tiktoken(cl100k_base);
const cl100kTokenizer = getEncoding('cl100k_base');
export const tokenizer = {
encode: (text: string) => cl100kTokenizer.encode(text),
decode: (tokens: number[]) => cl100kTokenizer.decode(tokens),
Expand Down
6 changes: 5 additions & 1 deletion packages/docs/docs/changelog.md
@@ -1,6 +1,10 @@
# Changelog

## 0.26.0
## 0.26.1

- Fix `js-tiktoken` import that fails on 1.0.8.

## [0.26.0](https://github.com/fixie-ai/ai-jsx/commit/c5501a1d1016a3cb27259a79bc38b8d68942f761)

- In the `Sidekick` component:
- Remove the MDX repair attempt.
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Expand Up @@ -7306,7 +7306,7 @@ __metadata:
globby: ^13.1.4
ink: ^4.2.0
jest: ^29.5.0
js-tiktoken: ^1.0.7
js-tiktoken: ^1.0.8
js-yaml: ^4.1.0
langchain: ^0.0.143
load-json-file: ^7.0.1
Expand Down Expand Up @@ -16413,6 +16413,15 @@ __metadata:
languageName: node
linkType: hard

"js-tiktoken@npm:^1.0.8":
version: 1.0.8
resolution: "js-tiktoken@npm:1.0.8"
dependencies:
base64-js: ^1.5.1
checksum: ac6e666f14661b4e744bd60987e35275668863a686413bb35baca2d9a503bc95fcfa907f3c02b8e8abe4a4a70abe622c06cbb72ce3574b3b929d22f9146c3f85
languageName: node
linkType: hard

"js-tokens@npm:^3.0.0 || ^4.0.0, js-tokens@npm:^4.0.0":
version: 4.0.0
resolution: "js-tokens@npm:4.0.0"
Expand Down

4 comments on commit 6f27bf8

@vercel
Copy link

@vercel vercel bot commented on 6f27bf8 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-jsx-voice – ./packages/voice

ai-jsx-voice-fixie-ai.vercel.app
ai-jsx-voice-git-main-fixie-ai.vercel.app
ai-jsx-voice.vercel.app
voice.fixie.ai

@vercel
Copy link

@vercel vercel bot commented on 6f27bf8 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-jsx-docs – ./packages/docs

ai-jsx-docs.vercel.app
ai-jsx-docs-fixie-ai.vercel.app
ai-jsx-docs-git-main-fixie-ai.vercel.app
docs.ai-jsx.com

@vercel
Copy link

@vercel vercel bot commented on 6f27bf8 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-jsx-nextjs-demo – ./packages/nextjs-demo

ai-jsx-nextjs-demo.vercel.app
ai-jsx-nextjs-demo-git-main-fixie-ai.vercel.app
ai-jsx-nextjs-demo-fixie-ai.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6f27bf8 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-jsx-tutorial-nextjs – ./packages/tutorial-nextjs

ai-jsx-tutorial-nextjs-git-main-fixie-ai.vercel.app
ai-jsx-tutorial-nextjs.vercel.app
ai-jsx-tutorial-nextjs-fixie-ai.vercel.app

Please sign in to comment.