From a049e1cdaa0dc1fedc24b2565fd1b3fa9de52bab Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Tue, 10 Dec 2024 21:42:28 -0800 Subject: [PATCH] Fix web search, list indexed files, pass current time to vault search (#921) * Enhance vault search with current time info * Fix file already exists for list indexed files * Fix safeFetch for GET request --- src/LLMProviders/chainRunner.ts | 8 +++++++- src/main.ts | 4 +++- src/utils.ts | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/LLMProviders/chainRunner.ts b/src/LLMProviders/chainRunner.ts index 5af5675a..f96abd9f 100644 --- a/src/LLMProviders/chainRunner.ts +++ b/src/LLMProviders/chainRunner.ts @@ -427,10 +427,16 @@ class CopilotPlusChainRunner extends BaseChainRunner { const timeExpression = this.getTimeExpression(toolCalls); const context = this.formatLocalSearchResult(documents, timeExpression); + const currentTimeOutputs = toolOutputs.filter((output) => output.tool === "getCurrentTime"); + const enhancedQuestion = this.prepareEnhancedUserMessage( + standaloneQuestion, + currentTimeOutputs + ); + if (debug) console.log(context); if (debug) console.log("==== Step 5: Invoking QA Chain ===="); const qaPrompt = await this.chainManager.promptManager.getQAPrompt({ - question: standaloneQuestion, + question: enhancedQuestion, context: context, systemMessage: "", // System prompt is added separately in streamMultimodalResponse }); diff --git a/src/main.ts b/src/main.ts index 3905a9dd..876236c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -355,7 +355,9 @@ export default class CopilotPlugin extends Plugin { const fileName = `Copilot-Indexed-Files-${new Date().toLocaleDateString().replace(/\//g, "-")}.md`; const filePath = `${fileName}`; - await this.app.vault.create(filePath, content); + if (!this.app.vault.getAbstractFileByPath(filePath)) { + await this.app.vault.create(filePath, content); + } // Open the newly created file const createdFile = this.app.vault.getAbstractFileByPath(filePath); diff --git a/src/utils.ts b/src/utils.ts index 858763e3..a5c88f13 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -551,8 +551,8 @@ export async function safeFetch(url: string, options: RequestInit): Promise, - method: "POST", - body: options.body?.toString(), + method: options.method, + ...(options.method === "POST" && { body: options.body?.toString() }), }); return {