Skip to content

Commit

Permalink
Add --skip-head/skipHead meta options, to streamline some bulk compar…
Browse files Browse the repository at this point in the history
…ison tasks.
  • Loading branch information
DavidSouther committed May 27, 2024
1 parent 146af8e commit b993317
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function makeArgs(argv = process.argv) {
"log-level": { type: "string", default: undefined },
"log-format": { type: "string", default: "pretty" },
verbose: { type: "boolean", default: false, short: "v" },
clean: { type: "boolean", default: false },
"skip-head": { type: "boolean", default: false },
},
});

Expand Down Expand Up @@ -90,6 +92,7 @@ export function help() {
-e, --edit use Ailly in edit mode. Provide a single file in paths, an edit marker, and a prompt. The path will be updated with the edit marker at the prompt.
-l, --lines the lines to edit as '[start]:[end]' with start inclusive, and end exclusive. With only '[start]', will insert after. With only ':[end]', will insert before.
--skip-head when printing
--engine will set the default engine. Can be set with AILLY_ENGINE environment variable. Default is bedrock. bedrock calls AWS Bedrock. noop is available for testing. (Probably? Check the code.)
--model will set the model from the engine. Can be set with AILLY_MODEL environment variable. Default depends on the engine; bedrock is anthropic.claude-3-sonnet-20240229-v1:0, OpenAI is gpt-4-0613. (Probably? Check the code.)
Expand Down
1 change: 1 addition & 0 deletions cli/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export async function loadFs(
templateView,
overwrite: !args.values["no-overwrite"],
requestLimit,
skipHead: args.values["skip-head"],
});

const system = args.values.system ?? "";
Expand Down
48 changes: 48 additions & 0 deletions core/src/content/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,54 @@ test("it writes deep java prompts and responses", async () => {
});
});

test("writes content and skips head", async () => {
const fs = new FileSystem(new ObjectFileSystemAdapter({}));

const content: WritableContent[] = [
{
name: "with-head.md",
path: "/with-head.md",
outPath: "/with-head.md.ailly.md",
prompt: "with-head",
response: "With Head",
context: { view: {} },
meta: { root: "/", debug: { engine: "test" } },
},
{
name: "without-head.md",
path: "/without-head.md",
outPath: "/without-head.md.ailly.md",
prompt: "without-head",
response: "Without Head",
context: { view: {} },
meta: { root: "/", debug: { engine: "test" }, skipHead: true },
},
{
name: "combined.md",
path: "/combined.md",
outPath: "/combined.md",
prompt: "combined",
response: "Combined",
context: { view: {} },
meta: {
combined: true,
root: "/",
debug: { engine: "test" },
skipHead: true,
},
},
];

await writeContent(fs, content);

expect((fs as any).adapter.fs).toEqual({
"/combined.md":
"---\ncombined: true\ndebug:\n engine: test\nprompt: combined\n---\nCombined",
"/with-head.md.ailly.md": "---\ndebug:\n engine: test\n---\nWith Head",
"/without-head.md.ailly.md": "Without Head",
});
});

describe("Load aillyrc", () => {
describe("parent = root (default)", () => {
test("at root with no .aillyrc in cwd", async () => {
Expand Down
6 changes: 5 additions & 1 deletion core/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface ContentMeta {
parent?: "root" | "always" | "never";
messages?: Message[];
skip?: boolean;
skipHead?: boolean;
isolated?: boolean;
combined?: boolean;
debug?: EngineDebug;
Expand Down Expand Up @@ -404,7 +405,10 @@ async function writeSingleContent(fs: FileSystem, content: WritableContent) {
lineWidth: 0,
sortMapEntries: true,
});
const file = (head === "{}\n" ? "" : `---\n${head}---\n`) + content.response;
const file =
(!combined && (content.meta?.skipHead || head === "{}\n")
? ""
: `---\n${head}---\n`) + content.response;
await fs.writeFile(path, file);
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface PipelineSettings {
plugin: string;
isolated: boolean;
combined: boolean | undefined;
skipHead: boolean;
overwrite: boolean;
templateView: View;
}
Expand All @@ -45,6 +46,7 @@ export async function makePipelineSettings({
plugin = DEFAULT_PLUGIN,
overwrite = true,
isolated = false,
skipHead = false,
combined,
templateView = {},
}: {
Expand All @@ -57,6 +59,7 @@ export async function makePipelineSettings({
overwrite?: boolean;
isolated?: boolean;
combined?: boolean;
skipHead?: boolean;
requestLimit?: number;
templateView?: View;
}): Promise<PipelineSettings> {
Expand All @@ -75,6 +78,7 @@ export async function makePipelineSettings({
overwrite,
isolated,
combined,
skipHead,
templateView,
};
}

0 comments on commit b993317

Please sign in to comment.