From 95be6e0b375e6aea0d676dfb3f4daeec57aacebc Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 3 Oct 2024 00:02:18 -0700 Subject: [PATCH] update config provider string and prompt --- extensions/void/src/extension.ts | 18 +++++++++--------- extensions/void/src/sidebar/Sidebar.tsx | 24 +++++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 43569988..20630248 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -14,17 +14,17 @@ const readFileContentOfUri = async (uri: vscode.Uri) => { const getApiConfig = () => { const apiConfig: ApiConfig = { anthropic: { - apikey: vscode.workspace.getConfiguration('void').get('anthropic.apiKey') ?? '', - model: vscode.workspace.getConfiguration('void').get('anthropic.model') ?? '', - maxTokens: vscode.workspace.getConfiguration('void').get('anthropic.maxTokens') ?? '', + apikey: vscode.workspace.getConfiguration('void.anthropic').get('apiKey') ?? '', + model: vscode.workspace.getConfiguration('void.anthropic').get('model') ?? '', + maxTokens: vscode.workspace.getConfiguration('void.anthropic').get('maxTokens') ?? '', }, openai: { - apikey: vscode.workspace.getConfiguration('void').get('openAI.apiKey') ?? '', - model: vscode.workspace.getConfiguration('void').get('anthropic.model') ?? '', + apikey: vscode.workspace.getConfiguration('void.openAI').get('apiKey') ?? '', + model: vscode.workspace.getConfiguration('void.openAI').get('model') ?? '', }, greptile: { - apikey: vscode.workspace.getConfiguration('void').get('greptile.apiKey') ?? '', - githubPAT: vscode.workspace.getConfiguration('void').get('greptile.githubPAT') ?? '', + apikey: vscode.workspace.getConfiguration('void.greptile').get('apiKey') ?? '', + githubPAT: vscode.workspace.getConfiguration('void.greptile').get('githubPAT') ?? '', repoinfo: { remote: 'github', repository: 'TODO', @@ -32,8 +32,8 @@ const getApiConfig = () => { } }, ollama: { - endpoint: vscode.workspace.getConfiguration('void').get('ollama.endpoint') ?? '', - model: vscode.workspace.getConfiguration('void').get('ollama.model') ?? '', + endpoint: vscode.workspace.getConfiguration('void.ollama').get('endpoint') ?? '', + model: vscode.workspace.getConfiguration('void.ollama').get('model') ?? '', }, whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? '' } diff --git a/extensions/void/src/sidebar/Sidebar.tsx b/extensions/void/src/sidebar/Sidebar.tsx index 539b06be..e96006d0 100644 --- a/extensions/void/src/sidebar/Sidebar.tsx +++ b/extensions/void/src/sidebar/Sidebar.tsx @@ -27,7 +27,7 @@ I am currently selecting this code: \`\`\`${selection.selectionStr}\`\`\` `} -Please edit the code following these instructions: +Please edit the code following these instructions (or, if appropriate, answer my question instead): ${instructions} If you make a change, rewrite the entire file. @@ -141,7 +141,7 @@ const Sidebar = () => { const [instructions, setInstructions] = useState('') // the user's instructions // state of chat - const [chatMessageHistory, setChatHistory] = useState([]) + const [chatMessageHistory, setChatMessageHistory] = useState([]) const [messageStream, setMessageStream] = useState('') const [isLoading, setIsLoading] = useState(false) @@ -197,6 +197,15 @@ const Sidebar = () => { setSelection(null) setFiles([]) + + // TODO this is just a hack, turn this into a button instead, and track all histories somewhere + if (instructions === 'clear') { + setChatMessageHistory([]) + setMessageStream('') + setIsLoading(false) + return + } + // request file content from vscode and await response getVSCodeAPI().postMessage({ type: 'requestFiles', filepaths: files }) const relevantFiles = await awaitVSCodeResponse('files') @@ -205,19 +214,16 @@ const Sidebar = () => { const content = userInstructionsStr(instructions, relevantFiles.files, selection) // console.log('prompt:\n', content) const newHistoryElt: ChatMessage = { role: 'user', content, displayContent: instructions, selection, files } - setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) + setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) // send message to claude let { abort } = sendLLMMessage({ messages: [...chatMessageHistory.map(m => ({ role: m.role, content: m.content })), { role: 'user', content }], onText: (newText, fullText) => setMessageStream(fullText), onFinalMessage: (content) => { - - // add assistant's message to chat history + // add assistant's message to chat history, and clear selection const newHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content, } - setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) - - // clear selection + setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) setMessageStream('') setIsLoading(false) }, @@ -234,7 +240,7 @@ const Sidebar = () => { // if messageStream was not empty, add it to the history const llmContent = messageStream || '(canceled)' const newHistoryElt: ChatMessage = { role: 'assistant', displayContent: messageStream, content: llmContent } - setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) + setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) setMessageStream('') setIsLoading(false)