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
fix(llm): mark DeepSeek searches with the magnifier
Elian Doran6dc77853a296
diff --git a/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts b/packages/trilium-core/src/services/llm/providers/deepseek.spec.tsindex 6b2ad1ec09..cb2b771fa9 100644--- a/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts+++ b/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts@@ -323,6 +323,8 @@ describe("DeepSeekProvider web search", () => {const followUp = String((fetchMock.mock.calls[2] as [ string, RequestInit ])[1].body);expect(followUp).toContain("https://triliumnotes.org");+ // A result without `searchProvider` shows the magnifier, as other built-in searches do.+ expect(followUp).not.toContain("searchProvider");});});diff --git a/packages/trilium-core/src/services/llm/providers/deepseek.ts b/packages/trilium-core/src/services/llm/providers/deepseek.tsindex 0822b88020..4264a9b8aa 100644--- a/packages/trilium-core/src/services/llm/providers/deepseek.ts+++ b/packages/trilium-core/src/services/llm/providers/deepseek.ts@@ -84,7 +84,7 @@ export class DeepSeekProvider extends BaseProvider {* Search API with the provider's key, through the same tools a search provider gets.*/protected override addWebSearchTool(tools: ToolSet): void {- tools.web_search = createWebSearchTool({ provider: "deepseek", name: "DeepSeek", apiKey: this.apiKey, baseURL: this.baseURL });+ tools.web_search = createWebSearchTool({ provider: "deepseek", apiKey: this.apiKey, baseURL: this.baseURL }, { builtIn: true });tools.read_web_page = createReadWebPageTool();}diff --git a/packages/trilium-core/src/services/llm/web_search.spec.ts b/packages/trilium-core/src/services/llm/web_search.spec.tsindex 3a6682124b..fc56513b17 100644--- a/packages/trilium-core/src/services/llm/web_search.spec.ts+++ b/packages/trilium-core/src/services/llm/web_search.spec.ts@@ -208,6 +208,10 @@ describe("createWebSearchTool", () => {searchProvider: { type: "tavily", name: "My Tavily" },sources: [ { ...PAGE, snippet: "Hit" } ]});++ respond({ results: [ { ...PAGE, summary: "Hit" } ] });+ expect(await run(createWebSearchTool({ provider: "deepseek", apiKey: "dk" }, { builtIn: true }), "trilium"))+ .toEqual({ query: "trilium", sources: [ { ...PAGE, snippet: "Hit" } ] });});it("points the model at read_web_page after any failure, and has it report one only the user can fix", async () => {diff --git a/packages/trilium-core/src/services/llm/web_search.ts b/packages/trilium-core/src/services/llm/web_search.tsindex 58f13ad379..94d30aae88 100644--- a/packages/trilium-core/src/services/llm/web_search.ts+++ b/packages/trilium-core/src/services/llm/web_search.ts@@ -39,8 +39,11 @@ const DEEPSEEK_MAX_QUERY_CHARS = 128;* line and the `searchProvider` whose mark the line shows, and a failure is returned as* `{ error, instruction }`: the chat shows `error` on the tool's line, and `instruction` directs the* model to `read_web_page` and, for a {@link SearchSetupError}, to tell the user about it.+ *+ * With `builtIn`, the tool is a model provider's own search, whose result has no `searchProvider`,+ * so the chat shows the magnifier on its line.*/-export function createWebSearchTool(setup: WebSearchSetup) {+export function createWebSearchTool(setup: WebSearchSetup, { builtIn = false } = {}) {return tool({description: "Search the web for current information. Returns the title, URL and a short excerpt of each matching page. "+ "The excerpts rarely hold specific facts such as numbers, dates or versions, so before answering a factual "@@ -52,7 +55,7 @@ export function createWebSearchTool(setup: WebSearchSetup) {try {return {query,- searchProvider: { type: setup.provider, name: setup.name ?? setup.provider },+ ...(!builtIn && { searchProvider: { type: setup.provider, name: setup.name ?? setup.provider } }),sources: await searchWeb(setup, query, options.abortSignal)};} catch (e) {