-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
Fix #422: Markdown formatting for chat history #444
Conversation
jeanlucthumm
commented
Jan 14, 2024
@TheR1D is there any procedure I need to do for assigning a reviewer? |
85aa9c9
to
3899b72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jeanlucthumm
I think we need to apply Markdown rendering only for "default" role conversations. Since we can have --code
conversations, and we are using pure text ouput there, markdown will skip \n
and print multiple lines of code in one line.
sgpt --repl --code c1
# <- print hello and print world using Python
# -> print('hello')
# -> print('world')
# <- exit()
sgpt --show-chat c1
...
user: print hello and print world using Python
assistant: print('hello') print('world') # <---
Ah ok good catch. Before enabling it only for We can do this only for The main concern here would be not outputting markdown wrapper when user is expected to redirect to file. But I think the use case for that is only this:
Both of which do not use |
You're right, we can use markdown code block when showing |
3899b72
to
ddc167f
Compare
Sounds good. I'll need to change how conversations are stored for this because we don't currently store the role along side the messages, only a json list, so My idea is to change the format from a list of messages to an object like this:
This is also good for future if we ever want to store more metadata about the conversations. Will take a look this weekend. |
ddc167f
to
b271ac5
Compare
Ok, @TheR1D please take a look. |
Thank you, @jeanlucthumm. I will review it during this week. I believe we may need to make some changes. |
Hey @jeanlucthumm, thank you for the PR. After reviewing the changes, I believe this feature could be implemented more concisely. We can reuse the @classmethod
def initial_message(cls, chat_id: str) -> str:
chat_history = cls.chat_session.get_messages(chat_id)
return chat_history[0] if chat_history else "" Then we can slightly change logic in @classmethod
def show_messages(cls, chat_id: str) -> None:
# Prints all messages from a specified chat ID to the console.
init_message = cls.initial_message(chat_id)
if "use and apply markdown" in init_message.lower():
for message in cls.chat_session.get_messages(chat_id):
if message.startswith("assistant"):
Console().print(Markdown(message))
else:
typer.secho(message, fg=cfg.get("DEFAULT_COLOR"))
typer.echo()
return
for index, message in enumerate(messages):
color = "magenta" if index % 2 == 0 else "green"
typer.secho(message, fg=color) I think this is more suitable solution since we are following the system prompt, and it would be compatible with custom roles. It will not wrap Thank you for interest and effort. |
Sure, let's do it this way. Will take a look this weekend! |
d156fcf
to
034516f
Compare
@TheR1D Ok I implemented your suggested change and also added unit tests. I also updated the documentation for custom roles so users are aware of this functionality. Also let me know if you'd like me to squash commits or anything like that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor comment, other than that, LGTM.
0aeefab
to
762670f
Compare
Ok finished! |
Thank you @jeanlucthumm, merged. |