Skip to content

Commit

Permalink
Fix TheR1D#422: Markdown formatting for chat history
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlucthumm committed Jan 14, 2024
1 parent d908d1d commit 3899b72
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sgpt/handlers/chat_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from pathlib import Path
from typing import Any, Callable, Dict, Generator, List, Optional
from rich.console import Console
from rich.markdown import Markdown

import typer
from click import BadArgumentUsage
Expand Down Expand Up @@ -125,10 +127,11 @@ def list_ids(cls, value: str) -> None:

@classmethod
def show_messages(cls, chat_id: str) -> None:
# Prints all messages from a specified chat ID to the console.
for index, message in enumerate(cls.chat_session.get_messages(chat_id)):
color = "magenta" if index % 2 == 0 else "green"
typer.secho(message, fg=color)
# Concatenate messages from a specified chat ID and render markdown
history = "\n\n".join(cls.chat_session.get_messages(chat_id))
console = Console()
md = Markdown(history)
console.print(md)

@classmethod
@option_callback
Expand Down

0 comments on commit 3899b72

Please sign in to comment.