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 getApiConfig = () => {
const apiConfig: ApiConfig = { const apiConfig: ApiConfig = {
anthropic: { anthropic: {
apikey: vscode.workspace.getConfiguration('void').get('anthropic.apiKey') ?? '', apikey: vscode.workspace.getConfiguration('void.anthropic').get('apiKey') ?? '',
model: vscode.workspace.getConfiguration('void').get('anthropic.model') ?? '', model: vscode.workspace.getConfiguration('void.anthropic').get('model') ?? '',
maxTokens: vscode.workspace.getConfiguration('void').get('anthropic.maxTokens') ?? '', maxTokens: vscode.workspace.getConfiguration('void.anthropic').get('maxTokens') ?? '',
}, },
openai: { openai: {
apikey: vscode.workspace.getConfiguration('void').get('openAI.apiKey') ?? '', apikey: vscode.workspace.getConfiguration('void.openAI').get('apiKey') ?? '',
model: vscode.workspace.getConfiguration('void').get('anthropic.model') ?? '', model: vscode.workspace.getConfiguration('void.openAI').get('model') ?? '',
}, },
greptile: { greptile: {
apikey: vscode.workspace.getConfiguration('void').get('greptile.apiKey') ?? '', apikey: vscode.workspace.getConfiguration('void.greptile').get('apiKey') ?? '',
githubPAT: vscode.workspace.getConfiguration('void').get('greptile.githubPAT') ?? '', githubPAT: vscode.workspace.getConfiguration('void.greptile').get('githubPAT') ?? '',
repoinfo: { repoinfo: {
remote: 'github', remote: 'github',
repository: 'TODO', repository: 'TODO',
@ -32,8 +32,8 @@ const getApiConfig = () => {
} }
}, },
ollama: { ollama: {
endpoint: vscode.workspace.getConfiguration('void').get('ollama.endpoint') ?? '', endpoint: vscode.workspace.getConfiguration('void.ollama').get('endpoint') ?? '',
model: vscode.workspace.getConfiguration('void').get('ollama.model') ?? '', model: vscode.workspace.getConfiguration('void.ollama').get('model') ?? '',
}, },
whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? '' whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? ''
} }

View file

@ -27,7 +27,7 @@ I am currently selecting this code:
\`\`\`${selection.selectionStr}\`\`\` \`\`\`${selection.selectionStr}\`\`\`
`} `}
Please edit the code following these instructions: Please edit the code following these instructions (or, if appropriate, answer my question instead):
${instructions} ${instructions}
If you make a change, rewrite the entire file. If you make a change, rewrite the entire file.
@ -141,7 +141,7 @@ const Sidebar = () => {
const [instructions, setInstructions] = useState('') // the user's instructions const [instructions, setInstructions] = useState('') // the user's instructions
// state of chat // state of chat
const [chatMessageHistory, setChatHistory] = useState<ChatMessage[]>([]) const [chatMessageHistory, setChatMessageHistory] = useState<ChatMessage[]>([])
const [messageStream, setMessageStream] = useState('') const [messageStream, setMessageStream] = useState('')
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
@ -197,6 +197,15 @@ const Sidebar = () => {
setSelection(null) setSelection(null)
setFiles([]) 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 // request file content from vscode and await response
getVSCodeAPI().postMessage({ type: 'requestFiles', filepaths: files }) getVSCodeAPI().postMessage({ type: 'requestFiles', filepaths: files })
const relevantFiles = await awaitVSCodeResponse('files') const relevantFiles = await awaitVSCodeResponse('files')
@ -205,19 +214,16 @@ const Sidebar = () => {
const content = userInstructionsStr(instructions, relevantFiles.files, selection) const content = userInstructionsStr(instructions, relevantFiles.files, selection)
// console.log('prompt:\n', content) // console.log('prompt:\n', content)
const newHistoryElt: ChatMessage = { role: 'user', content, displayContent: instructions, selection, files } const newHistoryElt: ChatMessage = { role: 'user', content, displayContent: instructions, selection, files }
setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt])
// send message to claude // send message to claude
let { abort } = sendLLMMessage({ let { abort } = sendLLMMessage({
messages: [...chatMessageHistory.map(m => ({ role: m.role, content: m.content })), { role: 'user', content }], messages: [...chatMessageHistory.map(m => ({ role: m.role, content: m.content })), { role: 'user', content }],
onText: (newText, fullText) => setMessageStream(fullText), onText: (newText, fullText) => setMessageStream(fullText),
onFinalMessage: (content) => { onFinalMessage: (content) => {
// add assistant's message to chat history, and clear selection
// add assistant's message to chat history
const newHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content, } const newHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content, }
setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt])
// clear selection
setMessageStream('') setMessageStream('')
setIsLoading(false) setIsLoading(false)
}, },
@ -234,7 +240,7 @@ const Sidebar = () => {
// if messageStream was not empty, add it to the history // if messageStream was not empty, add it to the history
const llmContent = messageStream || '(canceled)' const llmContent = messageStream || '(canceled)'
const newHistoryElt: ChatMessage = { role: 'assistant', displayContent: messageStream, content: llmContent } const newHistoryElt: ChatMessage = { role: 'assistant', displayContent: messageStream, content: llmContent }
setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) setChatMessageHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt])
setMessageStream('') setMessageStream('')
setIsLoading(false) setIsLoading(false)