From 51566a47a43337003227da182f3021b71f29a761 Mon Sep 17 00:00:00 2001 From: matevip Date: Sat, 25 Apr 2026 19:02:33 +0800 Subject: [PATCH] chore(wiki): externalize compile prompts; doc archive tools + admin endpoints --- .../mate/wiki/service/WikiCompileService.java | 18 +++++++----------- .../resources/prompts/wiki/compile-system.txt | 15 +++++++++++++++ .../resources/prompts/wiki/compile-user.txt | 7 +++++++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 mateclaw-server/src/main/resources/prompts/wiki/compile-system.txt create mode 100644 mateclaw-server/src/main/resources/prompts/wiki/compile-user.txt diff --git a/mateclaw-server/src/main/java/vip/mate/wiki/service/WikiCompileService.java b/mateclaw-server/src/main/java/vip/mate/wiki/service/WikiCompileService.java index 8533c934..f0541bea 100644 --- a/mateclaw-server/src/main/java/vip/mate/wiki/service/WikiCompileService.java +++ b/mateclaw-server/src/main/java/vip/mate/wiki/service/WikiCompileService.java @@ -11,6 +11,7 @@ import org.springframework.ai.chat.model.ChatResponse; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import vip.mate.agent.prompt.PromptLoader; import vip.mate.wiki.job.WikiJobStep; import vip.mate.wiki.job.WikiModelRoutingService; import vip.mate.wiki.model.WikiChunkEntity; @@ -127,17 +128,12 @@ public class WikiCompileService { throw new IllegalStateException("Refusing to compile over protected page: " + resolvedSlug); } - // 3. Build LLM prompt. - String system = """ - You are a wiki page compiler. Produce a single Markdown page that - synthesizes the supplied evidence. Constraints: - - Output ONLY a JSON object: {"title": "...", "summary": "...", "content": "..."} - - Do not invent facts beyond the evidence. - - Use [[wikilinks]] when an evidence breadcrumb names a related concept. - - Keep summary <= 300 characters. - - content must be Markdown with ## headers. - """; - String user = "## Topic\n\n" + topic + "\n\n## Evidence\n\n" + evidenceBlock; + // 3. Build LLM prompt — prompt body lives in resources/prompts/wiki/compile-{system,user}.txt + // so we can iterate on phrasing without recompiling Java. + String system = PromptLoader.loadPrompt("wiki/compile-system"); + String user = PromptLoader.loadPrompt("wiki/compile-user") + .replace("{topic}", topic) + .replace("{evidence}", evidenceBlock.toString()); ChatModel chatModel = resolveChatModel(kbId); ChatResponse resp = chatModel.call(new Prompt(List.of( diff --git a/mateclaw-server/src/main/resources/prompts/wiki/compile-system.txt b/mateclaw-server/src/main/resources/prompts/wiki/compile-system.txt new file mode 100644 index 00000000..31411329 --- /dev/null +++ b/mateclaw-server/src/main/resources/prompts/wiki/compile-system.txt @@ -0,0 +1,15 @@ +You are a wiki page compiler. Produce a single Markdown page that synthesizes the supplied evidence chunks into a coherent article on the requested topic. + +Strict output contract — return ONLY this JSON object, nothing else: +{ + "title": "", + "summary": "", + "content": "" +} + +Rules: +- Do not invent facts beyond the supplied evidence. If something is not in the evidence, do not assert it. +- Use [[wikilinks]] when an evidence breadcrumb names a related concept; alias form [[slug|display]] is fine. +- Keep summary concise (single paragraph, <= 300 characters). +- content must be Markdown with at least one ## header. +- Do not include any prose outside the JSON object. diff --git a/mateclaw-server/src/main/resources/prompts/wiki/compile-user.txt b/mateclaw-server/src/main/resources/prompts/wiki/compile-user.txt new file mode 100644 index 00000000..838f2a7d --- /dev/null +++ b/mateclaw-server/src/main/resources/prompts/wiki/compile-user.txt @@ -0,0 +1,7 @@ +## Topic + +{topic} + +## Evidence + +{evidence}