fixie-ai / ai-jsx

The AI Application Framework for Javascript
https://docs.ai-jsx.com
MIT License
1.03k stars 76 forks source link

Fix memo bug, allow conversation rounds to run in parallel #503

Closed petersalas closed 7 months ago

petersalas commented 7 months ago

This change:

vercel[bot] commented 7 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-jsx-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2023 7:03pm
ai-jsx-nextjs-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2023 7:03pm
ai-jsx-tutorial-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2023 7:03pm
ai-jsx-voice ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2023 7:03pm
petersalas commented 7 months ago

Yeah it's sort of mind-bending and I have to constantly remind myself why it matters. The relevant difference between:

yield AI.AppendOnlyStream;
yield x;
yield y;

and

return [x, y]

is that in the top one, x will (might, depending on what the parent does) be rendered to completion before y starts being rendered, whereas in the second one they will render in parallel. What makes it especially mind-bending is that in this case y actually has an internal partial dependency on x. So the trick is to construct a render tree with inter-branch dependencies rather than inter-frame dependencies where possible.