mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 11:42:24 +08:00
fix encoding if error
This commit is contained in:
parent
6ebfcc85cf
commit
aed11e72a6
|
@ -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