Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): teach the chat model content tabs
Elian Doran06e37fc4ac39
diff --git a/packages/trilium-core/src/services/llm/system_prompt.spec.ts b/packages/trilium-core/src/services/llm/system_prompt.spec.tsindex db3772a344..662a8666b2 100644--- a/packages/trilium-core/src/services/llm/system_prompt.spec.ts+++ b/packages/trilium-core/src/services/llm/system_prompt.spec.ts@@ -10,6 +10,7 @@ vi.mock("../../services/task_states.js", async (importOriginal) => {return { ...actual, getTaskStates: getTaskStatesMock };});+import markdownImport from "../import/markdown.js";import { buildSystemPrompt } from "./system_prompt.js";describe("buildSystemPrompt", () => {@@ -64,6 +65,24 @@ describe("buildSystemPrompt", () => {expect(prompt).toContain(`<span class="tn-icon bx bx-cog"></span>`);});+ it("teaches content tabs with an example that imports as a tabs block", () => {+ const example = "=== \"Windows\"\n\n Run `setup.exe`.\n\n=== \"Linux\"\n\n Run `./setup.sh`.";+ const prompt = buildSystemPrompt([], {}) ?? "";+ expect(prompt).toContain("Content tabs");+ expect(prompt).toContain(example);++ const html = markdownImport.renderToHtml(example, "Title");+ expect(html.match(/class="trilium-tabs"/g)).toHaveLength(1);+ expect(html).toContain(`<p class="trilium-tab-title">Windows</p>`);+ expect(html).toContain(`<p class="trilium-tab-title">Linux</p>`);+ });++ it("asks to keep the indentation of content tabs only when the model can edit notes", () => {+ const hint = "keep each `===` line and the four-space indentation of its content";+ expect(buildSystemPrompt([], { enableNoteTools: true }) ?? "").toContain(hint);+ expect(buildSystemPrompt([], {}) ?? "").not.toContain(hint);+ });+it("names the icon search tool in the icon hint only when the tool is there", () => {expect(buildSystemPrompt([], { enableNoteTools: true }) ?? "").toContain("find one with search_icons");expect(buildSystemPrompt([], {}) ?? "").not.toContain("find one with search_icons");diff --git a/packages/trilium-core/src/services/llm/system_prompt.ts b/packages/trilium-core/src/services/llm/system_prompt.tsindex cd8f7642ed..44aa103cf6 100644--- a/packages/trilium-core/src/services/llm/system_prompt.ts+++ b/packages/trilium-core/src/services/llm/system_prompt.ts@@ -102,6 +102,7 @@ export function buildSystemPrompt(messages: LlmMessage[], config: LlmProviderCon+ `**Tables** — GitHub-style pipe tables: a header row, a \`---\` separator row, then the data rows.\n\n`+ `**Collapsible blocks** — use the standard HTML \`<details>\`/\`<summary>\` form; the \`<summary>\` is the always-visible title. Placed back-to-back with nothing between them, consecutive collapsible blocks are grouped into an accordion — handy when presenting several options or alternatives the user can expand one at a time. Example:\n`+ `<details><summary>Option A</summary>\nDetails about the first option.\n</details>\n<details><summary>Option B</summary>\nDetails about the second option.\n</details>\n\n`+ + buildTabsHint(config.enableNoteTools === true)+ `**Footnotes** — use \`[^1]\` in text and \`[^1]: explanation\` at the bottom.\n\n`+ `**Keyboard keys** — wrap each key in a \`<kbd>\` tag when documenting shortcuts, e.g. \`<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Del</kbd>\`.\n\n`+ buildIconHint(config.enableNoteTools === true)@@ -123,6 +124,18 @@ function buildIconHint(canSearchIcons: boolean): string {return `**Icons** — insert an inline icon as \`<span class="tn-icon bx bx-cog"></span>\`, with the icon's classes in place of \`bx bx-cog\` (Boxicons such as \`bx bx-star\`, or an installed icon pack's${find}). Use one to show a button or other UI element the user should look for, e.g. "click <span class="tn-icon bx bx-cog"></span> to open the settings"; not as decoration, and not in note titles.\n\n`;}+/**+ * The content-tabs hint. The note tools return text notes as Markdown, so a model that can edit+ * notes is also told to keep the indentation that holds a tab's content inside the tab.+ */+function buildTabsHint(canEditNotes: boolean): string {+ const keep = canEditNotes+ ? " When editing a note that has content tabs, keep each `===` line and the four-space indentation of its content, or the content leaves the tab."+ : "";+ return `**Content tabs** — for content that comes in parallel variants of which the reader needs only one (steps for each operating system, the same snippet in several languages). Each tab is a \`=== "Title"\` line followed by its content indented four spaces; consecutive tabs form one block, and \`===! "Title"\` starts a new block straight after another. Prefer a collapsible accordion when the reader might want to open several options.${keep} Example:\n`+ + "=== \"Windows\"\n\n Run `setup.exe`.\n\n=== \"Linux\"\n\n Run `./setup.sh`.\n\n";+}+/*** The task-list formatting hint, extended with the workspace's user-defined multi-state checkboxes so* the model recognizes their markers (e.g. `- [/]` = "Doing") in the user's notes and can produce them.