diff --git a/src/lib/components/layout/Navbar/Menu.svelte b/src/lib/components/layout/Navbar/Menu.svelte index 03e36d8e9..e06b9ab00 100644 --- a/src/lib/components/layout/Navbar/Menu.svelte +++ b/src/lib/components/layout/Navbar/Menu.svelte @@ -5,13 +5,17 @@ import fileSaver from 'file-saver'; const { saveAs } = fileSaver; + import { downloadChatAsPDF } from '$lib/apis/utils'; + import { copyToClipboard } from '$lib/utils'; + import { showSettings } from '$lib/stores'; import { flyAndScale } from '$lib/utils/transitions'; import Dropdown from '$lib/components/common/Dropdown.svelte'; import Tags from '$lib/components/chat/Tags.svelte'; - - import { downloadChatAsPDF } from '$lib/apis/utils'; + import Map from '$lib/components/icons/Map.svelte'; + import { get } from 'svelte/store'; + import Clipboard from '$lib/components/icons/Clipboard.svelte'; const i18n = getContext('i18n'); @@ -24,14 +28,18 @@ export let chat; export let onClose: Function = () => {}; - const downloadTxt = async () => { + const getChatAsText = async () => { const _chat = chat.chat; - console.log('download', chat); - const chatText = _chat.messages.reduce((a, message, i, arr) => { return `${a}### ${message.role.toUpperCase()}\n${message.content}\n\n`; }, ''); + return chatText.trim(); + }; + + const downloadTxt = async () => { + const chatText = await getChatAsText(); + let blob = new Blob([chatText], { type: 'text/plain' }); @@ -117,6 +125,30 @@
{$i18n.t('Settings')}
--> + { + shareHandler(); + }} + > + +
{$i18n.t('Overview')}
+
+ + { + await copyToClipboard(await getChatAsText()).catch((e) => { + console.error(e); + }); + }} + > + +
{$i18n.t('Copy')}
+
+
{$i18n.t('Share')}
- +