From 26ddd6418c02bf11a021d823178f62d94a185607 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Fri, 3 Jan 2025 16:54:04 -0800 Subject: [PATCH] extract result --- .../browser/helpers/extractCodeFromResult.ts | 54 +++++++++++++++++++ .../contrib/void/browser/prompt/prompts.ts | 34 ++++++------ .../void/browser/react/src/util/inputs.tsx | 1 - .../react/src/void-settings-tsx/Settings.tsx | 2 +- 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/helpers/extractCodeFromResult.ts b/src/vs/workbench/contrib/void/browser/helpers/extractCodeFromResult.ts index 048ebbfc..25801a19 100644 --- a/src/vs/workbench/contrib/void/browser/helpers/extractCodeFromResult.ts +++ b/src/vs/workbench/contrib/void/browser/helpers/extractCodeFromResult.ts @@ -3,10 +3,64 @@ * Void Editor additions licensed under the AGPL 3.0 License. *--------------------------------------------------------------------------------------------*/ + + + +export const extractArtificialFIMCodeFromResult = ({ text, preTag, sufTag, midTag }: { text: string, preTag: string, sufTag: string, midTag: string }) => { + + /* desired matches +` +`` +``` +< +

+

 a
+
 a 
+
 a 
< +
 a 
a
a a + +
 a 
 ->
+	*/
+
+
+	/* ------------- summary of the regex -------------
+		[optional ` | `` | ```]
+		(match optional_language_name)
+		[optional strings here]
+		[required  tag]
+		(match the stuff between mid tags)
+		[required  tag]
+		[optional ` | `` | ```]
+	*/
+
+	const regex = /[\s\S]*?(?:`{1,3}\s*([a-zA-Z_]+[\w]*)?[\s\S]*?)?([\s\S]*?)(?:|`{1,3}|$)/;
+
+	const match = text.match(regex);
+	if (match) {
+		const [_, languageName, codeBetweenMidTags] = match;
+		return [languageName, codeBetweenMidTags]
+
+	} else {
+		return [undefined, extractCodeFromResult(text)]
+	}
+
+}
+
+
+
 export const extractCodeFromResult = (result: string) => {
 	// Match either:
 	// 1. ```language\n```
 	// 2. ``````
+
+	// 4 
 A
+	// 3. 
 A 
B -> B const match = result.match(/```(?:\w+\n)?([\s\S]*?)```|```([\s\S]*?)```/); if (!match) { diff --git a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts index 8570fb1b..be1f0f6c 100644 --- a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts +++ b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts @@ -325,9 +325,9 @@ export const ctrlKStream_prefixAndSuffix = ({ fullFileStr, startLine, endLine }: } export const ctrlKStream_prompt = ({ selection, prefix, suffix, userMessage }: { selection: string, prefix: string, suffix: string, userMessage: string, }) => { - const onlySpeaksFIM = false + const modelWasTrainedOnFIM = false - if (onlySpeaksFIM) { + if (modelWasTrainedOnFIM) { const preTag = 'PRE' const sufTag = 'SUF' const midTag = 'MID' @@ -341,32 +341,34 @@ ${prefix} <${sufTag}>${suffix} <${midTag}>` } - // prompt the model on how to do FIM + // prompt the model artifically on how to do FIM else { - const preTag = 'PRE' - const sufTag = 'SUF' - const midTag = 'MID' + const preTag = 'BEFORE' + const sufTag = 'AFTER' + const midTag = 'SELECTION' return `\ -Here is the user's original selection: +The user is selecting this code as their SELECTION: \`\`\` <${midTag}>${selection} \`\`\` -The user wants to apply the following instructions to the selection: +The user wants to apply the following INSTRUCTIONS to the SELECTION: ${userMessage} -Please rewrite the selection following the user's instructions. +Please edit the SELECTION following the user's INSTRUCTIONS, and return the new SELECTION. -Instructions to follow: -1. Follow the user's instructions -2. You may ONLY CHANGE the selection, and nothing else in the file -3. Make sure all brackets in the new selection are balanced the same was as in the original selection -3. Be careful not to duplicate or remove variables, comments, or other syntax by mistake +Note that the SELECTION has code that comes before it. This code is indicated with <${preTag}>...before<${preTag}/>. +Note also that the SELECTION has code that comes after it. This code is indicated with <${sufTag}>...after<${sufTag}/>. + +Instructions: +1. Your OUTPUT should be a SINGLE PIECE OF CODE of the form <${midTag}>...new_selection<${midTag}/> +2. You may ONLY CHANGE the original SELECTION, and NOT the content in the <${preTag}>...<${preTag}/> or <${sufTag}>...<${sufTag}/> tags +3. Make sure all brackets in the new selection are balanced the same as in the original selection +4. Be careful not to duplicate or remove variables, comments, or other syntax by mistake Complete the following: <${preTag}>${prefix} -<${sufTag}>${suffix} -<${midTag}>` +<${sufTag}>${suffix}` } }; diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx index 3bdf4707..6319c1f0 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx @@ -303,7 +303,6 @@ export const VoidCodeEditor = ({ initValue, language }: { initValue: string, lan const instantiationService = accessor.get('IInstantiationService') const modelService = accessor.get('IModelService') const languageDetectionService = accessor.get('ILanguageDetectionService') - const themeService = accessor.get('IThemeService') initValue = normalizeIndentation(initValue) diff --git a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx index f7af5b15..94b14733 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx @@ -424,7 +424,7 @@ export const Settings = () => {

-

+

{/* TODO we should create UI for downloading models without user going into terminal */}