chatbot1-1 Exercise 2: A Channel With No Keyboard ==================================================== ex2.py (save in the project root): import asyncio from bot.core import Bot from bot.providers import FakeProvider async def run_script(bot: Bot, lines: list[str], session_id: str = "script") -> list[tuple[str, str]]: """A channel with no keyboard and no network: feed lines in, get the transcript back.""" transcript = [] for line in lines: transcript.append((line, await bot.handle(session_id, line))) return transcript async def main(): bot = Bot(FakeProvider(["Hello Ada!", "Your name is Ada."])) for you, reply in await run_script(bot, ["My name is Ada", "What is my name?"]): print("you>", you) print("bot>", reply) asyncio.run(main()) Run with: py ex2.py Output: you> My name is Ada bot> Hello Ada! you> What is my name? bot> Your name is Ada. WHY THIS WORKS AS AN ANSWER --------------------------- A channel is only something that gets text into bot.handle() and shows the text that comes back, so a "channel" that reads from a list instead of a keyboard fits the design with no change to Bot or to any provider. That is also why it is useful for testing: a conversation becomes data. A later chapter's tests can feed the same list of lines to the bot with a scripted fake provider and assert on the transcript (or on what the provider was sent), with no typing, no network and no real model, so the tests run in milliseconds and give the same result every time. The scripted replies here ("Your name is Ada.") are chosen by the test, not produced by understanding, which is exactly the point: the test checks the bot's plumbing, not the model's intelligence.