diff --git a/core/commands/index.ts b/core/commands/index.ts index 7115d22be..6837449ef 100644 --- a/core/commands/index.ts +++ b/core/commands/index.ts @@ -1,6 +1,7 @@ import { CustomCommand, SlashCommand, SlashCommandDescription } from "../"; import { renderTemplatedString } from "../promptFiles/v1/renderTemplatedString"; import { replaceSlashCommandWithPromptInChatHistory } from "../promptFiles/v1/updateChatHistory"; +import { renderPromptFileV2 } from "../promptFiles/v2/renderPromptFile"; import { renderChatMessage } from "../util/messageContent"; import SlashCommands from "./slash"; @@ -15,7 +16,16 @@ export function slashFromCustomCommand( name: commandName, description: customCommand.description ?? "", prompt: customCommand.prompt, - run: async function* ({ input, llm, history, ide, completionOptions }) { + run: async function* ({ + input, + llm, + history, + ide, + completionOptions, + config, + selectedCode, + fetch, + }) { // Render prompt template let renderedPrompt: string; if (customCommand.prompt.includes("{{{ input }}}")) { @@ -25,7 +35,16 @@ export function slashFromCustomCommand( { input }, ); } else { - renderedPrompt = customCommand.prompt + "\n\n" + input; + renderedPrompt = await renderPromptFileV2(customCommand.prompt, { + config, + llm, + ide, + selectedCode, + fetch, + fullInput: input, + embeddingsProvider: config.modelsByRole.embed[0], + reranker: config.modelsByRole.rerank[0], + }); } // Replaces slash command messages with the rendered prompt diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index 6abd4927f..cfe3d409a 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -2,6 +2,7 @@ import { ContinueSDK, SlashCommand } from "../.."; import { renderChatMessage } from "../../util/messageContent"; import { getLastNPathParts } from "../../util/uri"; import { parsePromptFileV1V2 } from "../v2/parsePromptFileV1V2"; +import { renderPromptFileV2 } from "../v2/renderPromptFile"; import { getContextProviderHelpers } from "./getContextProviderHelpers"; import { renderTemplatedString } from "./renderTemplatedString"; @@ -67,7 +68,17 @@ export function slashCommandFromPromptFileV1( context.llm.systemMessage = systemMessage; const userInput = extractUserInput(context.input, name); - const renderedPrompt = await renderPromptV1(prompt, context, userInput); + const renderedPrompt = await renderPromptFileV2(prompt, { + config: context.config, + fullInput: userInput, + embeddingsProvider: context.config.modelsByRole.embed[0], + reranker: context.config.modelsByRole.rerank[0], + llm: context.llm, + ide: context.ide, + selectedCode: context.selectedCode, + fetch: context.fetch, + }); + const messages = replaceSlashCommandWithPromptInChatHistory( context.history, name, diff --git a/core/promptFiles/v2/renderPromptFile.ts b/core/promptFiles/v2/renderPromptFile.ts index 1f08011a8..c13a3ef93 100644 --- a/core/promptFiles/v2/renderPromptFile.ts +++ b/core/promptFiles/v2/renderPromptFile.ts @@ -65,8 +65,8 @@ async function resolveAttachment( export async function renderPromptFileV2( rawContent: string, extras: ContextProviderExtras, -): Promise<[ContextItem[], string]> { - const [preamble, body] = getPreambleAndBody(rawContent); +) { + const [_, body] = getPreambleAndBody(rawContent); const contextItemsPromises: Promise[] = []; const renderedBody = body.replace(/@([^\s]+)/g, (match, name) => { @@ -76,5 +76,9 @@ export async function renderPromptFileV2( const contextItems = (await Promise.all(contextItemsPromises)).flat(); - return [contextItems, renderedBody]; + return ( + contextItems.map((item) => item.content).join("\n\n") + + "\n\n" + + renderedBody + ); }