Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
/cookbook: opt-in live-calls gate, retryAfter-honoring polls, richer guide; fix broken architecture SVG path
nirholasde52b0858b45
diff --git a/public/cookbook/houseplant-set.png b/public/cookbook/houseplant-set.pngnew file mode 100644index 000000000..a03d0c65bBinary files /dev/null and b/public/cookbook/houseplant-set.png differdiff --git a/public/cookbook/index.html b/public/cookbook/index.htmlindex 7ada9c39e..cc66e9b07 100644--- a/public/cookbook/index.html+++ b/public/cookbook/index.html@@ -7855,7 +7855,11 @@ downloadable 3D objects, and then turns the model's vision on its own output.That generate, render, inspect, repair loop is the shape you need any time atool's output is generative and can silently miss: image generation, chartrendering, UI screenshots, 3D.</p>-<p><img alt="Pipeline architecture: a one-line brief goes to a gpt-5-mini art director, which issues parallel function calls to the keyless three.ws text-to-3D API; each GLB is rendered to a PNG and inspected by a vision critic returning a structured verdict; failed props are rebuilt once from the critic's revised prompt; passing props render in an interactive 3D gallery" src="../../images/threews_self_correcting_3d_pipeline.svg"/></p>+<p><img alt="Pipeline architecture: a one-line brief goes to a gpt-5-mini art director, which issues parallel function calls to the keyless three.ws text-to-3D API; each GLB is rendered to a PNG and inspected by a vision critic returning a structured verdict; failed props are rebuilt once from the critic's revised prompt; passing props render in an interactive 3D gallery" src="/cookbook/pipeline.svg"/></p>+<p>The committed run below turns the one-line brief "chunky potted houseplants+for a sunny windowsill" into this set, with the one prop that failed vision QA+rebuilt from the critic's own revised prompt:</p>+<p><img alt="The finished houseplant set after vision QA: six potted plants generated from one brief, with the failed golden barrel cactus rebuilt from the critic's revised prompt" src="/cookbook/houseplant-set.png"/></p><h2 id="What-you'll-learn">What you'll learn<a class="anchor-link" href="#What-you'll-learn">¶</a></h2><ol><li>Wrap an external REST API as a <strong>function tool</strong> and describe it so the modelproduces clean arguments.</li>@@ -7874,19 +7878,49 @@ endpoint. It runs an open text-to-3D model (Microsoftstandard <a href="https://www.khronos.org/gltf/">glTF 2.0</a> <code>.glb</code>. The QA step uses asecond keyless endpoint from the same API, which renders any GLB to a PNG.Neither needs an account or API key, so both are free to run.</p>-<h2 id="Prerequisites">Prerequisites<a class="anchor-link" href="#Prerequisites">¶</a></h2><ul>-<li>Python 3.10+ and an OpenAI API key set as the <code>OPENAI_API_KEY</code> environment-variable (used only for the model's reasoning and vision).</li>-<li>The <code>openai</code>, <code>requests</code>, and <code>pillow</code> packages (installed below).</li>-<li>To interact with the 3D gallery (orbit, zoom, AR), run the notebook in an-environment that renders HTML output (Jupyter, JupyterLab, VS Code, or-Colab). Every gallery also bakes a static contact sheet into the notebook,-so the results stay visible in static views like GitHub.</li>-<li>A full run takes roughly 10 to 15 minutes end to end. Almost all of it is-3D generation time (about 30 to 90 seconds per prop, run in parallel);-model usage is a few cents with <code>gpt-5-mini</code>, and both 3D endpoints are-free.</li>-</ul>+<h2 id="Prerequisites">Prerequisites<a class="anchor-link" href="#Prerequisites">¶</a></h2><table>+<thead>+<tr>+<th>You need</th>+<th>Used for</th>+<th>Notes</th>+</tr>+</thead>+<tbody>+<tr>+<td>Python 3.10+</td>+<td>running the notebook</td>+<td>the tool wrappers use <code>str \| None</code> union annotations</td>+</tr>+<tr>+<td><code>OPENAI_API_KEY</code></td>+<td>the art director's reasoning and vision QA</td>+<td>a full run costs a few cents with <code>gpt-5-mini</code></td>+</tr>+<tr>+<td><code>openai</code>, <code>requests</code>, <code>pillow</code></td>+<td>API clients and PNG contact sheets</td>+<td>installed by the first cell</td>+</tr>+<tr>+<td>An HTML-rendering environment</td>+<td>the interactive 3D galleries (orbit, zoom, AR)</td>+<td>Jupyter, JupyterLab, VS Code, or Colab; static views like GitHub see the baked PNG contact sheets instead</td>+</tr>+<tr>+<td>A three.ws account</td>+<td>nothing</td>+<td>both 3D endpoints are keyless and free; there is nothing to sign up for</td>+</tr>+</tbody>+</table>+<p><strong>The notebook ships fully executed, and live calls are opt-in.</strong> Every result+below is real committed output from a live run, readable without executing+anything. The <code>RUN_LIVE</code> flag in the Setup cell (default <code>False</code>) gates every+cell that calls an external service, so a plain Run All makes no network calls+beyond <code>pip</code>; flip the flag to <code>True</code> to reproduce the pipeline yourself. A+live run takes roughly 10 to 15 minutes end to end, almost all of it 3D+generation time (about 30 to 90 seconds per prop, run in parallel).</p></div></div></div>@@ -7961,6 +7995,16 @@ free.</li><span class="n">MODEL</span> <span class="o">=</span> <span class="s2">"gpt-5-mini"</span> <span class="c1"># any vision-capable, tool-calling model works</span><span class="n">THREE_WS_BASE</span> <span class="o">=</span> <span class="s2">"https://three.ws"</span>+<span class="c1"># -- Live-calls switch --------------------------------------------------------</span>+<span class="c1"># Running this notebook drives two live external services: the keyless three.ws</span>+<span class="c1"># text-to-3D and render endpoints (free, no account) and the OpenAI API (your</span>+<span class="c1"># OPENAI_API_KEY; a few cents with gpt-5-mini). The notebook ships fully</span>+<span class="c1"># executed, so every result is readable below without running anything. Flip to</span>+<span class="c1"># True to opt in and reproduce the whole pipeline yourself.</span>+<span class="n">RUN_LIVE</span> <span class="o">=</span> <span class="kc">False</span>++<span class="n">SKIP_NOTE</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"RUN_LIVE is False: this cell kept its committed results instead of "</span>+ <span class="s2">"calling the live services. Set RUN_LIVE = True in the Setup cell to run it."</span><span class="p">)</span></pre></div></div></div>@@ -8033,11 +8077,20 @@ real function the model will call, no mocking.</p><span class="n">deadline</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout_s</span><span class="k">while</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"status"</span><span class="p">)</span> <span class="o">==</span> <span class="s2">"pending"</span> <span class="ow">and</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o"><</span> <span class="n">deadline</span><span class="p">:</span>- <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>+ <span class="c1"># Every pending response carries a retryAfter poll-cadence hint in</span>+ <span class="c1"># seconds; honoring it is what keeps the poll from tripping the</span>+ <span class="c1"># lane's rate limit in the first place.</span>+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"retryAfter"</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">3</span><span class="p">),</span> <span class="mi">30</span><span class="p">))</span><span class="n">job</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"job"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"jobId"</span><span class="p">)</span><span class="n">poll</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">THREE_WS_BASE</span><span class="si">}</span><span class="s2">/api/3d/generate"</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">{</span><span class="s2">"job"</span><span class="p">:</span> <span class="n">job</span><span class="p">},</span> <span class="n">timeout</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">60</span><span class="p">)</span><span class="p">)</span>+ <span class="k">if</span> <span class="n">poll</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">429</span><span class="p">:</span>+ <span class="c1"># Rate-limited mid-poll: wait out Retry-After and keep polling</span>+ <span class="c1"># the SAME job. Raising here would restart the whole submit and</span>+ <span class="c1"># duplicate the generation.</span>+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">poll</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"retry-after"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"15"</span><span class="p">),</span> <span class="mi">120</span><span class="p">))</span>+ <span class="k">continue</span><span class="n">poll</span><span class="o">.</span><span class="n">raise_for_status</span><span class="p">()</span><span class="n">data</span> <span class="o">=</span> <span class="n">poll</span><span class="o">.</span><span class="n">json</span><span class="p">()</span><span class="k">return</span> <span class="n">data</span>@@ -8267,16 +8320,19 @@ the batch. Every model below was generated live by this cell.</p><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">" skipped </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">err</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span><span class="k">return</span> <span class="kc">None</span>-<span class="k">with</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>- <span class="n">study</span> <span class="o">=</span> <span class="p">[</span><span class="n">m</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">safe_generate</span><span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="p">),</span> <span class="n">PROPS</span><span class="p">)</span> <span class="k">if</span> <span class="n">m</span><span class="p">]</span>--<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"generated </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">study</span><span class="p">)</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">PROPS</span><span class="p">)</span><span class="si">}</span><span class="s2"> props"</span><span class="p">)</span>-<span class="n">render_models</span><span class="p">(</span>- <span class="n">study</span><span class="p">,</span>- <span class="n">title</span><span class="o">=</span><span class="s2">"A wizard's study"</span><span class="p">,</span>- <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Four props, one sentence each, generated on the free three.ws draft "</span>- <span class="s2">"lane and rendered inline. Drag to orbit; tap AR on a phone."</span><span class="p">,</span>-<span class="p">)</span>+<span class="k">if</span> <span class="n">RUN_LIVE</span><span class="p">:</span>+ <span class="k">with</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>+ <span class="n">study</span> <span class="o">=</span> <span class="p">[</span><span class="n">m</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">safe_generate</span><span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="p">),</span> <span class="n">PROPS</span><span class="p">)</span> <span class="k">if</span> <span class="n">m</span><span class="p">]</span>++ <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"generated </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">study</span><span class="p">)</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">PROPS</span><span class="p">)</span><span class="si">}</span><span class="s2"> props"</span><span class="p">)</span>+ <span class="n">render_models</span><span class="p">(</span>+ <span class="n">study</span><span class="p">,</span>+ <span class="n">title</span><span class="o">=</span><span class="s2">"A wizard's study"</span><span class="p">,</span>+ <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Four props, one sentence each, generated on the free three.ws draft "</span>+ <span class="s2">"lane and rendered inline. Drag to orbit; tap AR on a phone."</span><span class="p">,</span>+ <span class="p">)</span>+<span class="k">else</span><span class="p">:</span>+ <span class="nb">print</span><span class="p">(</span><span class="n">SKIP_NOTE</span><span class="p">)</span></pre></div></div></div>@@ -8551,14 +8607,17 @@ own brief in the last line:</p><span class="p">)</span><span class="n">THEME</span> <span class="o">=</span> <span class="s2">"A windowsill of houseplants"</span> <span class="c1"># gallery headline; keep it matching the brief</span>-<span class="n">collection</span> <span class="o">=</span> <span class="n">run_art_director</span><span class="p">(</span><span class="n">WINDOWSILL_BRIEF</span><span class="p">)</span>+<span class="k">if</span> <span class="n">RUN_LIVE</span><span class="p">:</span>+ <span class="n">collection</span> <span class="o">=</span> <span class="n">run_art_director</span><span class="p">(</span><span class="n">WINDOWSILL_BRIEF</span><span class="p">)</span>-<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Art director:"</span><span class="p">,</span> <span class="n">collection</span><span class="p">[</span><span class="s2">"reply"</span><span class="p">])</span>-<span class="n">render_models</span><span class="p">(</span>- <span class="n">collection</span><span class="p">[</span><span class="s2">"items"</span><span class="p">],</span>- <span class="n">title</span><span class="o">=</span><span class="n">THEME</span><span class="p">,</span>- <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Designed and built by the model from a single-line brief."</span><span class="p">,</span>-<span class="p">)</span>+ <span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Art director:"</span><span class="p">,</span> <span class="n">collection</span><span class="p">[</span><span class="s2">"reply"</span><span class="p">])</span>+ <span class="n">render_models</span><span class="p">(</span>+ <span class="n">collection</span><span class="p">[</span><span class="s2">"items"</span><span class="p">],</span>+ <span class="n">title</span><span class="o">=</span><span class="n">THEME</span><span class="p">,</span>+ <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Designed and built by the model from a single-line brief."</span><span class="p">,</span>+ <span class="p">)</span>+<span class="k">else</span><span class="p">:</span>+ <span class="nb">print</span><span class="p">(</span><span class="n">SKIP_NOTE</span><span class="p">)</span></pre></div></div></div>@@ -8958,15 +9017,18 @@ survive script-free views too.</p><span class="n">display</span><span class="p">(</span><span class="n">Image</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">png</span><span class="p">))</span>-<span class="k">with</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>- <span class="n">inspected</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">item</span><span class="p">:</span> <span class="n">inspect_model</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">WINDOWSILL_BRIEF</span><span class="p">),</span>- <span class="n">collection</span><span class="p">[</span><span class="s2">"items"</span><span class="p">]))</span>+<span class="k">if</span> <span class="n">RUN_LIVE</span><span class="p">:</span>+ <span class="k">with</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>+ <span class="n">inspected</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">item</span><span class="p">:</span> <span class="n">inspect_model</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">WINDOWSILL_BRIEF</span><span class="p">),</span>+ <span class="n">collection</span><span class="p">[</span><span class="s2">"items"</span><span class="p">]))</span>-<span class="n">render_verdicts</span><span class="p">(</span>- <span class="n">inspected</span><span class="p">,</span>- <span class="n">title</span><span class="o">=</span><span class="s2">"What the critic saw"</span><span class="p">,</span>- <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Each card is the exact image the model inspected, with its structured verdict."</span><span class="p">,</span>-<span class="p">)</span>+ <span class="n">render_verdicts</span><span class="p">(</span>+ <span class="n">inspected</span><span class="p">,</span>+ <span class="n">title</span><span class="o">=</span><span class="s2">"What the critic saw"</span><span class="p">,</span>+ <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Each card is the exact image the model inspected, with its structured verdict."</span><span class="p">,</span>+ <span class="p">)</span>+<span class="k">else</span><span class="p">:</span>+ <span class="nb">print</span><span class="p">(</span><span class="n">SKIP_NOTE</span><span class="p">)</span></pre></div></div></div>@@ -9110,17 +9172,20 @@ human.</p><span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">fix</span><span class="p">,</span> <span class="n">inspected</span><span class="p">))</span>-<span class="n">windowsill_final</span> <span class="o">=</span> <span class="n">repair</span><span class="p">(</span><span class="n">inspected</span><span class="p">,</span> <span class="n">WINDOWSILL_BRIEF</span><span class="p">)</span>+<span class="k">if</span> <span class="n">RUN_LIVE</span><span class="p">:</span>+ <span class="n">windowsill_final</span> <span class="o">=</span> <span class="n">repair</span><span class="p">(</span><span class="n">inspected</span><span class="p">,</span> <span class="n">WINDOWSILL_BRIEF</span><span class="p">)</span>-<span class="n">passed</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">windowsill_final</span> <span class="k">if</span> <span class="n">it</span><span class="p">[</span><span class="s2">"verdict"</span><span class="p">][</span><span class="s2">"passed"</span><span class="p">])</span>-<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">passed</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">windowsill_final</span><span class="p">)</span><span class="si">}</span><span class="s2"> props pass QA after repair"</span><span class="p">)</span>-<span class="n">render_models</span><span class="p">(</span>- <span class="p">[{</span><span class="o">**</span><span class="n">it</span><span class="p">,</span> <span class="s2">"name"</span><span class="p">:</span> <span class="n">it</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="s2">" · rebuilt"</span> <span class="k">if</span> <span class="n">it</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"repaired"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">""</span><span class="p">)}</span>- <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">windowsill_final</span><span class="p">],</span>- <span class="n">title</span><span class="o">=</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">THEME</span><span class="si">}</span><span class="s2">, after QA"</span><span class="p">,</span>- <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Every prop was inspected by the model; failures were rebuilt from "</span>- <span class="s2">"the critic's own revised prompt."</span><span class="p">,</span>-<span class="p">)</span>+ <span class="n">passed</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">windowsill_final</span> <span class="k">if</span> <span class="n">it</span><span class="p">[</span><span class="s2">"verdict"</span><span class="p">][</span><span class="s2">"passed"</span><span class="p">])</span>+ <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">passed</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">windowsill_final</span><span class="p">)</span><span class="si">}</span><span class="s2"> props pass QA after repair"</span><span class="p">)</span>+ <span class="n">render_models</span><span class="p">(</span>+ <span class="p">[{</span><span class="o">**</span><span class="n">it</span><span class="p">,</span> <span class="s2">"name"</span><span class="p">:</span> <span class="n">it</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="s2">" · rebuilt"</span> <span class="k">if</span> <span class="n">it</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"repaired"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">""</span><span class="p">)}</span>+ <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">windowsill_final</span><span class="p">],</span>+ <span class="n">title</span><span class="o">=</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">THEME</span><span class="si">}</span><span class="s2">, after QA"</span><span class="p">,</span>+ <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Every prop was inspected by the model; failures were rebuilt from "</span>+ <span class="s2">"the critic's own revised prompt."</span><span class="p">,</span>+ <span class="p">)</span>+<span class="k">else</span><span class="p">:</span>+ <span class="nb">print</span><span class="p">(</span><span class="n">SKIP_NOTE</span><span class="p">)</span></pre></div></div></div>@@ -9265,13 +9330,16 @@ the cell to copy into your own project.</p><span class="k">return</span> <span class="n">final</span>-<span class="n">cabin</span> <span class="o">=</span> <span class="n">build_set</span><span class="p">(</span><span class="s2">"Design a collectible set for a deep-sea explorer's cabin."</span><span class="p">)</span>-<span class="n">render_models</span><span class="p">(</span>- <span class="n">cabin</span><span class="p">,</span>- <span class="n">title</span><span class="o">=</span><span class="s2">"A deep-sea explorer's cabin"</span><span class="p">,</span>- <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Art-directed, built, inspected, and repaired by the model from "</span>- <span class="s2">"one sentence. Drag to orbit; tap AR on a phone."</span><span class="p">,</span>-<span class="p">)</span>+<span class="k">if</span> <span class="n">RUN_LIVE</span><span class="p">:</span>+ <span class="n">cabin</span> <span class="o">=</span> <span class="n">build_set</span><span class="p">(</span><span class="s2">"Design a collectible set for a deep-sea explorer's cabin."</span><span class="p">)</span>+ <span class="n">render_models</span><span class="p">(</span>+ <span class="n">cabin</span><span class="p">,</span>+ <span class="n">title</span><span class="o">=</span><span class="s2">"A deep-sea explorer's cabin"</span><span class="p">,</span>+ <span class="n">subtitle</span><span class="o">=</span><span class="s2">"Art-directed, built, inspected, and repaired by the model from "</span>+ <span class="s2">"one sentence. Drag to orbit; tap AR on a phone."</span><span class="p">,</span>+ <span class="p">)</span>+<span class="k">else</span><span class="p">:</span>+ <span class="nb">print</span><span class="p">(</span><span class="n">SKIP_NOTE</span><span class="p">)</span></pre></div></div></div>@@ -9425,6 +9493,140 @@ If you want variations (e.g., more weathering, different color palette, high-pol</div></div></div>+<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5353acbd">+<div class="jp-Cell-inputWrapper" tabindex="0">+<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">+</div>+<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">+</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">+<h2 id="Error-handling-and-troubleshooting">Error handling and troubleshooting<a class="anchor-link" href="#Error-handling-and-troubleshooting">¶</a></h2><p>Every failure path in this notebook is handled where it occurs, so a run+degrades instead of crashing. What that looks like in practice:</p>+<table>+<thead>+<tr>+<th>Symptom</th>+<th>Cause</th>+<th>What the notebook does</th>+</tr>+</thead>+<tbody>+<tr>+<td><code>429</code> on submit or poll</td>+<td>per-IP rate limit on the free lane</td>+<td>honors the <code>Retry-After</code> header, then retries; mid-poll it keeps waiting on the <strong>same</strong> job rather than resubmitting it</td>+</tr>+<tr>+<td><code>502</code> / <code>503</code> / <code>504</code></td>+<td>brief GPU-lane saturation</td>+<td>retries the generation up to 3 times with a pause between attempts</td>+</tr>+<tr>+<td>A job stays <code>pending</code> past the timeout</td>+<td>long queue on the free lane</td>+<td>raises <code>GenerationError</code>; inside the art-director loop that error is reported back to the model as the tool result instead of crashing the run</td>+</tr>+<tr>+<td>Other <code>4xx</code> on submit</td>+<td>prompt rejected by the lane</td>+<td>not retried; surfaces immediately so you can fix the prompt</td>+</tr>+<tr>+<td>Render endpoint unavailable</td>+<td>the QA snapshot call failed</td>+<td>QA <strong>fails open</strong>: the prop is kept and marked passed, because a guardrail that can take down the pipeline it guards is worse than no guardrail</td>+</tr>+<tr>+<td>A rebuild fails</td>+<td>the repair generation itself errored</td>+<td>keeps the original draft prop and its original verdict</td>+</tr>+</tbody>+</table>+</div>+</div>+</div>+</div>+<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5d9ea790">+<div class="jp-Cell-inputWrapper" tabindex="0">+<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">+</div>+<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">+</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">+<h2 id="Production-checklist">Production checklist<a class="anchor-link" href="#Production-checklist">¶</a></h2><p>Promoting this pattern from a notebook into a service? Check these first:</p>+<table>+<thead>+<tr>+<th>Area</th>+<th>Check</th>+</tr>+</thead>+<tbody>+<tr>+<td>Budgets</td>+<td>every loop here is bounded (one art-director conversation, one repair per prop, three submit attempts); keep it that way when you raise the limits</td>+</tr>+<tr>+<td>Poll cadence</td>+<td>keep honoring <code>retryAfter</code> / <code>Retry-After</code>; a fleet of impatient pollers is indistinguishable from an attack</td>+</tr>+<tr>+<td>Caching</td>+<td><code>glbUrl</code> results are immutable; cache them keyed by prompt so repeat briefs and retried jobs cost nothing</td>+</tr>+<tr>+<td>Concurrency</td>+<td>the free draft lane is per-IP rate-limited; keep <code>max_workers</code> modest (four here) or move to a keyed lane</td>+</tr>+<tr>+<td>Fidelity</td>+<td>the draft lane is single-subject and unrigged by design; three.ws serves higher-poly PBR and rigged lanes with the same tool shape when quality matters</td>+</tr>+<tr>+<td>Evals</td>+<td>log every structured verdict; the pass rate over time is a free model-graded eval of your whole asset pipeline</td>+</tr>+</tbody>+</table>+</div>+</div>+</div>+</div>+<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=522f1f1c">+<div class="jp-Cell-inputWrapper" tabindex="0">+<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">+</div>+<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">+</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">+<h2 id="When-to-use-this-pattern">When to use this pattern<a class="anchor-link" href="#When-to-use-this-pattern">¶</a></h2><table>+<thead>+<tr>+<th>Use generate / render / inspect / repair when</th>+<th>Skip it when</th>+</tr>+</thead>+<tbody>+<tr>+<td>the tool's output is <strong>generative</strong> and can miss silently (3D, images, charts, UI code)</td>+<td>the tool returns deterministic data (a database row, a price); validate with schemas instead</td>+</tr>+<tr>+<td>quality is judged visually, so only a vision pass can grade it</td>+<td>correctness is checkable in code (types, ranges, invariants)</td>+</tr>+<tr>+<td>a retry with a better prompt plausibly fixes a failure</td>+<td>failures need a human decision, not a rewrite</td>+</tr>+<tr>+<td>you can afford one render and one vision call per artifact</td>+<td>you are latency-bound and would rather ship drafts than gate on QA</td>+</tr>+</tbody>+</table>+</div>+</div>+</div>+</div><div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=6060491e"><div class="jp-Cell-inputWrapper" tabindex="0"><div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">diff --git a/public/cookbook/text_to_3d_with_function_calling.ipynb b/public/cookbook/text_to_3d_with_function_calling.ipynbindex 8fb5f6be3..c3bc94914 100644--- a/public/cookbook/text_to_3d_with_function_calling.ipynb+++ b/public/cookbook/text_to_3d_with_function_calling.ipynb@@ -34,6 +34,12 @@"\n","\n","\n",+ "The committed run below turns the one-line brief \"chunky potted houseplants\n",+ "for a sunny windowsill\" into this set, with the one prop that failed vision QA\n",+ "rebuilt from the critic's own revised prompt:\n",+ "\n",+ "\n",+ "\n","## What you'll learn\n","\n","1. Wrap an external REST API as a **function tool** and describe it so the model\n",@@ -58,17 +64,21 @@"\n","## Prerequisites\n","\n",- "- Python 3.10+ and an OpenAI API key set as the `OPENAI_API_KEY` environment\n",- " variable (used only for the model's reasoning and vision).\n",- "- The `openai`, `requests`, and `pillow` packages (installed below).\n",- "- To interact with the 3D gallery (orbit, zoom, AR), run the notebook in an\n",- " environment that renders HTML output (Jupyter, JupyterLab, VS Code, or\n",- " Colab). Every gallery also bakes a static contact sheet into the notebook,\n",- " so the results stay visible in static views like GitHub.\n",- "- A full run takes roughly 10 to 15 minutes end to end. Almost all of it is\n",- " 3D generation time (about 30 to 90 seconds per prop, run in parallel);\n",- " model usage is a few cents with `gpt-5-mini`, and both 3D endpoints are\n",- " free."+ "| You need | Used for | Notes |\n",+ "|---|---|---|\n",+ "| Python 3.10+ | running the notebook | the tool wrappers use `str \\| None` union annotations |\n",+ "| `OPENAI_API_KEY` | the art director's reasoning and vision QA | a full run costs a few cents with `gpt-5-mini` |\n",+ "| `openai`, `requests`, `pillow` | API clients and PNG contact sheets | installed by the first cell |\n",+ "| An HTML-rendering environment | the interactive 3D galleries (orbit, zoom, AR) | Jupyter, JupyterLab, VS Code, or Colab; static views like GitHub see the baked PNG contact sheets instead |\n",+ "| A three.ws account | nothing | both 3D endpoints are keyless and free; there is nothing to sign up for |\n",+ "\n",+ "**The notebook ships fully executed, and live calls are opt-in.** Every result\n",+ "below is real committed output from a live run, readable without executing\n",+ "anything. The `RUN_LIVE` flag in the Setup cell (default `False`) gates every\n",+ "cell that calls an external service, so a plain Run All makes no network calls\n",+ "beyond `pip`; flip the flag to `True` to reproduce the pipeline yourself. A\n",+ "live run takes roughly 10 to 15 minutes end to end, almost all of it 3D\n",+ "generation time (about 30 to 90 seconds per prop, run in parallel).\n"]},{@@ -142,7 +152,17 @@"client = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key>\"))\n","\n","MODEL = \"gpt-5-mini\" # any vision-capable, tool-calling model works\n",- "THREE_WS_BASE = \"https://three.ws\""+ "THREE_WS_BASE = \"https://three.ws\"\n",+ "# -- Live-calls switch --------------------------------------------------------\n",+ "# Running this notebook drives two live external services: the keyless three.ws\n",+ "# text-to-3D and render endpoints (free, no account) and the OpenAI API (your\n",+ "# OPENAI_API_KEY; a few cents with gpt-5-mini). The notebook ships fully\n",+ "# executed, so every result is readable below without running anything. Flip to\n",+ "# True to opt in and reproduce the whole pipeline yourself.\n",+ "RUN_LIVE = False\n",+ "\n",+ "SKIP_NOTE = (\"RUN_LIVE is False: this cell kept its committed results instead of \"\n",+ " \"calling the live services. Set RUN_LIVE = True in the Setup cell to run it.\")\n"]},{@@ -221,11 +241,20 @@"\n"," deadline = time.time() + timeout_s\n"," while data.get(\"status\") == \"pending\" and time.time() < deadline:\n",- " time.sleep(3)\n",+ " # Every pending response carries a retryAfter poll-cadence hint in\n",+ " # seconds; honoring it is what keeps the poll from tripping the\n",+ " # lane's rate limit in the first place.\n",+ " time.sleep(min(float(data.get(\"retryAfter\") or 3), 30))\n"," job = data.get(\"job\") or data.get(\"jobId\")\n"," poll = requests.get(\n"," f\"{THREE_WS_BASE}/api/3d/generate\", params={\"job\": job}, timeout=(10, 60)\n"," )\n",+ " if poll.status_code == 429:\n",+ " # Rate-limited mid-poll: wait out Retry-After and keep polling\n",+ " # the SAME job. Raising here would restart the whole submit and\n",+ " # duplicate the generation.\n",+ " time.sleep(min(int(poll.headers.get(\"retry-after\") or \"15\"), 120))\n",+ " continue\n"," poll.raise_for_status()\n"," data = poll.json()\n"," return data\n",@@ -562,16 +591,19 @@" print(f\" skipped {name}: {err}\")\n"," return None\n","\n",- "with ThreadPoolExecutor(max_workers=4) as pool:\n",- " study = [m for m in pool.map(lambda p: safe_generate(*p), PROPS) if m]\n",- "\n",- "print(f\"generated {len(study)}/{len(PROPS)} props\")\n",- "render_models(\n",- " study,\n",- " title=\"A wizard's study\",\n",- " subtitle=\"Four props, one sentence each, generated on the free three.ws draft \"\n",- " \"lane and rendered inline. Drag to orbit; tap AR on a phone.\",\n",- ")"+ "if RUN_LIVE:\n",+ " with ThreadPoolExecutor(max_workers=4) as pool:\n",+ " study = [m for m in pool.map(lambda p: safe_generate(*p), PROPS) if m]\n",+ "\n",+ " print(f\"generated {len(study)}/{len(PROPS)} props\")\n",+ " render_models(\n",+ " study,\n",+ " title=\"A wizard's study\",\n",+ " subtitle=\"Four props, one sentence each, generated on the free three.ws draft \"\n",+ " \"lane and rendered inline. Drag to orbit; tap AR on a phone.\",\n",+ " )\n",+ "else:\n",+ " print(SKIP_NOTE)\n"]},{@@ -913,14 +945,17 @@")\n","THEME = \"A windowsill of houseplants\" # gallery headline; keep it matching the brief\n","\n",- "collection = run_art_director(WINDOWSILL_BRIEF)\n",+ "if RUN_LIVE:\n",+ " collection = run_art_director(WINDOWSILL_BRIEF)\n","\n",- "print(\"\\nArt director:\", collection[\"reply\"])\n",- "render_models(\n",- " collection[\"items\"],\n",- " title=THEME,\n",- " subtitle=\"Designed and built by the model from a single-line brief.\",\n",- ")"+ " print(\"\\nArt director:\", collection[\"reply\"])\n",+ " render_models(\n",+ " collection[\"items\"],\n",+ " title=THEME,\n",+ " subtitle=\"Designed and built by the model from a single-line brief.\",\n",+ " )\n",+ "else:\n",+ " print(SKIP_NOTE)\n"]},{@@ -1289,15 +1324,18 @@" display(Image(data=png))\n","\n","\n",- "with ThreadPoolExecutor(max_workers=4) as pool:\n",- " inspected = list(pool.map(lambda item: inspect_model(item, WINDOWSILL_BRIEF),\n",- " collection[\"items\"]))\n",+ "if RUN_LIVE:\n",+ " with ThreadPoolExecutor(max_workers=4) as pool:\n",+ " inspected = list(pool.map(lambda item: inspect_model(item, WINDOWSILL_BRIEF),\n",+ " collection[\"items\"]))\n","\n",- "render_verdicts(\n",- " inspected,\n",- " title=\"What the critic saw\",\n",- " subtitle=\"Each card is the exact image the model inspected, with its structured verdict.\",\n",- ")"+ " render_verdicts(\n",+ " inspected,\n",+ " title=\"What the critic saw\",\n",+ " subtitle=\"Each card is the exact image the model inspected, with its structured verdict.\",\n",+ " )\n",+ "else:\n",+ " print(SKIP_NOTE)\n"]},{@@ -1474,17 +1512,20 @@" return list(pool.map(fix, inspected))\n","\n","\n",- "windowsill_final = repair(inspected, WINDOWSILL_BRIEF)\n",+ "if RUN_LIVE:\n",+ " windowsill_final = repair(inspected, WINDOWSILL_BRIEF)\n","\n",- "passed = sum(1 for it in windowsill_final if it[\"verdict\"][\"passed\"])\n",- "print(f\"{passed}/{len(windowsill_final)} props pass QA after repair\")\n",- "render_models(\n",- " [{**it, \"name\": it[\"name\"] + (\" · rebuilt\" if it.get(\"repaired\") else \"\")}\n",- " for it in windowsill_final],\n",- " title=f\"{THEME}, after QA\",\n",- " subtitle=\"Every prop was inspected by the model; failures were rebuilt from \"\n",- " \"the critic's own revised prompt.\",\n",- ")"+ " passed = sum(1 for it in windowsill_final if it[\"verdict\"][\"passed\"])\n",+ " print(f\"{passed}/{len(windowsill_final)} props pass QA after repair\")\n",+ " render_models(\n",+ " [{**it, \"name\": it[\"name\"] + (\" · rebuilt\" if it.get(\"repaired\") else \"\")}\n",+ " for it in windowsill_final],\n",+ " title=f\"{THEME}, after QA\",\n",+ " subtitle=\"Every prop was inspected by the model; failures were rebuilt from \"\n",+ " \"the critic's own revised prompt.\",\n",+ " )\n",+ "else:\n",+ " print(SKIP_NOTE)\n"]},{@@ -1688,13 +1729,70 @@" return final\n","\n","\n",- "cabin = build_set(\"Design a collectible set for a deep-sea explorer's cabin.\")\n",- "render_models(\n",- " cabin,\n",- " title=\"A deep-sea explorer's cabin\",\n",- " subtitle=\"Art-directed, built, inspected, and repaired by the model from \"\n",- " \"one sentence. Drag to orbit; tap AR on a phone.\",\n",- ")"+ "if RUN_LIVE:\n",+ " cabin = build_set(\"Design a collectible set for a deep-sea explorer's cabin.\")\n",+ " render_models(\n",+ " cabin,\n",+ " title=\"A deep-sea explorer's cabin\",\n",+ " subtitle=\"Art-directed, built, inspected, and repaired by the model from \"\n",+ " \"one sentence. Drag to orbit; tap AR on a phone.\",\n",+ " )\n",+ "else:\n",+ " print(SKIP_NOTE)\n"+ ]+ },+ {+ "cell_type": "markdown",+ "id": "5353acbd",+ "metadata": {},+ "source": [+ "## Error handling and troubleshooting\n",+ "\n",+ "Every failure path in this notebook is handled where it occurs, so a run\n",+ "degrades instead of crashing. What that looks like in practice:\n",+ "\n",+ "| Symptom | Cause | What the notebook does |\n",+ "|---|---|---|\n",+ "| `429` on submit or poll | per-IP rate limit on the free lane | honors the `Retry-After` header, then retries; mid-poll it keeps waiting on the **same** job rather than resubmitting it |\n",+ "| `502` / `503` / `504` | brief GPU-lane saturation | retries the generation up to 3 times with a pause between attempts |\n",+ "| A job stays `pending` past the timeout | long queue on the free lane | raises `GenerationError`; inside the art-director loop that error is reported back to the model as the tool result instead of crashing the run |\n",+ "| Other `4xx` on submit | prompt rejected by the lane | not retried; surfaces immediately so you can fix the prompt |\n",+ "| Render endpoint unavailable | the QA snapshot call failed | QA **fails open**: the prop is kept and marked passed, because a guardrail that can take down the pipeline it guards is worse than no guardrail |\n",+ "| A rebuild fails | the repair generation itself errored | keeps the original draft prop and its original verdict |\n"+ ]+ },+ {+ "cell_type": "markdown",+ "id": "5d9ea790",+ "metadata": {},+ "source": [+ "## Production checklist\n",+ "\n",+ "Promoting this pattern from a notebook into a service? Check these first:\n",+ "\n",+ "| Area | Check |\n",+ "|---|---|\n",+ "| Budgets | every loop here is bounded (one art-director conversation, one repair per prop, three submit attempts); keep it that way when you raise the limits |\n",+ "| Poll cadence | keep honoring `retryAfter` / `Retry-After`; a fleet of impatient pollers is indistinguishable from an attack |\n",+ "| Caching | `glbUrl` results are immutable; cache them keyed by prompt so repeat briefs and retried jobs cost nothing |\n",+ "| Concurrency | the free draft lane is per-IP rate-limited; keep `max_workers` modest (four here) or move to a keyed lane |\n",+ "| Fidelity | the draft lane is single-subject and unrigged by design; three.ws serves higher-poly PBR and rigged lanes with the same tool shape when quality matters |\n",+ "| Evals | log every structured verdict; the pass rate over time is a free model-graded eval of your whole asset pipeline |\n"+ ]+ },+ {+ "cell_type": "markdown",+ "id": "522f1f1c",+ "metadata": {},+ "source": [+ "## When to use this pattern\n",+ "\n",+ "| Use generate / render / inspect / repair when | Skip it when |\n",+ "|---|---|\n",+ "| the tool's output is **generative** and can miss silently (3D, images, charts, UI code) | the tool returns deterministic data (a database row, a price); validate with schemas instead |\n",+ "| quality is judged visually, so only a vision pass can grade it | correctness is checkable in code (types, ranges, invariants) |\n",+ "| a retry with a better prompt plausibly fixes a failure | failures need a human decision, not a rewrite |\n",+ "| you can afford one render and one vision call per artifact | you are latency-bound and would rather ship drafts than gate on QA |\n"]},{