From 9ecf596cbba6a27822956d6fa5d33410051f09df Mon Sep 17 00:00:00 2001 From: mp Date: Sat, 19 Oct 2024 20:17:54 -0700 Subject: [PATCH] Prepare to debug --- extensions/void/src/common/ctrlL.ts | 14 +++++--------- extensions/void/src/common/sendLLMMessage.ts | 3 +++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/extensions/void/src/common/ctrlL.ts b/extensions/void/src/common/ctrlL.ts index 60649218..6edc0839 100644 --- a/extensions/void/src/common/ctrlL.ts +++ b/extensions/void/src/common/ctrlL.ts @@ -545,7 +545,7 @@ ${newFileStr} messages: [{ role: 'assistant', content: rewriteFileWithDiffInstructions, }, { role: 'assistant', content: promptContent, }], onText, onFinalMessage: (finalMessage) => { res(finalMessage) }, - onError: () => { res(''); console.error('Error rewriting file with diff') }, + onError: (e) => { res(''); console.error('Error rewriting file with diff', e) }, voidConfig: { ...voidConfig, default: { @@ -561,7 +561,7 @@ ${newFileStr} } -const shouldApplyDiffFn = async ({ diff, fileStr, speculationStr, type, voidConfig, setAbort }: { diff: string, fileStr: string, speculationStr: string, type: 'line' | 'chunk', voidConfig: VoidConfig, setAbort: SetAbort }) => { +const shouldApplyDiffFn = ({ diff, fileStr, speculationStr, type, voidConfig, setAbort }: { diff: string, fileStr: string, speculationStr: string, type: 'line' | 'chunk', voidConfig: VoidConfig, setAbort: SetAbort }) => { const promptContent = ( // the speculation is a line @@ -620,9 +620,9 @@ Return \`true\` if this any part of the chunk should be modified, and \`false\` .includes('true') res(containsTrue) }, - onError: () => { + onError: (e) => { res(false); - console.error('Error applying diff to line') + console.error('Error applying diff to line: ', e) }, voidConfig, setAbort, @@ -679,7 +679,7 @@ const applyDiffLazily = async ({ fileUri, fileStr, diff, voidConfig, setAbort }: diff, fileUri, voidConfig, - onText: async (text) => { + onText: async (newText, fullText) => { // TODO! update highlighting here // also make edits here @@ -688,10 +688,6 @@ const applyDiffLazily = async ({ fileUri, fileStr, diff, voidConfig, setAbort }: }) completedLines.push(changeStr) - - // if there's matchup with the file, we stop rewriting - // TODO! otherwise keep rewriting until there is matchup - } } diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index f107c29b..2a29369f 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -278,6 +278,9 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin export const sendLLMMessage: SendLLMMessageFnTypeExternal = ({ messages, onText, onFinalMessage, onError, voidConfig, setAbort }) => { if (!voidConfig) return; + // trim message content (Anthropic and other providers give an error if there is trailing whitespace) + messages = messages.map(m => ({ ...m, content: m.content.trim() })) + switch (voidConfig.default.whichApi) { case 'anthropic': return sendAnthropicMsg({ messages, onText, onFinalMessage, onError, voidConfig, setAbort });