aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-01-12 15:31:30 +0000
committerMohamed Bassem <me@mbassem.com>2025-01-12 15:31:30 +0000
commitb8bd7d7eb27aaaadae728599f64a0874f66196ea (patch)
treed2b9ac7f4324ffe7e1659a7e509635c74c9a1c57 /packages/shared
parent1ec21b67df64992bf472fc17bc3842369aa313a7 (diff)
downloadkarakeep-b8bd7d7eb27aaaadae728599f64a0874f66196ea.tar.zst
feat: Support customizing the summarization prompt. Fixes #731
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/prompts.ts6
-rw-r--r--packages/shared/types/prompts.ts7
2 files changed, 11 insertions, 2 deletions
diff --git a/packages/shared/prompts.ts b/packages/shared/prompts.ts
index 82c9ba6e..40e706b2 100644
--- a/packages/shared/prompts.ts
+++ b/packages/shared/prompts.ts
@@ -53,11 +53,15 @@ You must respond in JSON with the key "tags" and the value is an array of string
export function buildSummaryPrompt(
lang: string,
+ customPrompts: string[],
content: string,
contextLength: number,
) {
const constructPrompt = (c: string) => `
- Summarize the following content in 3-4 sentences in ${lang}, responding ONLY with the summary:
+ Summarize the following content responding ONLY with the summary. You MUST follow the following rules:
+- Summary must be in 3-4 sentences.
+- The summary language must be in ${lang}.
+${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
${c}`;
const promptSize = calculateNumTokens(constructPrompt(""));
diff --git a/packages/shared/types/prompts.ts b/packages/shared/types/prompts.ts
index 71a7ee02..e02208e7 100644
--- a/packages/shared/types/prompts.ts
+++ b/packages/shared/types/prompts.ts
@@ -2,7 +2,12 @@ import { z } from "zod";
const MAX_PROMPT_TEXT_LENGTH = 500;
-export const zAppliesToEnumSchema = z.enum(["all", "text", "images"]);
+export const zAppliesToEnumSchema = z.enum([
+ "all_tagging",
+ "text",
+ "images",
+ "summary",
+]);
export const zPromptSchema = z.object({
id: z.string(),