diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index d69730606..7b21232d6 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -51,16 +51,7 @@ function templateRendererOfModel( ): TemplateRenderer { let template = NEXT_EDIT_MODEL_TEMPLATES[modelName]; if (!template) { - // Check if modelName includes any known model name as substring. - const matchingModel = Object.keys(NEXT_EDIT_MODEL_TEMPLATES).find((key) => - modelName.includes(key), - ); - - if (matchingModel) { - template = NEXT_EDIT_MODEL_TEMPLATES[matchingModel as NextEditModelName]; - } else { - throw new Error(`Model ${modelName} is not supported for next edit.`); - } + throw new Error(`Model ${modelName} is not supported for next edit.`); } const compiledTemplate = Handlebars.compile(template.template); @@ -74,7 +65,7 @@ export function renderPrompt( helper: HelperVars, userEdits: string, ): UserPrompt { - const modelName = helper.modelName as NextEditModelName; + let modelName = helper.modelName as NextEditModelName; if (modelName === "this field is not used") { return { @@ -85,7 +76,18 @@ export function renderPrompt( // Validate that the modelName is actually a supported model. if (!Object.keys(NEXT_EDIT_MODEL_TEMPLATES).includes(modelName)) { - throw new Error(`${helper.modelName} is not yet supported for next edit.`); + // Check if modelName includes any known model name as substring. + const matchingModel = Object.keys(NEXT_EDIT_MODEL_TEMPLATES).find((key) => + modelName.includes(key), + ); + + if (matchingModel) { + modelName = matchingModel as NextEditModelName; + } else { + throw new Error( + `${helper.modelName} is not yet supported for next edit.`, + ); + } } const renderer = templateRendererOfModel(modelName);