Skip to content

Commit

Permalink
Fix caching for other APIs as well (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
shengyfu authored Oct 13, 2023
1 parent 6c7d0d2 commit 3c6fcb9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tokenizer_ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tokenizer_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@microsoft/tiktokenizer",
"displayName": "tiktokenizer",
"description": "Tokenizer for OpenAI large language models.",
"version": "1.0.2",
"version": "1.0.3",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
2 changes: 2 additions & 0 deletions tokenizer_ts/src/tikTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export class TikTokenizer {
const bytes = this.textEncoder.encode(piece);
const token = this.encoder!.get(uint8ArrayToString(bytes));
if (token !== undefined) {
this.cache.set(piece, [token]);
tokenCount++;
if (tokenCount <= maxTokenCount) {
encodeLength += piece.length;
Expand Down Expand Up @@ -397,6 +398,7 @@ export class TikTokenizer {
const bytes = new TextEncoder().encode(piece);
const token = this.encoder!.get(uint8ArrayToString(bytes));
if (token !== undefined) {
this.cache.set(piece, [token]);
tokenCount++;
encodeLength += piece.length;
tokenIds.push(token);
Expand Down

0 comments on commit 3c6fcb9

Please sign in to comment.