Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not save conversation log when conversation is empty #316

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/conversation/conversation_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ def save_conversation_log(character: Character, messages: list[ChatCompletionMes
# save conversation history

if not character.is_generic_npc:
# if this is not the first conversation
conversation_history_file = conversation_log.__get_path_to_conversation_history_file(character)
# transformed_messages = messages.transform_to_openai_messages(messages.get_talk_only())
if os.path.exists(conversation_history_file):
with open(conversation_history_file, 'r', encoding='utf-8') as f:
conversation_history = json.load(f)
if len(messages) > 0:
# if this is not the first conversation
conversation_history_file = conversation_log.__get_path_to_conversation_history_file(character)
# transformed_messages = messages.transform_to_openai_messages(messages.get_talk_only())
if os.path.exists(conversation_history_file):
with open(conversation_history_file, 'r', encoding='utf-8') as f:
conversation_history = json.load(f)

# add new conversation to conversation history
conversation_history.append(messages) # append everything except the initial system prompt
# if this is the first conversation
else:
directory = os.path.dirname(conversation_history_file)
os.makedirs(directory, exist_ok=True)
conversation_history = [messages] # wrap the first conversation in a list

with open(conversation_history_file, 'w', encoding='utf-8') as f:
json.dump(conversation_history, f, indent=4) # save everything except the initial system prompt
# add new conversation to conversation history
conversation_history.append(messages) # append everything except the initial system prompt
# if this is the first conversation
else:
directory = os.path.dirname(conversation_history_file)
os.makedirs(directory, exist_ok=True)
conversation_history = [messages] # wrap the first conversation in a list
with open(conversation_history_file, 'w', encoding='utf-8') as f:
json.dump(conversation_history, f, indent=4) # save everything except the initial system prompt
else:
logging.log(23, 'Conversation history will not be saved for this generic NPC.')

Expand Down