Commands and Resets
Control
Part of: Build a Chatbot
Your user types /clear. What should happen? If you just append it as a normal user turn, the model will earnestly try to respond to the literal text "/clear" in character: your pirate will say "Arr, clear what, matey?" Commands aren't conversation. They're instructions to your app about the conversation, and you have to handle them before the model ever sees them. What chat commands are A command is a special user input, usually starting with / that your code intercepts to control the session instead of sending to the model. /clear wipes the history. /persona wizard swaps the character. /help lists commands. The pattern is the same: check for a command first, and only if it isn't one do you treat the input as a normal message and call the model. This is where owning the message list (lesson 1) pays off. Because the history is just your Python list and the persona is just your system string, resetting or re-skinning a chat is a few lines of your code; the model never objects, because the model never sees the command. How it works Route the input before the model: Two subtleties matter. On /clear, don't just empty the history, also re-inject the system prompt (here, reset it to the d
Challenge: Command Router