Nick: test suite init

This commit is contained in:
Nicolas
2024-05-08 11:38:46 -07:00
parent 056b0ec24d
commit ad58bc2820
11 changed files with 420 additions and 186 deletions
+16
View File
@@ -0,0 +1,16 @@
import { encoding_for_model } from "@dqbd/tiktoken";
import { TiktokenModel } from "@dqbd/tiktoken";
// This function calculates the number of tokens in a text string using GPT-3.5-turbo model
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);
// Free the encoder resources after use
encoder.free();
// Return the number of tokens
return tokens.length;
}