fix: new chat load

This commit is contained in:
Timothy J. Baek 2023-11-19 20:39:13 -08:00
parent e116016543
commit 6a2c1600f5
5 changed files with 37 additions and 21 deletions

View file

@ -50,10 +50,12 @@
if (API_BASE_URL === '') { if (API_BASE_URL === '') {
API_BASE_URL = BUILD_TIME_API_BASE_URL; API_BASE_URL = BUILD_TIME_API_BASE_URL;
} }
const res = await getModels(API_BASE_URL, 'ollama'); const _models = await getModels(API_BASE_URL, 'ollama');
if (res) { if (_models.length > 0) {
toast.success('Server connection verified'); toast.success('Server connection verified');
await models.set(_models);
saveSettings({ saveSettings({
API_BASE_URL: API_BASE_URL API_BASE_URL: API_BASE_URL
}); });

View file

@ -1,5 +1,8 @@
<script lang="ts"> <script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { chatId } from '$lib/stores';
export let title: string = 'Ollama Web UI'; export let title: string = 'Ollama Web UI';
</script> </script>
@ -14,8 +17,10 @@
<div class="pr-2"> <div class="pr-2">
<button <button
class=" cursor-pointer p-1 flex dark:hover:bg-gray-700 rounded-lg transition" class=" cursor-pointer p-1 flex dark:hover:bg-gray-700 rounded-lg transition"
on:click={() => { on:click={async () => {
location.href = '/'; console.log('newChat');
goto('/');
await chatId.set(uuidv4());
}} }}
> >
<div class=" m-auto self-center"> <div class=" m-auto self-center">

View file

@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { goto, invalidateAll } from '$app/navigation'; import { goto, invalidateAll } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { user, db, chats, showSettings, chatId } from '$lib/stores'; import { user, db, chats, showSettings, chatId } from '$lib/stores';
@ -168,8 +170,10 @@
<div class="px-2.5 flex justify-center space-x-2"> <div class="px-2.5 flex justify-center space-x-2">
<button <button
class="flex-grow flex justify-between rounded-md px-3 py-1.5 my-2 hover:bg-gray-900 transition" class="flex-grow flex justify-between rounded-md px-3 py-1.5 my-2 hover:bg-gray-900 transition"
on:click={() => { on:click={async () => {
location.href = '/'; goto('/');
await chatId.set(uuidv4());
// createNewChat(); // createNewChat();
}} }}
> >

View file

@ -41,17 +41,18 @@
} }
onMount(async () => { onMount(async () => {
console.log(); await chatId.set(uuidv4());
chatId.subscribe(async () => {
await initNewChat(); await initNewChat();
}); });
});
////////////////////////// //////////////////////////
// Web functions // Web functions
////////////////////////// //////////////////////////
const initNewChat = async () => { const initNewChat = async () => {
await chatId.set(uuidv4());
console.log($chatId); console.log($chatId);
autoScroll = true; autoScroll = true;

View file

@ -91,6 +91,8 @@
if (messages.length > 0) { if (messages.length > 0) {
history.messages[messages.at(-1).id].done = true; history.messages[messages.at(-1).id].done = true;
} }
await tick();
return chat; return chat;
} else { } else {
return null; return null;
@ -503,8 +505,9 @@
}} }}
/> />
<Navbar {title} /> {#if loaded}
<div class="min-h-screen w-full flex justify-center"> <Navbar {title} />
<div class="min-h-screen w-full flex justify-center">
<div class=" py-2.5 flex flex-col justify-between w-full"> <div class=" py-2.5 flex flex-col justify-between w-full">
<div class="max-w-2xl mx-auto w-full px-3 md:px-0 mt-10"> <div class="max-w-2xl mx-auto w-full px-3 md:px-0 mt-10">
<ModelSelector bind:selectedModels disabled={messages.length > 0} /> <ModelSelector bind:selectedModels disabled={messages.length > 0} />
@ -516,4 +519,5 @@
</div> </div>
<MessageInput bind:prompt bind:autoScroll {messages} {submitPrompt} {stopResponse} /> <MessageInput bind:prompt bind:autoScroll {messages} {submitPrompt} {stopResponse} />
</div> </div>
{/if}