aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/prompts.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2026-02-09 00:09:10 +0000
committerGitHub <noreply@github.com>2026-02-09 00:09:10 +0000
commit4186c4c64c68892248ce8671d9b8e67fc7f884a0 (patch)
tree91bbbfc0bb47a966b9e340fdbe2a61b2e10ebd19 /packages/shared/prompts.ts
parent77b186c3a599297da0cf19e923c66607ad7d74e7 (diff)
downloadkarakeep-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.ts')
-rw-r--r--packages/shared/prompts.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/shared/prompts.ts b/packages/shared/prompts.ts
index e878a18b..6c5c02c4 100644
--- a/packages/shared/prompts.ts
+++ b/packages/shared/prompts.ts
@@ -1,5 +1,5 @@
import type { ZTagStyle } from "./types/users";
-import { getTagStylePrompt } from "./utils/tag";
+import { getCuratedTagsPrompt, getTagStylePrompt } from "./utils/tag";
/**
* Remove duplicate whitespaces to avoid tokenization issues
@@ -12,8 +12,10 @@ export function buildImagePrompt(
lang: string,
customPrompts: string[],
tagStyle: ZTagStyle,
+ curatedTags?: string[],
) {
const tagStyleInstruction = getTagStylePrompt(tagStyle);
+ const curatedInstruction = getCuratedTagsPrompt(curatedTags);
return `
You are an expert whose responsibility is to help with automatic text tagging for a read-it-later/bookmarking app.
@@ -23,6 +25,7 @@ Analyze the attached image and suggest relevant tags that describe its key theme
- If the tag is not generic enough, don't include it.
- Aim for 10-15 tags.
- If there are no good tags, don't emit any.
+${curatedInstruction}
${tagStyleInstruction}
${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
You must respond in valid JSON with the key "tags" and the value is list of tags. Don't wrap the response in a markdown code.`;
@@ -36,8 +39,10 @@ export function constructTextTaggingPrompt(
customPrompts: string[],
content: string,
tagStyle: ZTagStyle,
+ curatedTags?: string[],
): string {
const tagStyleInstruction = getTagStylePrompt(tagStyle);
+ const curatedInstruction = getCuratedTagsPrompt(curatedTags);
return `
You are an expert whose responsibility is to help with automatic tagging for a read-it-later/bookmarking app.
@@ -50,6 +55,7 @@ Analyze the TEXT_CONTENT below and suggest relevant tags that describe its key t
- Boilerplate content (cookie consent, login walls, GDPR notices)
- Aim for 3-5 tags.
- If there are no good tags, leave the array empty.
+${curatedInstruction}
${tagStyleInstruction}
${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
@@ -83,12 +89,14 @@ export function buildTextPromptUntruncated(
customPrompts: string[],
content: string,
tagStyle: ZTagStyle,
+ curatedTags?: string[],
): string {
return constructTextTaggingPrompt(
lang,
customPrompts,
preprocessContent(content),
tagStyle,
+ curatedTags,
);
}