Skip to content

dyui.llm

async def stream(
model: str,
messages: list[Any],
*,
system: str | None = None,
components: Any = None,
ui_mode: str = 'fence',
max_tool_rounds: int = 8,
rate_limit_retries: int = DEFAULT_RATE_LIMIT_RETRIES,
base_url: str | None = None,
api_key: str | None = None,
client: Any = None,
**kwargs: Any,
) -> AsyncIterator[Any]

Stream a completion as str text deltas and dyui.Reasoning deltas.

model is "provider/model" (see dyui.llm.PROVIDERS). components is a catalog (anything with .prompt()); its prompt is merged into system (at {dyui_components} if present, else appended).

ui_mode="fence" (default): the model writes ``dyui fences inside its text. ui_mode="tools": one render_<name> tool per component (strict schemas via components.tool_schemas); dyui runs the tool loop (at most max_tool_rounds requests) and yields each completed call as a {"ui": name, ...props} dict. A caller-supplied tools= list is merged; if the model calls one of those tools the loop stops (custom tools need their own loop).

Rate limits: an HTTP 429 from the provider is retried up to rate_limit_retries times, waiting for the provider’s Retry-After (or 2s, 4s, 8s…). Waits over a minute (daily quotas) are not retried. Set rate_limit_retries=0 to disable.

`client`` lets you pass a pre-built async SDK client. Extra kwargs go to the SDK.

async def complete(model: str, messages: list[Any], **kwargs: Any) -> str

Non-streaming convenience: return the full text reply (reasoning dropped).

class Provider(
name: str,
sdk: str,
base_url: str | None = None,
base_url_env: str | None = None,
key_envs: tuple[str, ...] = (),
key_required: bool = True,
)
class MissingDependencyError(ImportError)

Raised when an optional SDK (openai / anthropic) is not installed.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.