appendix G Building a chat interface
The supplementary code repository for this book includes a small browser-based chat interface, built with the open source Chainlit Python package (https://github.com/Chainlit/chainlit). This ChatGPT-like interface allows us to interact with the various LLMs and reasoning models in this book, as shown in the screenshot in figure G.1. This interface can be useful when we want a more convenient way to interact with the models than typing prompts into a notebook cell or terminal.
Figure G.1 Chainlit interface for the Qwen3 model, which mimics the ChatGPT interface
Building upon the Chainlit library, the implementation of this interface is relatively straightforward. Instead of printing tokens to the terminal, we wrap the same model-loading and generation functions from the earlier chapters inside a small web application, which stays local on the computer and runs in a browser. In practice, this means that we can reuse the from-scratch Qwen3Model implementation and the chapter 2 streaming helper while letting Chainlit handle the browser UI and message events.
The book’s supplementary materials contain two variants of the interface in chG/01_main-chapter-code (https://github.com/rasbt/reasoning-from-scratch/tree/main/chG/01_main-chapter-code):
qwen3_chat_interface.pyis a single-turn interface.qwen3_chat_interface_multiturn.pystores conversation history and supports multi-turn interactions.