yr.chat

chat(
    stop_str: str = '/quit',
) → Generator[str]

Yield user prompts until one starts with stop_str.

Repeatedly prompts the user for text input, yielding each prompt. When the user submits a prompt starting with stop_str, the run quits and iteration stops.

Parameters

stop_str
type: str = '/quit'

Prefix that, when matched, ends the chat loop. Default = "/quit"

Examples

Build a conversational app that stops when the user enters /goodbye:

python
import yera as yr

@yr.app
def history_guide() -> None:
    yr.sys_prompt("You are a friendly history guide.")

    for question in yr.chat(stop_str="/goodbye"):
        yr.response(question)