Closed Aflous closed 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
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`
Thanks for raising this issue ! fix in 5a49a66
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)
^^^^^^^^^^^^^^^^^^^^^