Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: add worker logs for tokenization (#3440)

Max Deichmannc979cae6207a
diff --git a/.vscode/launch.json b/.vscode/launch.json
index ee3bdd72cb..be20cab391 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -2,10 +2,10 @@
"version": "0.2.0",
"configurations": [
{
- "name": "Next.js: debug server-side",
+ "name": "Web and Worker: server side",
"type": "node-terminal",
"request": "launch",
- "command": "npm run dev"
+ "command": "pnpm run dev"
},
{
"name": "Next.js: debug client-side",
diff --git a/worker/src/features/tokenisation/usage.ts b/worker/src/features/tokenisation/usage.ts
index 12bcae9d1f..0a846c58aa 100644
--- a/worker/src/features/tokenisation/usage.ts
+++ b/worker/src/features/tokenisation/usage.ts
@@ -59,7 +59,7 @@ export function tokenCount(p: {
return undefined;
}
- },
+ }
);
}
@@ -74,8 +74,8 @@ function openAiTokenCount(p: { model: Model; text: unknown }) {
if (!config.success) {
logger.error(
`Invalid tokenizer config for model ${p.model.id}: ${JSON.stringify(
- p.model.tokenizerConfig,
- )}, ${JSON.stringify(config.error)}`,
+ p.model.tokenizerConfig
+ )}, ${JSON.stringify(config.error)}`
);
return undefined;
}
@@ -90,13 +90,13 @@ function openAiTokenCount(p: { model: Model; text: unknown }) {
) {
// check if the tokenizerConfig is a valid chat config
const parsedConfig = OpenAiChatTokenConfig.safeParse(
- p.model.tokenizerConfig,
+ p.model.tokenizerConfig
);
if (!parsedConfig.success) {
logger.error(
`Invalid tokenizer config for chat model ${
p.model.id
- }: ${JSON.stringify(p.model.tokenizerConfig)}`,
+ }: ${JSON.stringify(p.model.tokenizerConfig)}`
);
return undefined;
}
@@ -109,7 +109,7 @@ function openAiTokenCount(p: { model: Model; text: unknown }) {
? getTokensByModel(config.data.tokenizerModel, parsedText)
: getTokensByModel(
config.data.tokenizerModel,
- JSON.stringify(parsedText),
+ JSON.stringify(parsedText)
);
}
return result;
@@ -174,6 +174,9 @@ const getTokensByModel = (model: TiktokenModel, text: string) => {
encoding = get_encoding("cl100k_base");
}
const cleandedText = unicodeToBytesInString(text);
+
+ logger.info(`Tokenized data for model: ${model}`);
+
return encoding?.encode(cleandedText).length;
};
@@ -205,7 +208,7 @@ function isChatMessageArray(value: unknown): value is ChatMessage[] {
typeof item.role === "string" &&
"content" in item &&
typeof item.content === "string" &&
- (!("name" in item) || typeof item.name === "string"),
+ (!("name" in item) || typeof item.name === "string")
);
}