Skip to content

Commit

Permalink
Fixed /export for timestamp, agent name (jupyterlab#854)
Browse files Browse the repository at this point in the history
* 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.

* update docs for export

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Amended export

Based on comments from Jason Weill

* Update docs/source/users/index.md

Co-authored-by: Jason Weill <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jason Weill <[email protected]>
  • Loading branch information
3 people authored Jun 21, 2024
1 parent 911bc93 commit 387e5b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file_name>` will export the chat history to `<file_name>-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 <file_name>`. Each export will include the entire chat history up to that point in the session.


### Fixing a code cell with an error
Expand Down
14 changes: 9 additions & 5 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 <Enter> 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}`")

0 comments on commit 387e5b7

Please sign in to comment.