update config provider string and prompt

This commit is contained in:
Andrew 2024-10-03 00:02:18 -07:00
parent 6741a6fceb
commit 95be6e0b37
2 changed files with 24 additions and 18 deletions

View file

@ -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') ?? ''
}

View file

@ -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<ChatMessage[]>([])
const [chatMessageHistory, setChatMessageHistory] = useState<ChatMessage[]>([])
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)