Skip to content

webui: Change Download function to download the full text of the conversation #14619

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file modified tools/server/public/index.html.gz
Binary file not shown.
18 changes: 13 additions & 5 deletions tools/server/webui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,29 @@ export default function Sidebar() {
navigate('/');
}
}}
onDownload={() => {
onDownload={async () => {
if (isGenerating(conv.id)) {
toast.error(
'Cannot download conversation while generating'
);
return;
}
const conversationJson = JSON.stringify(conv, null, 2);
const blob = new Blob([conversationJson], {
type: 'application/json',
const messages = await StorageUtils.getMessages(conv.id);
const messageChain = StorageUtils.filterByLeafNodeId(
messages,
conv.currNode,
false
);
const conversationText = messageChain
.map((msg) => `${msg.role}: ${msg.content}`)
.join('\n\n');
const blob = new Blob([conversationText], {
type: 'text/plain',
});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `conversation_${conv.id}.json`;
a.download = `conversation_${conv.id}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
Expand Down