diff --git a/docs/source/users/index.md b/docs/source/users/index.md index 4b339f13c..8db821238 100644 --- a/docs/source/users/index.md +++ b/docs/source/users/index.md @@ -511,7 +511,7 @@ The `/learn` command also provides downloading and processing papers from the [a ``` ### Exporting chat history -Use the `/export` command to export the chat history from the current session to a markdown file named `chat_history-YYYY-MM-DD-HH-mm.md`. Using `/export ` will export the chat history to `-YYYY-MM-DD-HH-mm.md` instead. You can export chat history as many times as you like in a single session. Each successive export will include the entire chat history up to that point in the session. +Use the `/export` command to export the chat history from the current session to a markdown file named `chat_history-YYYY-MM-DD-HH-mm-ss.md`. You can also specify a filename using `/export `. Each export will include the entire chat history up to that point in the session. ### Fixing a code cell with an error diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py index ec3f1e53a..c51a3a3e2 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py @@ -23,7 +23,8 @@ def __init__(self, *args, **kwargs): def chat_message_to_markdown(self, message): if isinstance(message, AgentChatMessage): - return f"**Agent**: {message.body}" + agent = self.config_manager.persona.name + return f"**{agent}**: {message.body}" elif isinstance(message, HumanChatMessage): return f"**{message.client.display_name}**: {message.body}" else: @@ -35,11 +36,14 @@ async def process_message(self, message: HumanChatMessage): self.chat_message_to_markdown(msg) for msg in self._chat_history ) args = self.parse_args(message) - chat_filename = ( - args.path[0] if (args.path and args.path[0] != "") else "chat_history" + chat_filename = ( # if no filename, use "chat_history" + timestamp + args.path[0] + if (args.path and args.path[0] != "") + else f"chat_history-{datetime.now():%Y-%m-%d-%H-%M-%S}.md" ) # Handles both empty args and double tap key - chat_filename = f"{chat_filename}-{datetime.now():%Y-%m-%d-%H-%M}.md" - chat_file = os.path.join(self.root_dir, chat_filename) + chat_file = os.path.join( + self.root_dir, chat_filename + ) # Do not use timestamp if filename is entered as argument with open(chat_file, "w") as chat_history: chat_history.write(markdown_content) self.reply(f"File saved to `{chat_file}`")