From 6327c584cc3b196b961d3ce9075c52bd730b6dcd Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Wed, 22 Jan 2025 17:23:00 -0800 Subject: [PATCH] remove role=system for compatibility --- .../platform/void/common/llmMessageService.ts | 19 ++++- .../contrib/void/browser/prompt/prompts.ts | 72 +++++++------------ .../react/src/sidebar-tsx/SidebarChat.tsx | 4 +- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/vs/platform/void/common/llmMessageService.ts b/src/vs/platform/void/common/llmMessageService.ts index caaeb0c8..cd2b4de4 100644 --- a/src/vs/platform/void/common/llmMessageService.ts +++ b/src/vs/platform/void/common/llmMessageService.ts @@ -98,9 +98,24 @@ export class LLMMessageService extends Disposable implements ILLMMessageService } const { providerName, modelName } = modelSelection + // end early if there are no messages + if (proxyParams.messages.length === 0) { + onError({ message: 'Please send a message first.', fullError: null }) + return null + } + + // make first message contain system message for compatibility + // this is needed because o1 and other models do not accept a system prompt const aiInstructions = this.voidSettingsService.state.globalSettings.aiInstructions - if (aiInstructions) - proxyParams.messages.unshift({ role: 'system', content: aiInstructions }) + const systemMessageIdx = proxyParams.messages.findIndex(m => m.role === 'system') + const systemMessage = systemMessageIdx > -1 ? proxyParams.messages[systemMessageIdx].content : undefined + proxyParams.messages[0].content = `` + + (systemMessage ? `\n\n${systemMessage}` : '') + + (aiInstructions ? `\n\n${aiInstructions}` : '') + + `\n\nHere are the user's instructions:\n\n${proxyParams.messages[0].content}` + if (systemMessageIdx > -1) { // remove role='system' messages + proxyParams.messages.splice(systemMessageIdx, 1) + } // add state for request id const requestId_ = generateUuid(); diff --git a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts index 1cc62878..86e58673 100644 --- a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts +++ b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts @@ -125,14 +125,13 @@ export const chat_prompt = (instructions: string, selections: CodeSelection[] | export const ctrlLStream_systemMessage = ` -You are a coding assistant that applies a diff to a file. You are given the original file \`original_file\`, a diff \`diff\`, and a new file that you are applying the diff to \`new_file\`. +You are a coding assistant that applies a change to a file. You are given the original file \`original_file\`, a change \`change\`, and a new file that you are applying the change to \`new_file\`. -Please finish writing the new file \`new_file\`, according to the diff \`diff\`. You must completely re-write the whole file, using the diff. +Please finish writing the new file \`new_file\`, according to the change \`change\`. You must completely re-write the whole file, using the change. Directions: 1. Continue exactly where the new file \`new_file\` left off. 2. Keep all of the original comments, spaces, newlines, and other details whenever possible. -3. Note that \`+\` lines represent additions, \`-\` lines represent removals, and space lines \` \` represent no change. # Example 1: @@ -173,43 +172,26 @@ const Sidebar: React.FC = ({ items, onItemSelect, onExtraButtonCli export default Sidebar; \`\`\` -DIFF +CHANGE \`\`\` typescript -@@ ... @@ --
--
    -- {items.map((item, index) => ( --
  • -- --
  • -- ))} --
-- --
-+
-+
    -+ {items.map((item, index) => ( -+
  • -+
    onItemSelect?.(item.label)} -+ > -+ {item.label} -+
    -+
  • -+ ))} -+
-+
-+ Extra Action -+
-+
+// existing code ... +
+
    + {items.map((item, index) => ( +
  • +
    onItemSelect?.(item.label)} + > + {item.label} +
    +
  • + ))} +
+
+ Extra Action +
+// existing code ... \`\`\` NEW_FILE @@ -265,22 +247,20 @@ ORIGINAL_CODE ${originalCode} \`\`\` -DIFF +CHANGE \`\`\` ${userMessage} \`\`\` INSTRUCTIONS -Please finish writing the new file by applying the diff to the original file. Return ONLY the completion of the file, without any explanation. +Please finish writing the new file by applying the change to the original file. Return ONLY the completion of the file, without any explanation. ` } // this should probably be longer -export const ctrlKStream_systemMessage = `\ -You are an AI assistant tasked with filling in the middle. -` +export const ctrlKStream_systemMessage = `` export const ctrlKStream_prefixAndSuffix = ({ fullFileStr, startLine, endLine }: { fullFileStr: string, startLine: number, endLine: number }) => { @@ -338,8 +318,8 @@ export type FimTagsType = { midTag: string } export const defaultFimTags: FimTagsType = { - preTag: 'BEFORE', - sufTag: 'AFTER', + preTag: 'ABOVE', + sufTag: 'BELOW', midTag: 'SELECTION', } diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index a05522f2..4fcfeb79 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -445,7 +445,7 @@ const ChatBubble_ = ({ isEditMode, isLoading, children, role }: { role: ChatMess className={` relative ${isEditMode ? 'px-2 w-full max-w-full' - : role === 'user' ? `px-2 self-end w-fit max-w-full` + : role === 'user' ? `px-2 mt-4 self-end w-fit max-w-full` : role === 'assistant' ? `px-2 self-start w-full max-w-full` : '' } `} @@ -628,7 +628,7 @@ export const SidebarChat = () => { scrollContainerRef={scrollContainerRef} className={` w-full h-auto - flex flex-col gap-1 + flex flex-col overflow-x-hidden overflow-y-auto `}