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): send the model to the note tools for any note but the open one
Elian Doran672df5da5559
diff --git a/packages/trilium-core/src/services/llm/note_hint.spec.ts b/packages/trilium-core/src/services/llm/note_hint.spec.tsnew file mode 100644index 0000000000..673f25528f--- /dev/null+++ b/packages/trilium-core/src/services/llm/note_hint.spec.ts@@ -0,0 +1,21 @@+import { beforeEach, describe, expect, it } from "vitest";++import becca from "../../becca/becca.js";+import { buildNote } from "../../test/becca_easy_mocking.js";+import { buildNoteHint } from "./note_hint.js";++describe("buildNoteHint", () => {+ beforeEach(() => becca.reset());++ it("sends other notes to the tools before it offers the preview of the open note", () => {+ buildNote({ id: "open1", title: "Pangram (English)", content: "The quick brown fox" });++ const hint = buildNoteHint("open1", false) ?? "";+ expect(hint).toContain("noteId: open1");+ const toTools = hint.indexOf("read it with the note tools");+ expect(toTools).toBeGreaterThan(-1);+ expect(toTools).toBeLessThan(hint.indexOf("contentPreview"));+ expect(hint).not.toContain("without calling tools");+ expect(buildNoteHint("missing", false)).toBeNull();+ });+});diff --git a/packages/trilium-core/src/services/llm/note_hint.ts b/packages/trilium-core/src/services/llm/note_hint.tsindex 95dcfdc6ee..a7cbad7096 100644--- a/packages/trilium-core/src/services/llm/note_hint.ts+++ b/packages/trilium-core/src/services/llm/note_hint.ts@@ -23,9 +23,9 @@ export function buildNoteHint(noteId: string, hasAttachments: boolean): string |const metadata = dump(getNoteMeta(note, SYSTEM_PROMPT_LIMITS), { lineWidth: -1 });const lines = [- "The user is currently viewing the following note.",- "Use this metadata (including contentPreview) to answer questions about the note without calling tools when possible.",- "Use get_note_content only if the preview is insufficient."+ "The user is currently viewing the note below.",+ "To answer about any other note the user mentions or links, read it with the note tools.",+ "For questions about this note, its metadata and contentPreview might be enough; use get_note_content when they are not."];if (hasAttachments) {// When the user has attached files alongside this turn, those are