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
This commit is contained in:
Logan Yang 2024-12-10 21:42:28 -08:00 committed by GitHub
parent 06a405aa5f
commit a049e1cdaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View file

@ -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
});

View file

@ -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);

View file

@ -551,8 +551,8 @@ export async function safeFetch(url: string, options: RequestInit): Promise<Resp
url,
contentType: "application/json",
headers: options.headers as Record<string, string>,
method: "POST",
body: options.body?.toString(),
method: options.method,
...(options.method === "POST" && { body: options.body?.toString() }),
});
return {