From 26950f7b52799b887283641310b563fff3fb5f26 Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Fri, 21 Jun 2024 12:35:41 -0700 Subject: [PATCH 1/5] Enhanced `/export` for timestamp, agent name (1) Added seconds to the end of the timestamp/ (2) If user provides a filename, we do not use the timestamp (3) If user does not provide a filename, we use "chat_history"+timestamp (4) Make sure the correct Agent name is used in the exported output. --- packages/jupyter-ai/jupyter_ai/chat_handlers/export.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py index ec3f1e53a..ae00eb4ef 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,10 @@ 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}`") From 8c398db59ed97dbe4f1e14459aff7f16acec6874 Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Fri, 21 Jun 2024 12:44:15 -0700 Subject: [PATCH 2/5] update docs for export --- docs/source/users/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/users/index.md b/docs/source/users/index.md index 4b339f13c..12a49858d 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`. Using `/export ` will export the chat history to `` without the timestamp 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. ### Fixing a code cell with an error From 98502fdedab36a6bff22183e1e0f8dc18f109880 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:48:11 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- packages/jupyter-ai/jupyter_ai/chat_handlers/export.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py index ae00eb4ef..fd8d7044e 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py @@ -36,10 +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 = ( # 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" + 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_file = os.path.join(self.root_dir, chat_filename) # Do not use timestamp if filename is entered as argument + 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}`") From d652ca842dc837f739cd4010bdb8fa6458a0b985 Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Fri, 21 Jun 2024 16:27:33 -0700 Subject: [PATCH 4/5] Amended export Based on comments from Jason Weill --- packages/jupyter-ai/jupyter_ai/chat_handlers/export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py index ae00eb4ef..56f99421e 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py @@ -23,8 +23,8 @@ def __init__(self, *args, **kwargs): def chat_message_to_markdown(self, message): if isinstance(message, AgentChatMessage): - Agent = self.config_manager.persona.name - 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: From 707512a4bc14ad427bdc95bf18a4d104e8625305 Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Fri, 21 Jun 2024 16:33:10 -0700 Subject: [PATCH 5/5] Update docs/source/users/index.md Co-authored-by: Jason Weill <93281816+JasonWeill@users.noreply.github.com> --- docs/source/users/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/users/index.md b/docs/source/users/index.md index 12a49858d..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-ss.md`. Using `/export ` will export the chat history to `` without the timestamp 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