From a696698ac8c618368be14950af269ae12104fd8c Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 26 Dec 2023 16:35:01 -0800 Subject: [PATCH] feat: chat import to backend added --- backend/apps/ollama/main.py | 2 - src/lib/components/chat/Messages.svelte | 13 +- src/lib/components/chat/SettingsModal.svelte | 204 ++++++++++++++++++- src/lib/components/layout/Sidebar.svelte | 173 +--------------- src/routes/(app)/+layout.svelte | 19 ++ src/routes/(app)/c/[id]/+page.svelte | 13 +- 6 files changed, 248 insertions(+), 176 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 53de123a..64c6361e 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -66,8 +66,6 @@ def proxy(path): headers.pop("Origin", None) headers.pop("Referer", None) - print(headers) - try: # Make a request to the target server r = requests.request( diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index a4627c5b..8516dc40 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -29,14 +29,25 @@ $: if (messages && messages.length > 0 && (messages.at(-1).done ?? false)) { (async () => { await tick(); + + [...document.querySelectorAll('*')].forEach((node) => { + if (node._tippy) { + node._tippy.destroy(); + } + }); + + console.log('rendering message'); + renderLatex(); hljs.highlightAll(); createCopyCodeBlockButton(); for (const message of messages) { if (message.info) { + console.log(message); + tippy(`#info-${message.id}`, { - content: `token/s: ${ + content: `token/s: ${ `${ Math.round( ((message.info.eval_count ?? 0) / (message.info.eval_duration / 1000000000)) * 100 diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index c86cc77f..4f7b9d0f 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -9,11 +9,12 @@ } from '$lib/constants'; import toast from 'svelte-french-toast'; import { onMount } from 'svelte'; - import { config, models, settings, user } from '$lib/stores'; + import { config, models, settings, user, chats } from '$lib/stores'; import { splitStream, getGravatarURL } from '$lib/utils'; import Advanced from './Settings/Advanced.svelte'; import { stringify } from 'postcss'; import { getOllamaVersion } from '$lib/apis/ollama'; + import { createNewChat, getChatList } from '$lib/apis/chats'; export let show = false; @@ -75,6 +76,37 @@ let OPENAI_API_KEY = ''; let OPENAI_API_BASE_URL = ''; + // Chats + + let importFiles; + let showDeleteHistoryConfirm = false; + + const importChats = async (_chats) => { + for (const chat of _chats) { + console.log(chat); + await createNewChat(localStorage.token, chat); + } + + await chats.set(await getChatList(localStorage.token)); + }; + + const exportChats = async () => { + console.log('TODO: export all chats'); + }; + + $: if (importFiles) { + console.log(importFiles); + + let reader = new FileReader(); + reader.onload = (event) => { + let chats = JSON.parse(event.target.result); + console.log(chats); + importChats(chats); + }; + + reader.readAsText(importFiles[0]); + } + // Auth let authEnabled = false; let authType = 'Basic'; @@ -752,6 +784,32 @@
Add-ons
+ + {#if !$config || ($config && !$config.auth)} + + + + {:else if selectedTab === 'auth'}
{ if (window.innerWidth > 1280) { show = true; @@ -57,29 +52,12 @@ // const deleteChatHistory = async () => { // await $db.deleteAllChat(); + + // const tx = this.db.transaction('chats', 'readwrite'); + // await Promise.all([tx.store.clear(), tx.done]); + + // await chats.set(await this.getChats()); // }; - - // const importChats = async (chatHistory) => { - // await $db.importChats(chatHistory); - // }; - - // const exportChats = async () => { - // let blob = new Blob([JSON.stringify(await $db.exportChats())], { type: 'application/json' }); - // saveAs(blob, `chat-export-${Date.now()}.json`); - // }; - - // $: if (importFiles) { - // console.log(importFiles); - - // let reader = new FileReader(); - // reader.onload = (event) => { - // let chats = JSON.parse(event.target.result); - // console.log(chats); - // importChats(chats); - // }; - - // reader.readAsText(importFiles[0]); - // }
- - {#if $user !== undefined}