From e8628b586181ea99980b0beafd9976cabfdd077e Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 27 Mar 2024 17:19:19 +0000 Subject: fix: Drop the 2k char limit on notes. Fixes #25 --- apps/workers/openaiWorker.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'apps/workers') diff --git a/apps/workers/openaiWorker.ts b/apps/workers/openaiWorker.ts index 9b2934e3..ee48d148 100644 --- a/apps/workers/openaiWorker.ts +++ b/apps/workers/openaiWorker.ts @@ -89,6 +89,14 @@ CONTENT START HERE: function buildPrompt( bookmark: NonNullable>>, ) { + const truncateContent = (content: string) => { + let words = content.split(" "); + if (words.length > 1500) { + words = words.slice(1500); + content = words.join(" "); + } + return content; + }; if (bookmark.link) { if (!bookmark.link.description && !bookmark.link.content) { throw new Error( @@ -98,11 +106,7 @@ function buildPrompt( let content = bookmark.link.content; if (content) { - let words = content.split(" "); - if (words.length > 2000) { - words = words.slice(2000); - content = words.join(" "); - } + content = truncateContent(content); } return ` ${TEXT_PROMPT_BASE} @@ -114,10 +118,11 @@ Content: ${content ?? ""} } if (bookmark.text) { + const content = truncateContent(bookmark.text.text ?? ""); // TODO: Ensure that the content doesn't exceed the context length of openai return ` ${TEXT_PROMPT_BASE} -${bookmark.text.text} +${content} `; } -- cgit v1.2.3-70-g09d2