🐛 add context items to /edit prompt
This commit is contained in:
parent
eb67849ac0
commit
19282ccf55
2 changed files with 17 additions and 9 deletions
|
|
@ -230,13 +230,18 @@ const EditSlashCommand: SlashCommand = {
|
|||
}
|
||||
|
||||
// Strip unecessary parts of the input (the fact that you have to do this is suboptimal, should be refactored away)
|
||||
input = input.replace(
|
||||
let content = history[history.length - 1].content;
|
||||
if (typeof content !== "string") {
|
||||
content.forEach((part) => {
|
||||
if (part.text && part.text.startsWith("/edit")) {
|
||||
part.text = part.text.replace("/edit", "").trimStart();
|
||||
}
|
||||
})
|
||||
}
|
||||
let userInput = stripImages(content).replace(
|
||||
`\`\`\`${contextItemToEdit.name}\n${contextItemToEdit.content}\n\`\`\`\n`,
|
||||
""
|
||||
);
|
||||
if (input.startsWith("/edit")) {
|
||||
input = input.replace("/edit", "").trimStart();
|
||||
}
|
||||
|
||||
const rif: RangeInFileWithContents =
|
||||
contextItemToRangeInFileWithContents(contextItemToEdit);
|
||||
|
|
@ -248,14 +253,14 @@ const EditSlashCommand: SlashCommand = {
|
|||
rif,
|
||||
fullFileContents,
|
||||
llm,
|
||||
input,
|
||||
userInput,
|
||||
params?.tokenLimit
|
||||
);
|
||||
const [dedentedContents, commonWhitespace] =
|
||||
dedentAndGetCommonWhitespace(contents);
|
||||
contents = dedentedContents;
|
||||
|
||||
let prompt = compilePrompt(filePrefix, contents, fileSuffix, input);
|
||||
let prompt = compilePrompt(filePrefix, contents, fileSuffix, userInput);
|
||||
let fullFileContentsLines = fullFileContents.split("\n");
|
||||
let fullPrefixLines = fullFileContentsLines.slice(
|
||||
0,
|
||||
|
|
@ -447,7 +452,7 @@ const EditSlashCommand: SlashCommand = {
|
|||
messages.slice(0, messages.length - 1),
|
||||
{
|
||||
codeToEdit: rif.contents,
|
||||
userInput: input,
|
||||
userInput,
|
||||
filePrefix: filePrefix,
|
||||
fileSuffix: fileSuffix,
|
||||
systemMessage: llm.systemMessage || "",
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ async function resolveEditorContent(
|
|||
for (const p of editorState?.content) {
|
||||
if (p.type === "paragraph") {
|
||||
const [text, ctxItems, foundSlashCommand] = resolveParagraph(p);
|
||||
|
||||
// Only take the first slash command
|
||||
if (foundSlashCommand && typeof slashCommand === "undefined") {
|
||||
slashCommand = foundSlashCommand;
|
||||
}
|
||||
|
|
@ -92,8 +94,9 @@ async function resolveEditorContent(
|
|||
if (item.itemType === "file") {
|
||||
// This is a quick way to resolve @file references
|
||||
const basename = getBasename(item.id);
|
||||
const content = await ide.readFile(item.id);
|
||||
contextItemsText += `\`\`\`title="${basename}"\n${content}\n\`\`\`\n`;
|
||||
const rawContent = await ide.readFile(item.id);
|
||||
const content = `\`\`\`title="${basename}"\n${rawContent}\n\`\`\`\n`;
|
||||
contextItemsText += content
|
||||
contextItems.push({
|
||||
name: basename,
|
||||
description: item.id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue