sahbic / profile-gpt

An AI-driven tool to analyze your profile and gain insights into how ChatGPT interprets your personality.
MIT License
180 stars 12 forks source link

UnboundLocalError: cannot access local variable 'sampled_conv_messages' where it is not associated with a value #1

Closed Aflous closed 1 year ago

Aflous commented 1 year ago

Error: cannot access local variable 'sampled_conv_messages' where it is not associated with a value Traceback: File "/usr/local/lib/python3.9/site-packages/streamlit/runtimescript_runner.py", line 565, in _run_script exec(code, module.dict) File "/home/user/projects/GPT/dashboard.py", line 59, in processed_messages = preprocess_messages(user_messages, total_desired_number_of_messages, number_of_words_max_per_message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/projects/GPT/utils/functions.py", line 83, in preprocess_messages sampled_messages.append(sampled_conv_messages) ^^^^^^^^^^^^^^^^^^^^^

Aflous commented 1 year ago

You've left an unchecked path here (which led to sampled_conv_messages being referenced before being assigned to):

if (number_of_messages_to_sample <= 3):
            if not (number_of_messages_to_sample == 0):
                sampled_conv_messages = conversation_messages[:number_of_messages_to_sample]
        else:
            sampled_conv_messages = conversation_messages[:3] + get_ordered_random_sample(conversation_messages[3:], number_of_messages_to_sample - 3)

Will push a PR to fix it later this week

cpkelley5 commented 1 year ago

Modify the preprocess_messages function as follows (though even after making this change, I still get an error about my message exceeding the maximum context length of 4097 tokens.)

`def preprocess_messages(user_messages, total_desired_number_of_messages=150, number_of_words_max_per_message=40):

...

for conversation in range(len(user_messages)):
    # ...
    if (number_of_messages_to_sample <= 3):
        if not (number_of_messages_to_sample == 0):
            sampled_conv_messages = conversation_messages[:number_of_messages_to_sample]
    else:
        sampled_conv_messages = conversation_messages[:3] + get_ordered_random_sample(conversation_messages[3:], number_of_messages_to_sample - 3)

    # Initialize sampled_conv_messages as an empty list if it hasn't been assigned a value
    if not sampled_conv_messages:
        sampled_conv_messages = []

    sampled_messages.append(sampled_conv_messages)
# ...
return user_messages`
sahbic commented 1 year ago

Thanks for raising this issue ! fix in 5a49a66