feat: fix ctx providers w/ slash cmds
This commit is contained in:
parent
400df1a51a
commit
e5608a94e5
3 changed files with 40 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<ContextItem[]>[] = [];
|
||||
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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue