No-LLM bot
DyUI is useful without a model too: guided flows, internal tools, demos and tests. You’ll build a pizza desk that uses a table, a choice, an approval, a live step and a plan.
Prerequisites
Section titled “Prerequisites”pip install dyui- No API key.
Save and run
Section titled “Save and run”-
Save the code below as
no_llm.pyin a new, empty file, or download no_llm.py. -
Run it:
Terminal window pip install dyuidyui run no_llm.py -
Open http://localhost:8000. Click Order a pizza and follow the buttons.
What to look at
Section titled “What to look at”@app.on_action("choice")handles thechoicecomponent’s default action. Itsvalues["selected"]is a list.chat.ask()inside an action handler waits for a second click before doing the work.- Everything is plain Python control flow. There’s no state machine to declare.
The code
Section titled “The code”"""A bot with no LLM: scripted components, actions, steps and human-in-the-loop."""import asyncio
import dyuifrom dyui import ui
app = dyui.App( title="Pizza Desk", description="A scripted bot - no API key needed.", starters=["Show the menu", "Order a pizza"],)
@app.on_messageasync def reply(msg: dyui.Message, chat: dyui.Chat): text = msg.text.lower() if "menu" in text: yield "Here is today's menu." yield ui.Table( columns=["Pizza", "Size", "Price"], rows=[["Margherita", "M", "$11"], ["Diavola", "M", "$13"], ["Funghi", "M", "$12"]], ) yield ui.QuickReplies(["Order a pizza"]) elif "order" in text: yield ui.Choice("Which pizza?", ["Margherita", "Diavola", "Funghi"]) else: yield "I can show the **menu** or take an **order**."
@app.on_action("choice")async def chosen(action: dyui.Action, chat: dyui.Chat): pizza = action.values["selected"][0] answer = await chat.ask(ui.Confirm(f"Order a {pizza}?", text="Total: $12")) if not answer.values.get("confirmed"): yield "No problem, cancelled." return async with chat.step("Sending to the kitchen", type="tool"): await asyncio.sleep(1) yield ui.Plan(title="Your order", items=[ {"title": "Order received", "status": "done"}, {"title": "In the oven", "status": "active"}, {"title": "Out for delivery", "status": "pending"}, ])Extend it
Section titled “Extend it”- Replace the menu with rows from your own database.
- For a bigger tour,
dyui demoruns the built-in showcase bot.