Skip to content

Commit

Permalink
Fix #182 properly. Allows special tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Nov 8, 2023
1 parent f76d5fa commit 0adc273
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/common/util/token-counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export const countModelTokens: (text: string, llmId: DLLMId, debugFrom: string)
}
}
let count: number = 0;
// Note: the try/catch shouldn't be necessary, but it seems that the Tiktoken library will
// throw an exception when particular text (e.g. '<|fim_suffix|>') is passed for encoding
// Note: the try/catch shouldn't be necessary, but there could be corner cases where the tiktoken library throws
// https://github.com/enricoros/big-agi/issues/182
try {
count = tokenEncoders[openaiModel]?.encode(text)?.length || 0;
count = tokenEncoders[openaiModel]?.encode(text, 'all', [])?.length || 0;
} catch (e) {
console.error(`Error tokenizing "${text.slice(0, 10)}..." with model '${openaiModel}': ${e}`);
}
Expand Down

1 comment on commit 0adc273

@vercel
Copy link

@vercel vercel bot commented on 0adc273 Nov 8, 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:

big-agi – ./

big-agi-git-main-enricoros.vercel.app
get.big-agi.com
big-agi-enricoros.vercel.app

Please sign in to comment.