Rename messages to history
Exit

Rename messages to history

Rename the messages variable in chat_loop to history to match build_prompt's parameter name

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

Consistent naming

chat_loop uses messages as the variable name for conversation history. build_prompt already uses history for the same concept — that's what its parameter is called. Using two different names for the same data makes the code harder to follow.

This chapter renames messages to history throughout chat_loop. The change is cosmetic — the behavior stays exactly the same — but after this rename both functions use consistent terminology.

Instructions

  1. In chat_loop, rename messages = [] to history = [].
  2. Update the build_prompt call: change the third argument from messages to history.
  3. Update both .append calls at the bottom of the loop: change messages.append(...) to history.append(...).