diff --git a/example/vite-demo/colorgen/app.tsx b/example/vite-demo/colorgen/app.tsx index 2cf03a1..871219f 100644 --- a/example/vite-demo/colorgen/app.tsx +++ b/example/vite-demo/colorgen/app.tsx @@ -44,17 +44,15 @@ const view: View = { hex: ({ context, update, primary, a }) => { const assistant = context('You are a helpful coloring assistant.') - const [hexColor] = createSignal( - assistant`#${a(`shade of ${primary} as a hex rgb value`, { + const hexColor = assistant`#${a(`shade of ${primary} as a hex rgb value`, { stops: ['\n', ' '], maxTokens: 6, validate: { retries: 10, - check: x => x.length === 6 + check: (x) => x.match(/[0-9a-fA-F]{6}/) !== null, }, id: 'hex' })} ` - ) return ( { const assistant = context('You are a helpful coloring assistant.') - const [pickPrimaryColor] = createSignal( - assistant`Color: ${prompt('pick a primary color between red, green or blue', { + const pickPrimaryColor = assistant`Color: ${prompt('pick a primary color between red, green or blue', { sampler: model.bias.accept(sample.oneOf(['red\n', 'green\n', 'blue\n'])), stops: ['\n'], id: 'color' })}` - ) return ( + template: Template onComplete: (refs: any) => any }) { const [canCancel, setCanCancel] = createSignal(true) @@ -12,34 +12,28 @@ export default function ShowInfer({ template, onComplete, showTemplate }: { const [templateText, setTemplateText] = createSignal('') const [partials, setPartials] = createSignal([]) - createEffect(() => { - setPartials([]) + template.collect_refs(partial => { + switch (partial.type) { + case 'ungen': + setPartials([...partials().slice(0, -partial.tokenCount)]) + break + case 'lit': + case 'gen': + setPartials([...partials(), partial]) - template().collect_refs(partial => { - switch (partial.type) { - case 'ungen': - setPartials([...partials().slice(0, -partial.tokenCount)]) - break - case 'lit': - case 'gen': - setPartials([...partials(), partial]) + if (partial.type === 'gen') { + setPrompt(partial.prompt) + } - if (partial.type === 'gen') { - setPrompt(partial.prompt) - } - - break - case 'template': - setTemplateText(partial.content) - break - } - }).then(results => { - setCanCancel(false) - onComplete(results) - }) - - console.log('showinfer', template()) - }) + break + case 'template': + setTemplateText(partial.content) + break + } + }).then(results => { + setCanCancel(false) + onComplete(results) + }) return (
@@ -56,7 +50,7 @@ export default function ShowInfer({ template, onComplete, showTemplate }: {
- +