From b8bd7d7eb27aaaadae728599f64a0874f66196ea Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 12 Jan 2025 15:31:30 +0000 Subject: feat: Support customizing the summarization prompt. Fixes #731 --- apps/web/components/settings/AISettings.tsx | 57 ++++++++++++++++++++++----- apps/web/lib/i18n/locales/en/translation.json | 7 +++- apps/workers/openaiWorker.ts | 2 +- 3 files changed, 54 insertions(+), 12 deletions(-) (limited to 'apps') diff --git a/apps/web/components/settings/AISettings.tsx b/apps/web/components/settings/AISettings.tsx index 79a9e558..1987f763 100644 --- a/apps/web/components/settings/AISettings.tsx +++ b/apps/web/components/settings/AISettings.tsx @@ -27,7 +27,11 @@ import { Plus, Save, Trash2 } from "lucide-react"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { buildImagePrompt, buildTextPrompt } from "@hoarder/shared/prompts"; +import { + buildImagePrompt, + buildSummaryPrompt, + buildTextPrompt, +} from "@hoarder/shared/prompts"; import { zNewPromptSchema, ZPrompt, @@ -42,7 +46,7 @@ export function PromptEditor() { resolver: zodResolver(zNewPromptSchema), defaultValues: { text: "", - appliesTo: "all", + appliesTo: "all_tagging", }, }); @@ -100,9 +104,18 @@ export function PromptEditor() { - All - Text - Images + + {t("settings.ai.all_tagging")} + + + {t("settings.ai.text_tagging")} + + + {t("settings.ai.image_tagging")} + + + {t("settings.ai.summarization")} + @@ -214,9 +227,18 @@ export function PromptRow({ prompt }: { prompt: ZPrompt }) { - All - Text - Images + + {t("settings.ai.all_tagging")} + + + {t("settings.ai.text_tagging")} + + + {t("settings.ai.image_tagging")} + + + {t("settings.ai.summarization")} + @@ -289,7 +311,9 @@ export function PromptDemo() { {buildTextPrompt( clientConfig.inference.inferredTagLang, (prompts ?? []) - .filter((p) => p.appliesTo == "text" || p.appliesTo == "all") + .filter( + (p) => p.appliesTo == "text" || p.appliesTo == "all_tagging", + ) .map((p) => p.text), "\n\n", /* context length */ 1024 /* The value here doesn't matter */, @@ -300,10 +324,23 @@ export function PromptDemo() { {buildImagePrompt( clientConfig.inference.inferredTagLang, (prompts ?? []) - .filter((p) => p.appliesTo == "images" || p.appliesTo == "all") + .filter( + (p) => p.appliesTo == "images" || p.appliesTo == "all_tagging", + ) .map((p) => p.text), ).trim()} +

{t("settings.ai.summarization_prompt")}

+ + {buildSummaryPrompt( + clientConfig.inference.inferredTagLang, + (prompts ?? []) + .filter((p) => p.appliesTo == "summary") + .map((p) => p.text), + "\n\n", + /* context length */ 1024 /* The value here doesn't matter */, + ).trim()} + ); } diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.json index e1bd443a..d23d5a96 100644 --- a/apps/web/lib/i18n/locales/en/translation.json +++ b/apps/web/lib/i18n/locales/en/translation.json @@ -87,7 +87,12 @@ "tagging_rule_description": "Prompts that you add here will be included as rules to the model during tag generation. You can view the final prompts in the prompt preview section.", "prompt_preview": "Prompt Preview", "text_prompt": "Text Prompt", - "images_prompt": "Image Prompt" + "images_prompt": "Image Prompt", + "summarization_prompt": "Summarization Prompt", + "all_tagging": "All Tagging", + "text_tagging": "Text Tagging", + "image_tagging": "Image Tagging", + "summarization": "Summarization" }, "feeds": { "rss_subscriptions": "RSS Subscriptions", diff --git a/apps/workers/openaiWorker.ts b/apps/workers/openaiWorker.ts index bad06bb3..704a6c04 100644 --- a/apps/workers/openaiWorker.ts +++ b/apps/workers/openaiWorker.ts @@ -172,7 +172,7 @@ async function fetchCustomPrompts( const prompts = await db.query.customPrompts.findMany({ where: and( eq(customPrompts.userId, userId), - inArray(customPrompts.appliesTo, ["all", appliesTo]), + inArray(customPrompts.appliesTo, ["all_tagging", appliesTo]), ), columns: { text: true, -- cgit v1.2.3-70-g09d2