I know this course was created a long time ago ![]()
but if it is of help, there are two bugs in the L4 notebook.
In run_action we have
world_info = f"""
World: {game_state['world']}
Kingdom: {game_state['kingdom']}
Town: {game_state['town']}
Your Character: {game_state['character']}
Inventory: {json.dumps(game_state['inventory'])}"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": world_info}
]
for action in history:
messages.append({"role": "assistant", "content": action[0]})
messages.append({"role": "user", "content": action[1]})
messages.append({"role": "user", "content": message})
Bug 1 is that the latest inventory shouldn’t be specified before the history messages, otherwise operations will be repeated mistakenly on inventory. For example, if at step 1 you bought a piece of bread with 1 gold and at step 2 you asked to show your inventory, you’ll find that your gold decreased by 1 at step 2!
Bug 2 is action[0] should be from user and action[1] assistant. The script just did the opposite.
I tested my update (as follows) and it works.
world_info = f"""
World: {game_state['world']}
Kingdom: {game_state['kingdom']}
Town: {game_state['town']}
Your Character: {game_state['character']}"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": world_info}
]
for action in history:
messages.append({"role": "user", "content": action[0]})
messages.append({"role": "assistant", "content": action[1]})
messages.append({"role": "assistant", "content": "Your current inventory: " + json.dumps(game_state['inventory'])})
messages.append({"role": "user", "content": message})



