diff options
| author | Mohamed Bassem <me@mbassem.com> | 2026-02-09 00:09:10 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-09 00:09:10 +0000 |
| commit | 4186c4c64c68892248ce8671d9b8e67fc7f884a0 (patch) | |
| tree | 91bbbfc0bb47a966b9e340fdbe2a61b2e10ebd19 /packages/shared/prompts.server.ts | |
| parent | 77b186c3a599297da0cf19e923c66607ad7d74e7 (diff) | |
| download | karakeep-4186c4c64c68892248ce8671d9b8e67fc7f884a0.tar.zst | |
feat(ai): Support restricting AI tags to a subset of existing tags (#2444)
* feat(ai): Support restricting AI tags to a subset of existing tags
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to 'packages/shared/prompts.server.ts')
| -rw-r--r-- | packages/shared/prompts.server.ts | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/packages/shared/prompts.server.ts b/packages/shared/prompts.server.ts index 3e2666de..c53f4190 100644 --- a/packages/shared/prompts.server.ts +++ b/packages/shared/prompts.server.ts @@ -49,6 +49,7 @@ export async function buildTextPrompt( content: string, contextLength: number, tagStyle: ZTagStyle, + curatedTags?: string[], ): Promise<string> { content = preprocessContent(content); const promptTemplate = constructTextTaggingPrompt( @@ -56,17 +57,18 @@ export async function buildTextPrompt( customPrompts, "", tagStyle, + curatedTags, ); const promptSize = await calculateNumTokens(promptTemplate); - const truncatedContent = await truncateContent( - content, - contextLength - promptSize, - ); + const available = Math.max(0, contextLength - promptSize); + const truncatedContent = + available === 0 ? "" : await truncateContent(content, available); return constructTextTaggingPrompt( lang, customPrompts, truncatedContent, tagStyle, + curatedTags, ); } @@ -79,9 +81,8 @@ export async function buildSummaryPrompt( content = preprocessContent(content); const promptTemplate = constructSummaryPrompt(lang, customPrompts, ""); const promptSize = await calculateNumTokens(promptTemplate); - const truncatedContent = await truncateContent( - content, - contextLength - promptSize, - ); + const available = Math.max(0, contextLength - promptSize); + const truncatedContent = + available === 0 ? "" : await truncateContent(content, available); return constructSummaryPrompt(lang, customPrompts, truncatedContent); } |
