Skip to content

Commit

Permalink
Add prompt templating and view coalescing.
Browse files Browse the repository at this point in the history
Closes #14.
  • Loading branch information
DavidSouther committed Apr 3, 2024
1 parent 487c592 commit 8a6a7b1
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 85 deletions.
4 changes: 2 additions & 2 deletions cli/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export async function loadFs(args) {

let content = await ailly.content.load(
fs,
[args.values.prompt ?? ""],
args.values.prompt ? [{ content: args.values.prompt, view: {} }] : [],
settings
);

if (isPipe) {
content.forEach(c => { c.meta = c.meta ?? {}; c.meta.skip = true; });
content.push({ name: 'stdout', outPath: "/dev/stdout", path: "/dev/stdout", prompt: args.values.prompt, predecessor: content.filter(c => dirname(c.path) == root).at(-1) })
content.push({ name: 'stdout', outPath: "/dev/stdout", path: "/dev/stdout", prompt: args.values.prompt, predecessor: content.filter(c => dirname(c.path) == root).at(-1), view: {} })
} else {
if (positionals.length == 0) positionals.push(root);
content = content.filter((c) =>
Expand Down
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function main() {
if (loaded.content.at(-1)?.outPath == "/dev/stdout") {
console.log(loaded.content.at(-1)?.response);
} else {
ailly.content.write(loaded.fs, loaded.content);
await ailly.content.write(loaded.fs, loaded.content);
}
break;
}
Expand Down
13 changes: 13 additions & 0 deletions content/35_templates/.aillyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
view:
project:
user: "You are a corporate marketing consultant."
overview: "The group works as an embedded team and views the clients' success as their own."
format:
ad_json: "Your output will be a JSON document with fields 'campaign_id' and 'ad_copy'."
---

{{project.user}}
{{project.overview}}
In this task, we are brainstorming for a corporate branding.
The brand is a new line of seltzer.
19 changes: 19 additions & 0 deletions content/35_templates/10_json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
combined: true
debug:
engine: bedrock
finish: end_turn
id: null
model: anthropic.claude-3-sonnet-20240229-v1:0
usage: null
isolated: false
prompt: |
{{claude.long}}
{{format.ad_json}}
Create an an ad spot for this product.
---
{
"campaign_id": "seltzerbrand_001",
"ad_copy": "Behold, a libation of unparalleled effervescence and refined taste, crafted with the utmost care and artistry. Our new line of seltzer beverages promises to elevate your senses and transport you to a realm of exquisite indulgence. Each delicate bubble bursts forth with a tantalizing bouquet of natural flavors, meticulously curated to tantalizing your palate. Embrace the epitome of sophisticated refreshment, a harmonious fusion of invigorating sparkle and sublime essence. Indulge in a sip that transcends the ordinary, and revel in the delightfully effervescent experience that awaits you."
}
22 changes: 19 additions & 3 deletions core/src/actions/prompt_thread.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { DEFAULT_LOGGER } from "@davidsouther/jiffies/lib/esm/log.js";
import { PipelineSettings } from "../ailly.js";
import type { Content } from "../content/content";
import type { Engine } from "../engine";
import type { Plugin } from "../plugin";
import { View, type Content } from "../content/content.js";
import type { Engine } from "../engine/index.js";
import type { Plugin } from "../plugin/index.js";
import {
GLOBAL_VIEW,
mergeContentViews,
mergeViews,
} from "../content/template.js";

export interface PromptThreadsSummary {
totalPrompts: number;
Expand Down Expand Up @@ -60,6 +65,8 @@ export class PromptThread {
return this.done && this.errors.length > 0;
}

private view: View;

static run(
content: Content[],
settings: PipelineSettings,
Expand All @@ -79,6 +86,10 @@ export class PromptThread {
) {
this.content = content;
this.isolated = Boolean(content[0]?.meta?.isolated ?? false);
this.view = mergeViews(
mergeViews(GLOBAL_VIEW, this.engine.view?.() ?? {}),
this.plugin.view?.() ?? {}
);
}

start() {
Expand All @@ -87,6 +98,7 @@ export class PromptThread {

private async runOne(c: Content, i: number): Promise<Content> {
try {
await this.template(c, this.view);
await this.plugin.augment(c);
await generateOne(c, this.settings, this.engine);
await this.plugin.clean(c);
Expand All @@ -99,6 +111,10 @@ export class PromptThread {
return c;
}

private async template(c: Content, view: View) {
mergeContentViews(c, view);
}

private runIsolated(): Promise<PromiseSettledResult<Content>[]> {
DEFAULT_LOGGER.info(
`Running thread for ${this.content.length} isolated prompts`
Expand Down
Loading

0 comments on commit 8a6a7b1

Please sign in to comment.