Skip to content
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

Fixed /export for timestamp, agent name #854

Merged
merged 6 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`")
Loading