Skip to content

Commit

Permalink
[Feature] Better JSON Exporter ChatGPTNextWeb#2692
Browse files Browse the repository at this point in the history
[+] A view looks better
[+] auto minify json when click a copy in markdown and download

Co-Authored-By: wangwentong-lunaon <[email protected]>
Co-Authored-By: Yifei Zhang <[email protected]>
Co-Authored-By: B0zal <[email protected]>
  • Loading branch information
4 people committed Aug 23, 2023
1 parent 7562ab3 commit 0113d44
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions app/components/exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,34 +565,45 @@ export function MarkdownPreviewer(props: {
);
}

// modified by BackTrackZ now it's looks better

export function JsonPreviewer(props: {
messages: ChatMessage[];
topic: string;
}) {
const msgs = props.messages.map((m) => ({
role: m.role,
content: m.content,
}));
const mdText = "\n" + JSON.stringify(msgs, null, 2) + "\n";
const msgs = {
messages: [
{
role: "system",
content: "You are an assistant that " + props.topic,
},
...props.messages.map((m) => ({
role: m.role,
content: m.content,
})),
],
};
const mdText = "```json\n" + JSON.stringify(msgs, null, 2) + "\n```";
const minifiedJson = JSON.stringify(msgs);

const copy = () => {
copyToClipboard(JSON.stringify(msgs, null, 2));
copyToClipboard(minifiedJson);
};
const download = () => {
downloadAs(JSON.stringify(msgs, null, 2), `${props.topic}.json`);
downloadAs(JSON.stringify(msgs), `${props.topic}.json`);
};

return (
<>
<PreviewActions
copy={copy}
download={download}
showCopy={true}
showCopy={false}
messages={props.messages}
/>
<div className="markdown-body">
<pre className={styles["export-content"]}>{mdText}</pre>
<div className="markdown-body" onClick={copy}>
<Markdown content={mdText} />
</div>
</>
);
}
}

0 comments on commit 0113d44

Please sign in to comment.