mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 11:42:24 +08:00
Merge pull request #793 from mendableai/fix/issue-665
[Bug] encoding error for special token
This commit is contained in:
commit
d31b85fa91
|
@ -6,7 +6,13 @@ export function numTokensFromString(message: string, model: string): number {
|
|||
const encoder = encoding_for_model(model as TiktokenModel);
|
||||
|
||||
// Encode the message into tokens
|
||||
const tokens = encoder.encode(message);
|
||||
let tokens: Uint32Array;
|
||||
try {
|
||||
tokens = encoder.encode(message);
|
||||
} catch (error) {
|
||||
message = message.replace("<|endoftext|>", "");
|
||||
tokens = encoder.encode(message);
|
||||
}
|
||||
|
||||
// Free the encoder resources after use
|
||||
encoder.free();
|
||||
|
|
Loading…
Reference in New Issue
Block a user