From d863e7e60b063936ad25b26ab1bc473f334cfcfb Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 21 Feb 2024 18:50:41 -0800 Subject: [PATCH] feat: save message --- src/lib/components/chat/Messages.svelte | 10 ++++++++++ .../chat/Messages/ResponseMessage.svelte | 15 ++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 071f715c..64574530 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -309,6 +309,16 @@ {copyToClipboard} {continueGeneration} {regenerateResponse} + on:save={async (e) => { + console.log('save', e); + + const message = e.detail; + history.messages[message.id] = message; + await updateChatById(localStorage.token, chatId, { + messages: messages, + history: history + }); + }} /> {/if} diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index d2925b04..e9dedc12 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -2,22 +2,25 @@ import toast from 'svelte-french-toast'; import dayjs from 'dayjs'; import { marked } from 'marked'; - import { config, settings } from '$lib/stores'; import tippy from 'tippy.js'; import auto_render from 'katex/dist/contrib/auto-render.mjs'; import 'katex/dist/katex.min.css'; + import { createEventDispatcher } from 'svelte'; import { onMount, tick } from 'svelte'; + const dispatch = createEventDispatcher(); + + import { config, settings } from '$lib/stores'; + import { synthesizeOpenAISpeech } from '$lib/apis/openai'; + import { imageGenerations } from '$lib/apis/images'; + import { extractSentences } from '$lib/utils'; + import Name from './Name.svelte'; import ProfileImage from './ProfileImage.svelte'; import Skeleton from './Skeleton.svelte'; import CodeBlock from './CodeBlock.svelte'; - import { synthesizeOpenAISpeech } from '$lib/apis/openai'; - import { extractSentences } from '$lib/utils'; - import { imageGenerations } from '$lib/apis/images'; - export let modelfiles = []; export let message; export let siblings; @@ -280,6 +283,8 @@ type: 'image', url: `data:image/png;base64,${image}` })); + + dispatch('save', message); } generatingImage = false;