From eec7cd73211ba6d464d05be4f2808defc77f0e2b Mon Sep 17 00:00:00 2001 From: Tom Spielvogel <35257265+IDLe-Engineering@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:55:37 +0200 Subject: [PATCH 1/2] Update SidebarChat.tsx Build the prompt based on the actual use-case. If no files or code is selected, don't prompt the LLM to change it. It saves time and tokens --- extensions/void/src/sidebar/SidebarChat.tsx | 46 +++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/extensions/void/src/sidebar/SidebarChat.tsx b/extensions/void/src/sidebar/SidebarChat.tsx index 4b029a66..b447ef68 100644 --- a/extensions/void/src/sidebar/SidebarChat.tsx +++ b/extensions/void/src/sidebar/SidebarChat.tsx @@ -22,22 +22,44 @@ ${content} \`\`\``).join('\n') } -const userInstructionsStr = (instructions: string, files: File[], selection: CodeSelection | null) => { - return ` -${filesStr(files)} +const userInstructionsStr = (instructions: string, files: File[], selection: Selection | null): string => { + let str = ''; -${!selection ? '' : ` + if (files.length > 0) { + str += filesStr(files); + } + + if (selection) { + str += ` I am currently selecting this code: -\`\`\`${selection.selectionStr}\`\`\` -`} +\t\`\`\`${selection.selectionStr}\`\`\` +`; + } -Please edit the code following these instructions (or, if appropriate, answer my question instead): -${instructions} - -If you make a change, rewrite the entire file. + if (files.length > 0 && selection) { + str += ` +Please edit the selected code or the entire file following these instructions: +`; + } else if (files.length > 0) { + str += ` +Please edit the file following these instructions: +`; + } else if (selection) { + str += ` +Please edit the selected code following these instructions: +`; + } + + str += ` +\t${instructions} +`; + if (files.length > 0) { + str += ` +\tIf you make a change, rewrite the entire file. `; // TODO don't rewrite the whole file on prompt, instead rewrite it when click Apply -} - + } + return str; +}; const ChatBubble = ({ chatMessage }: { chatMessage: ChatMessage }) => { From 15994c46d1e3d66624e79668cec058c5fe0c26e5 Mon Sep 17 00:00:00 2001 From: Tom Spielvogel <35257265+IDLe-Engineering@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:28:23 +0200 Subject: [PATCH 2/2] Adapted to new type CodeSelection --- extensions/void/src/sidebar/SidebarChat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/void/src/sidebar/SidebarChat.tsx b/extensions/void/src/sidebar/SidebarChat.tsx index b447ef68..645afb46 100644 --- a/extensions/void/src/sidebar/SidebarChat.tsx +++ b/extensions/void/src/sidebar/SidebarChat.tsx @@ -22,7 +22,7 @@ ${content} \`\`\``).join('\n') } -const userInstructionsStr = (instructions: string, files: File[], selection: Selection | null): string => { +const userInstructionsStr = (instructions: string, files: File[], selection: CodeSelection | null) => { let str = ''; if (files.length > 0) {