A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix(shared): cap content length before tokenizing prompts
Mohamed Bassemef07e913edf9
diff --git a/packages/shared/prompts.server.ts b/packages/shared/prompts.server.tsindex 86978fe7..a0c7d1cb 100644--- a/packages/shared/prompts.server.ts+++ b/packages/shared/prompts.server.ts@@ -28,6 +28,9 @@ async function truncateContent(length: number,): Promise<string> {const enc = await getEncodingInstance();+ // Tokenizing is slow and blocks the event loop, so cut the content to a+ // generous upper bound of characters before encoding it.+ content = content.slice(0, length * 8);const tokens = enc.encode(content);if (tokens.length <= length) {return content;