diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-27 17:19:19 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-27 17:19:36 +0000 |
| commit | e8628b586181ea99980b0beafd9976cabfdd077e (patch) | |
| tree | f06985061592e00f5899edb5491dbcc64c754fb4 | |
| parent | 9986746aa890f2490ff18fd4fc79be4de0e4dbe2 (diff) | |
| download | karakeep-e8628b586181ea99980b0beafd9976cabfdd077e.tar.zst | |
fix: Drop the 2k char limit on notes. Fixes #25
| -rw-r--r-- | apps/workers/openaiWorker.ts | 17 | ||||
| -rw-r--r-- | packages/trpc/types/bookmarks.ts | 2 |
2 files changed, 12 insertions, 7 deletions
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<Awaited<ReturnType<typeof fetchBookmark>>>, ) { + 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} `; } diff --git a/packages/trpc/types/bookmarks.ts b/packages/trpc/types/bookmarks.ts index 477adbc8..3360a792 100644 --- a/packages/trpc/types/bookmarks.ts +++ b/packages/trpc/types/bookmarks.ts @@ -15,7 +15,7 @@ export type ZBookmarkedLink = z.infer<typeof zBookmarkedLinkSchema>; export const zBookmarkedTextSchema = z.object({ type: z.literal("text"), - text: z.string().max(2000), + text: z.string(), }); export type ZBookmarkedText = z.infer<typeof zBookmarkedTextSchema>; |
