Two bugs in L4 notebook

I know this course was created a long time ago :grinning_face:
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})
1 Like

Before the fix: you mistakenly get another piece of bread and lose one gold.


After the fix


By the way

response_format={"type": "json_object"}

should be added to detect_inventory_changes, otherwise the output may not always be json.

I also commented

output += update_msg

in main_loop because I found that caused trouble.

2 Likes

Thank you so much for catching this! And thanks @pang.luo for the suggestions!
Indeed, this is a late 2024 short course. I’m currently checking the notebooks and will be updating them along the team!

-- Lesly, DLAI

1 Like