From 68b8ad745bbc8a081d568167bc94a09943acffb2 Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Wed, 27 Nov 2024 15:04:16 -0800 Subject: [PATCH] Add index button to plus mode, disable unnecessary calls (#873) --- src/components/Chat.tsx | 11 ++++++++--- src/components/chat-components/ChatControls.tsx | 3 ++- src/contextProcessor.ts | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 3daea531..3ac3ebb5 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -1,4 +1,5 @@ import { useAIState } from "@/aiState"; +import { ChainType } from "@/chainFactory"; import { updateChatMemory } from "@/chatUtils"; import ChatInput from "@/components/chat-components/ChatInput"; import ChatMessages from "@/components/chat-components/ChatMessages"; @@ -109,7 +110,8 @@ const Chat: React.FC = ({ app.vault, contextNotes, includeActiveNote, - activeNote + activeNote, + currentChain ); }; @@ -167,8 +169,11 @@ const Chat: React.FC = ({ app.workspace.getActiveFile() as TFile | undefined ); - // Extract Mentions (such as URLs) from original input message only - const urlContextAddition = await mention.processUrls(inputMessage || ""); + // Extract Mentions (such as URLs) from original input message only if using Copilot Plus chain + const urlContextAddition = + currentChain === ChainType.COPILOT_PLUS_CHAIN + ? await mention.processUrls(inputMessage || "") + : ""; // Add context notes const noteContextAddition = await processContextNotes(customPromptProcessor, fileParserManager); diff --git a/src/components/chat-components/ChatControls.tsx b/src/components/chat-components/ChatControls.tsx index 7e466456..5f98a416 100644 --- a/src/components/chat-components/ChatControls.tsx +++ b/src/components/chat-components/ChatControls.tsx @@ -179,7 +179,8 @@ const ChatControls: React.FC = ({ }> Save as Note - {selectedChain === "vault_qa" && ( + {(selectedChain === ChainType.VAULT_QA_CHAIN || + selectedChain === ChainType.COPILOT_PLUS_CHAIN) && ( } diff --git a/src/contextProcessor.ts b/src/contextProcessor.ts index 8ece1a36..fa6a4ca3 100644 --- a/src/contextProcessor.ts +++ b/src/contextProcessor.ts @@ -1,3 +1,4 @@ +import { ChainType } from "@/chainFactory"; import { CustomPromptProcessor } from "@/customPromptProcessor"; import { FileParserManager } from "@/tools/FileParserManager"; import { TFile, Vault } from "obsidian"; @@ -48,20 +49,31 @@ export class ContextProcessor { vault: Vault, contextNotes: TFile[], includeActiveNote: boolean, - activeNote: TFile | null + activeNote: TFile | null, + currentChain: ChainType ): Promise { const processedVars = await customPromptProcessor.getProcessedVariables(); let additionalContext = ""; const processNote = async (note: TFile) => { try { + if (currentChain !== ChainType.COPILOT_PLUS_CHAIN && note.extension !== "md") { + if (!fileParserManager.supportsExtension(note.extension)) { + console.warn(`Unsupported file type: ${note.extension}`); + } else { + console.warn(`File type ${note.extension} only supported in Copilot Plus mode`); + } + return; + } + if (!fileParserManager.supportsExtension(note.extension)) { console.warn(`Unsupported file type: ${note.extension}`); return; } + let content = await fileParserManager.parseFile(note, vault); - if (note.extension === "md") { + if (note.extension === "md" && currentChain === ChainType.COPILOT_PLUS_CHAIN) { content = await this.processEmbeddedPDFs(content, vault, fileParserManager); }