Skip to content

Commit

Permalink
Close #4: Only save chat if there is at least one assistant message i…
Browse files Browse the repository at this point in the history
…n history.
  • Loading branch information
yaph committed Oct 16, 2024
1 parent 813a2e3 commit 9c956d1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions charla/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ def run(argv: argparse.Namespace) -> None:
except (KeyboardInterrupt, EOFError):
break

print(f'Saving chat in: {chats_file}')
save(chats_file, client)
# Save chat if there is at least one response.
if any(m['role'] == 'assistant' for m in client.message_history):
print(f'Saving chat in: {chats_file}')
save(chats_file, client)

print_fmt(HTML('<b>Exiting program.</b>'))


Expand All @@ -147,6 +150,7 @@ def save(chats_file: Path, client: client.Client) -> None:

output = f'# Chat with: {client.model}\n\n'

# Add user and assistant messages to output.
for msg in client.message_history:
if msg['role'] == 'user':
output += f"{ui.t_prompt}{msg['text']}\n\n"
Expand Down

0 comments on commit 9c956d1

Please sign in to comment.