Skip to content

Commit

Permalink
feat: Support customizing the summarization prompt. Fixes #731
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Jan 12, 2025
1 parent 1ec21b6 commit b8bd7d7
Show file tree
Hide file tree
Showing 10 changed files with 1,649 additions and 16 deletions.
57 changes: 47 additions & 10 deletions apps/web/components/settings/AISettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,7 +46,7 @@ export function PromptEditor() {
resolver: zodResolver(zNewPromptSchema),
defaultValues: {
text: "",
appliesTo: "all",
appliesTo: "all_tagging",
},
});

Expand Down Expand Up @@ -100,9 +104,18 @@ export function PromptEditor() {
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="all">All</SelectItem>
<SelectItem value="text">Text</SelectItem>
<SelectItem value="images">Images</SelectItem>
<SelectItem value="all_tagging">
{t("settings.ai.all_tagging")}
</SelectItem>
<SelectItem value="text">
{t("settings.ai.text_tagging")}
</SelectItem>
<SelectItem value="images">
{t("settings.ai.image_tagging")}
</SelectItem>
<SelectItem value="summary">
{t("settings.ai.summarization")}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
Expand Down Expand Up @@ -214,9 +227,18 @@ export function PromptRow({ prompt }: { prompt: ZPrompt }) {
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="all">All</SelectItem>
<SelectItem value="text">Text</SelectItem>
<SelectItem value="images">Images</SelectItem>
<SelectItem value="all_tagging">
{t("settings.ai.all_tagging")}
</SelectItem>
<SelectItem value="text">
{t("settings.ai.text_tagging")}
</SelectItem>
<SelectItem value="images">
{t("settings.ai.image_tagging")}
</SelectItem>
<SelectItem value="summary">
{t("settings.ai.summarization")}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
Expand Down Expand Up @@ -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<CONTENT_HERE>\n",
/* context length */ 1024 /* The value here doesn't matter */,
Expand All @@ -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()}
</code>
<p>{t("settings.ai.summarization_prompt")}</p>
<code className="whitespace-pre-wrap rounded-md bg-muted p-3 text-sm text-muted-foreground">
{buildSummaryPrompt(
clientConfig.inference.inferredTagLang,
(prompts ?? [])
.filter((p) => p.appliesTo == "summary")
.map((p) => p.text),
"\n<CONTENT_HERE>\n",
/* context length */ 1024 /* The value here doesn't matter */,
).trim()}
</code>
</div>
);
}
Expand Down
7 changes: 6 additions & 1 deletion apps/web/lib/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/workers/openaiWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/db/drizzle/0038_calm_clint_barton.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE `customPrompts` SET `attachedBy` = 'all_tagging' WHERE `attachedBy` = 'all';--> statement-breakpoint
ALTER TABLE `customPrompts` RENAME COLUMN `attachedBy` TO `appliesTo`;
Loading

0 comments on commit b8bd7d7

Please sign in to comment.