diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 46b8c365f..232879602 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -141,6 +141,21 @@ })(); } + $: if (selectedModels) { + saveSessionSelectedModels(); + } + + const saveSessionSelectedModels = () => { + if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { + return; + } + if (chatIdProp === '') { + return; + } + sessionStorage.selectedModels = JSON.stringify(selectedModels); + console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels); + }; + const showMessage = async (message) => { const _chatId = JSON.parse(JSON.stringify($chatId)); let _messageId = JSON.parse(JSON.stringify(message.id)); @@ -300,6 +315,7 @@ }; onMount(async () => { + console.log('mounted'); window.addEventListener('message', onMessageHandler); $socket?.on('chat-events', chatEventHandler); @@ -420,6 +436,55 @@ ////////////////////////// const initNewChat = async () => { + if (sessionStorage.selectedModels) { + selectedModels = JSON.parse(sessionStorage.selectedModels); + sessionStorage.removeItem('selectedModels'); + } else { + if ($page.url.searchParams.get('models')) { + selectedModels = $page.url.searchParams.get('models')?.split(','); + } else if ($page.url.searchParams.get('model')) { + const urlModels = $page.url.searchParams.get('model')?.split(','); + + if (urlModels.length === 1) { + const m = $models.find((m) => m.id === urlModels[0]); + if (!m) { + const modelSelectorButton = document.getElementById('model-selector-0-button'); + if (modelSelectorButton) { + modelSelectorButton.click(); + await tick(); + + const modelSelectorInput = document.getElementById('model-search-input'); + if (modelSelectorInput) { + modelSelectorInput.focus(); + modelSelectorInput.value = urlModels[0]; + modelSelectorInput.dispatchEvent(new Event('input')); + } + } + } else { + selectedModels = urlModels; + } + } else { + selectedModels = urlModels; + } + } else if ($settings?.models) { + selectedModels = $settings?.models; + } else if ($config?.default_models) { + console.log($config?.default_models.split(',') ?? ''); + selectedModels = $config?.default_models.split(','); + } + } + + selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId)); + if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { + if ($models.length > 0) { + selectedModels = [$models[0].id]; + } else { + selectedModels = ['']; + } + } + + console.log(selectedModels); + await showControls.set(false); await showCallOverlay.set(false); await showOverview.set(false); @@ -442,51 +507,6 @@ chatFiles = []; params = {}; - if ($page.url.searchParams.get('models')) { - selectedModels = $page.url.searchParams.get('models')?.split(','); - } else if ($page.url.searchParams.get('model')) { - const urlModels = $page.url.searchParams.get('model')?.split(','); - - if (urlModels.length === 1) { - const m = $models.find((m) => m.id === urlModels[0]); - if (!m) { - const modelSelectorButton = document.getElementById('model-selector-0-button'); - if (modelSelectorButton) { - modelSelectorButton.click(); - await tick(); - - const modelSelectorInput = document.getElementById('model-search-input'); - if (modelSelectorInput) { - modelSelectorInput.focus(); - modelSelectorInput.value = urlModels[0]; - modelSelectorInput.dispatchEvent(new Event('input')); - } - } - } else { - selectedModels = urlModels; - } - } else { - selectedModels = urlModels; - } - } else if ($settings?.models) { - selectedModels = $settings?.models; - } else if ($config?.default_models) { - console.log($config?.default_models.split(',') ?? ''); - selectedModels = $config?.default_models.split(','); - } - - selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId)); - - if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { - if ($models.length > 0) { - selectedModels = [$models[0].id]; - } else { - selectedModels = ['']; - } - } - - console.log(selectedModels); - if ($page.url.searchParams.get('youtube')) { uploadYoutubeTranscription( `https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}` diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 83a4b8eba..d3e9b03fd 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -468,7 +468,7 @@ } onMount(async () => { - console.log('ResponseMessage mounted'); + // console.log('ResponseMessage mounted'); await tick(); }); diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index c54b7edf2..cad307421 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -83,7 +83,7 @@ }; onMount(() => { - console.log('UserMessage mounted'); + // console.log('UserMessage mounted'); });