-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export chat to markdown functionality added
- Loading branch information
1 parent
b18b7d0
commit 3ef11ce
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import List | ||
|
||
from jupyter_ai.models import HumanChatMessage, AgentChatMessage | ||
|
||
from .base import BaseChatHandler, SlashCommandRoutingType | ||
|
||
class ExportChatHandler(BaseChatHandler): | ||
id = "export" | ||
name = "Export chat messages" | ||
help = "Export the chat messages in various formats" | ||
routing_type = SlashCommandRoutingType(slash_id="export") | ||
|
||
uses_llm = False | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def chat_message_to_markdown(self, message): | ||
if isinstance(message, AgentChatMessage): | ||
return f"**Agent**: {message.body}" | ||
elif isinstance(message, HumanChatMessage): | ||
return f"**{message.client.display_name}**: {message.body}" | ||
else: | ||
return "" | ||
|
||
|
||
async def process_message(self, _): | ||
markdown_content = "\n\n".join(self.chat_message_to_markdown(msg) for msg in self._chat_history) | ||
# Write the markdown content to a file or do whatever you want with it | ||
with open("./playground/chat_history.md", "w") as chat_history: | ||
chat_history.write(markdown_content) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters