Skip to content

Commit

Permalink
Rename chats_file to chat_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Oct 16, 2024
1 parent b963e35 commit e4e7782
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions charla/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def run(argv: argparse.Namespace) -> None:
config.mkdir(chats_path, exist_ok=True, parents=True)
now = datetime.strftime(datetime.now(), '%Y-%m-%d-%H-%M-%S')
slug = re.sub(r'\W', '-', client.model)
chats_file = chats_path / f'{now}-{slug}.md'
chat_file = chats_path / f'{now}-{slug}.md'

# Start the chat REPL.
session = prompt_session(argv)
Expand Down Expand Up @@ -128,21 +128,21 @@ def run(argv: argparse.Namespace) -> None:
client.generate(user_input)
print('\n')

save(chats_file, client)
save(chat_file, client)

# Exit program on CTRL-C and CTRL-D
except (KeyboardInterrupt, EOFError):
break

# 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(f'Saving chat in: {chat_file}')
save(chat_file, client)

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


def save(chats_file: Path, client: client.Client) -> None:
def save(chat_file: Path, client: client.Client) -> None:
"""Save the chat as a markdown file."""

output = f'# Chat with: {client.model}\n\n'
Expand All @@ -154,4 +154,4 @@ def save(chats_file: Path, client: client.Client) -> None:
elif msg['role'] == 'assistant':
output += f"{ui.t_response}\n\n{msg['text']}\n\n"

chats_file.write_text(output)
chat_file.write_text(output)

0 comments on commit e4e7782

Please sign in to comment.