Skip to content

Commit

Permalink
patch text.substring bug from compressor (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat authored Jul 22, 2024
1 parent a43fa8a commit 18171bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/utils/helpers/tiktoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class TokenManager {
// https://github.com/openai/tiktoken/blob/9e79899bc248d5313c7dd73562b5e211d728723d/tiktoken/core.py#L91C20-L91C38
// Returns number[]
tokensFromString(input = "") {
const tokens = this.encoder.encode(input, undefined, []);
return tokens;
try {
const tokens = this.encoder.encode(String(input), undefined, []);
return tokens;
} catch (e) {
console.error(e);
return [];
}
}

bytesFromTokens(tokens = []) {
Expand Down

0 comments on commit 18171bc

Please sign in to comment.