Skip to content

Commit 07ed8e6

Browse files
committed
update with latest patches
1 parent c4edac6 commit 07ed8e6

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

typescript/packages/lookslike-high-level/src/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function addGems(gems: CellImpl<any>[]) {
3535
}
3636

3737
addGems([
38-
run(prompt, { title: "a whippet sleeping" }),
38+
run(prompt, { title: "a cute blue betta fish" }),
3939
run(todoList, {
4040
title: "My TODOs",
4141
items: ["Buy groceries", "Walk the dog", "Wash the car"].map((item) => ({
Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
11
import { html } from "@commontools/common-html";
2-
import { recipe, lift, NAME, UI } from "../builder/index.js";
2+
import {
3+
recipe,
4+
lift,
5+
generateData,
6+
handler,
7+
NAME,
8+
UI,
9+
ifElse,
10+
} from "../builder/index.js";
11+
import { run, getCellReferenceOrValue } from "../runner/index.js";
12+
import { openSaga, addGems, ID } from "../data.js";
313

414
export const prompt = recipe<{ title: string }>("prompt", ({ title }) => {
515
// this kinda makes sense but feels painful? better syntactic sugar?
6-
const url = lift<{ title: string }, string>(
16+
17+
const url = lift(
718
({ title }) =>
819
`https://ct-img.m4ke.workers.dev/?prompt=${encodeURIComponent(title)}`,
920
)({ title });
1021

22+
const query = lift(({ title }) => ({
23+
prompt: `generate 10 image prompt variations for the current prompt: ${title}. Some should change just the style, some should change the content, and some should change both.`,
24+
result: [],
25+
schema: {
26+
type: "array",
27+
items: {
28+
type: "object",
29+
properties: {
30+
title: {
31+
type: "string",
32+
description: "Image prompt",
33+
},
34+
},
35+
required: ["title"],
36+
},
37+
},
38+
}))({
39+
title,
40+
});
41+
42+
const { result: variations } = generateData<string[]>(query);
43+
44+
// const inner = ({ title }) => html`<div>${title}</div>`;
45+
const inner = ({ title }) => html` <common-button onclick=${handler(
46+
{ title },
47+
(_, { title }) => {
48+
const newPrompt = run(prompt, {
49+
title: getCellReferenceOrValue(title),
50+
});
51+
52+
addGems([newPrompt]);
53+
54+
openSaga(newPrompt.get()[ID]);
55+
},
56+
)}}">
57+
${title}
58+
</common-button>`;
59+
1160
return {
1261
[NAME]: title,
13-
[UI]: html`<div>
14-
Prompt: ${title}<br /><img src=${url} width="100%" />
15-
</div>`,
62+
[UI]: html`<common-vstack gap="sm">
63+
${title}
64+
<img src=${url} width="100%" />
65+
${ifElse(variations, variations.map(inner), html`<i></i>`)}
66+
</common-vstack>`,
1667
};
1768
});

0 commit comments

Comments
 (0)