Deploying the Chatbot

Deploy

Part of: Build a Chatbot

Your chatbot runs as a while True loop in a terminal, and exactly one person can use it: you, on your machine. To put it on the web, you don't rewrite the bot. You wrap the same load-append-call-save logic in a request handler, and let the statelessness you've been fighting become the thing that makes deployment easy. What deploying a chatbot means Deploying turns your local loop into a service many users hit over HTTP. The terminal loop and a web endpoint do the same four steps (load history, append the user turn, call the model, append and save the reply) but the loop runs them in one long-lived process, while the endpoint runs them once per request and then exits. The shift is that a web request is short-lived and isolated. The handler can't rely on a Python variable surviving between requests, because the next request might land on a different server entirely. So each request must rebuild the message list from stored history, which is the session-store discipline from lesson 5, now mandatory rather than optional. How it works A minimal endpoint is the loop body, unrolled into one function: Notice what's gone: there is no while loop and no in-memory messages variable that persis

Challenge: Stateless Request Replay