Skip to content

Commit

Permalink
Feat: --continue to use assistant prompt (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored May 27, 2024
1 parent 3071b17 commit 61b6d8a
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function makeArgs(argv = process.argv) {
out: { type: "string", short: "o" },
isolated: { type: "boolean", default: false, short: "i" },
combined: { type: "boolean", default: false },
continue: { type: "boolean", default: false },
"no-overwrite": { type: "boolean", default: false },
edit: { type: "boolean", default: false, short: "e" },
lines: { type: "string", default: "", short: "l" },
Expand Down Expand Up @@ -89,6 +90,7 @@ export function help() {
'folder' includes all files in the folder at the same level as the current file when generating. Default with --edit.
'none' includes no additional content (including no system context) when generating.
(note: context is separate from isolated. isolated: true with either 'content' or 'folder' will result in the same behavior with either. With 'none', Ailly will send _only_ the prompt when generating.)
--continue when a response is present, will include that response as the "assistant" message to begin inference from.
--clean resets all your ailly files to have no debug, no response, and minimal head matter settings.
-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.
Expand Down
1 change: 1 addition & 0 deletions cli/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function loadFs(
context: argContext,
isolated: args.values.isolated,
combined: args.values.combined,
continued: args.values.continue,
engine: args.values.engine,
model: args.values.model,
plugin: args.values.plugin,
Expand Down
1 change: 1 addition & 0 deletions core/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface ContentMeta {
text?: string;
context?: "conversation" | "folder" | "none";
parent?: "root" | "always" | "never";
continue?: boolean;
messages?: Message[];
skip?: boolean;
skipHead?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion core/src/engine/bedrock/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const generate: EngineGenerate<BedrockDebug> = (
});

try {
let message = "";
let message = c.meta?.continue ? c.response ?? "" : "";
const debug: BedrockDebug = {
id: "",
finish: "unknown",
Expand Down
9 changes: 5 additions & 4 deletions core/src/engine/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ export async function addContentMessages(
content.meta.messages = getMessagesFolder(content, context);
else content.meta.messages = getMessagesPredecessor(content, context);
let messages = content.meta.messages;
if (messages.at(-1)?.role == "assistant") {
if (
messages.at(-1)?.role == "assistant" &&
(content.context.edit || !content.meta.continue)
) {
messages.splice(-1, 1);
}
let fence: undefined | string = undefined;
if (content.context.edit) {
const lang = content.context.edit.file.split(".").at(-1) ?? "";
fence = "```" + lang;
messages.push({ role: "assistant", content: fence });
messages.push({ role: "assistant", content: "```" + lang });
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/engine/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const generate: EngineGenerate<OpenAIDebug> = (
};

try {
let message = "";
let message = c.meta?.continue ? c.response ?? "" : "";
let chunkNum = 0;
const stream = new TransformStream();

Expand Down
4 changes: 4 additions & 0 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface PipelineSettings {
isolated: boolean;
combined: boolean | undefined;
skipHead: boolean;
continue: boolean;
overwrite: boolean;
templateView: View;
}
Expand All @@ -47,6 +48,7 @@ export async function makePipelineSettings({
overwrite = true,
isolated = false,
skipHead = false,
continued = false,
combined,
templateView = {},
}: {
Expand All @@ -60,6 +62,7 @@ export async function makePipelineSettings({
isolated?: boolean;
combined?: boolean;
skipHead?: boolean;
continued?: boolean;
requestLimit?: number;
templateView?: View;
}): Promise<PipelineSettings> {
Expand All @@ -75,6 +78,7 @@ export async function makePipelineSettings({
requestLimit,
context: context as NonNullable<ContentMeta["context"]>,
plugin,
continue: continued,
overwrite,
isolated,
combined,
Expand Down
9 changes: 9 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"title": "Ailly: Clean",
"enablement": "explorerViewletFocus"
},
{
"command": "ailly.continue",
"title": "Ailly: Continue"
},
{
"command": "ailly.edit",
"title": "Ailly: Edit"
Expand All @@ -53,6 +57,11 @@
"command": "ailly.generate.all",
"group": "3_generate"
},
{
"command": "ailly.continue",
"group": "1_modification",
"when": "!explorerResourceIsFolder"
},
{
"command": "ailly.clean",
"group": "3_generate"
Expand Down
12 changes: 12 additions & 0 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export function activate(context: vscode.ExtensionContext) {
deep: true,
});

registerGenerateCommand(context, {
name: "continue",
manager: statusManager,
continued: true,
gerund: "continuing",
pastpart: "continued",
});

registerGenerateCommand(context, {
name: "clean",
manager: statusManager,
Expand Down Expand Up @@ -84,6 +92,7 @@ export function registerGenerateCommand(
edit = false,
clean = false,
deep = false,
continued = false,
gerund,
pastpart,
infinitive = name,
Expand All @@ -93,6 +102,7 @@ export function registerGenerateCommand(
clean?: boolean;
edit?: boolean;
deep?: boolean;
continued?: boolean;
gerund: string;
pastpart: string;
infinitive?: string;
Expand Down Expand Up @@ -137,6 +147,8 @@ export function registerGenerateCommand(
await generate(path, {
manager,
clean,
depth: deep ? Number.MAX_SAFE_INTEGER : 1,
continued,
extensionEdit,
});
vscode.window.showInformationMessage(`Ailly ${pastpart} ${base}`);
Expand Down
3 changes: 3 additions & 0 deletions extension/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export async function generate(
extensionEdit,
manager,
clean = false,
continued = false,
depth = 1,
}: {
extensionEdit?: ExtensionEdit;
manager: StatusManager;
clean?: boolean;
continued?: boolean;
depth?: number;
}
) {
Expand All @@ -58,6 +60,7 @@ export async function generate(
root,
out: root,
context: "folder",
continued,
engine,
model,
});
Expand Down
28 changes: 28 additions & 0 deletions integ/07_conversation_continue/conversation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -x
set -e

cd $(dirname $0)

rm -f ./out ./err
git restore ./root/01_a.txt.ailly.md

###

echo "continued conversation"
npx ailly --root ./root --log-format json --verbose --continue > >(tee ./out) 2> >(tee ./err >&2)
tail ./out ./err
[ ! -s ./err ] # No error output at all

MESSAGES=(
"user: File a"
"assistant: Continuing response"
)
for M in "${MESSAGES[@]}"; do
grep -q "$M" ./root/01_a.txt.ailly.md
done

echo "(continued conversation messages checked)"
rm -f ./out ./err
git restore ./root/01_a.txt.ailly.md
1 change: 1 addition & 0 deletions integ/07_conversation_continue/root/01_a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File a.
1 change: 1 addition & 0 deletions integ/07_conversation_continue/root/01_a.txt.ailly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Continuing response.

0 comments on commit 61b6d8a

Please sign in to comment.