Loading topic
try/except. You should also know that a chat API takes a list of messages and returns a reply. The previous chapter explained why the model forgets between requests. This chapter builds the program that works around that. 5 min readtry/except blocks, and that you know a chat API takes a list of messages and returns a reply. You should also have the terminal loop and message history from earlier chapters.5 min readhistory list of role-tagged dictionaries that is sent in full on every turn. It also assumes you are comfortable with basic Python arithmetic and functions. No model SDK is needed, because the code here only measures and simu5 min readrole and content keys. You should also know that the whole list is sent on every request, and that the model has a limited context window. Here you will build the fu5 min readsave_history and load_history helpers from earlier chapters. You should be comfortable with dictionaries of functions and with raising and catching exceptions.4 min readsave_history and load_history from earlier chapters. It also assumes you know Python exceptions, including that KeyboardInterrupt is not a subclass of Exception. The goal is a program where a network error, a Ctrl+C or a damaged 5 min readrun_turn, trim_history, save_history and load_history functions from the earlier chapters. It also assumes basic familiarity with pytest: test functions named test_*, plain assert statements, and the tmp_path fixture. Install it with `pip install pyt5 min readrun_turn function from earlier chapters. You should be comfortable with Python dictionaries, JSON files, and the idea that each model request is stateless.4 min read