Skip to content

Commit 3899b72

Browse files
committed
Fix #422: Markdown formatting for chat history
1 parent d908d1d commit 3899b72

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sgpt/handlers/chat_handler.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
from pathlib import Path
33
from typing import Any, Callable, Dict, Generator, List, Optional
4+
from rich.console import Console
5+
from rich.markdown import Markdown
46

57
import typer
68
from click import BadArgumentUsage
@@ -125,10 +127,11 @@ def list_ids(cls, value: str) -> None:
125127

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

133136
@classmethod
134137
@option_callback

0 commit comments

Comments
 (0)