Skip to content

Commit

Permalink
Feat: warn when double prompt in combined: false
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed May 27, 2024
1 parent 146af8e commit d52dd8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions core/src/content/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ test("it loads content", async () => {
});
});

test("it loads prompt from head in combined: false", async () => {
const testFs = new FileSystem(
new ObjectFileSystemAdapter({
"a.md": "---\nprompt: prompt\n---\n",
})
);

const content = await loadContent(testFs, [], { combined: false });

expect(content["/a.md"].prompt).toBe("prompt");
});

test("it loads responses", async () => {
const testFs = new FileSystem(
new ObjectFileSystemAdapter({
Expand Down
12 changes: 11 additions & 1 deletion core/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,23 @@ async function loadFile(

let response: string | undefined;
let outPath: string;
if (data.prompt) {
const combined = head.combined ?? data.combined;
if (data.prompt && combined !== false) {
outPath = promptPath;
response = prompt;
data.combined = true;
prompt = data.prompt;
delete data.prompt;
} else {
if (data.prompt !== undefined) {
if (prompt.trim().length > 0) {
LOGGER.warn(`Head and body both have prompt, skipping ${file.name}`);
data.skip = true;
} else {
prompt = data.prompt;
}
}

outPath =
head.out === undefined || head.root === head.out
? promptPath
Expand Down

0 comments on commit d52dd8f

Please sign in to comment.