From 4186c4c64c68892248ce8671d9b8e67fc7f884a0 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Mon, 9 Feb 2026 00:09:10 +0000 Subject: 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 --- packages/shared/prompts.server.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'packages/shared/prompts.server.ts') 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 { 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); } -- cgit v1.2.3-70-g09d2