Commit d12599b2 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac

parent 1482119a
<script lang="ts"> <script lang="ts">
import toast from 'svelte-french-toast'; import toast from 'svelte-french-toast';
import queue from 'async/queue';
import fileSaver from 'file-saver'; import fileSaver from 'file-saver';
const { saveAs } = fileSaver; const { saveAs } = fileSaver;
import { goto } from '$app/navigation';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { config, models, settings, user, chats } from '$lib/stores';
import { splitStream, getGravatarURL } from '$lib/utils';
import queue from 'async/queue';
import { import {
getOllamaVersion, getOllamaVersion,
...@@ -17,14 +16,16 @@ ...@@ -17,14 +16,16 @@
createModel, createModel,
deleteModel deleteModel
} from '$lib/apis/ollama'; } from '$lib/apis/ollama';
import { updateUserPassword } from '$lib/apis/auths';
import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats'; import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats';
import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants'; import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { config, models, settings, user, chats } from '$lib/stores';
import { splitStream, getGravatarURL } from '$lib/utils';
import Advanced from './Settings/Advanced.svelte'; import Advanced from './Settings/Advanced.svelte';
import Modal from '../common/Modal.svelte'; import Modal from '../common/Modal.svelte';
import { updateUserPassword } from '$lib/apis/auths';
import { goto } from '$app/navigation';
import Page from '../../../routes/(app)/+page.svelte';
import { import {
getOpenAIKey, getOpenAIKey,
getOpenAIModels, getOpenAIModels,
...@@ -50,13 +51,6 @@ ...@@ -50,13 +51,6 @@
let theme = 'dark'; let theme = 'dark';
let notificationEnabled = false; let notificationEnabled = false;
let system = ''; let system = '';
const MAX_PARALLEL_DOWNLOADS = 3;
const modelDownloadQueue = queue(
(task: { modelName: string }, cb) =>
pullModelHandlerProcessor({ modelName: task.modelName, callback: cb }),
MAX_PARALLEL_DOWNLOADS
);
let modelDownloadStatus: Record<string, any> = {};
// Advanced // Advanced
let requestFormat = ''; let requestFormat = '';
...@@ -78,8 +72,15 @@ ...@@ -78,8 +72,15 @@
}; };
// Models // Models
let modelTransferring = false; const MAX_PARALLEL_DOWNLOADS = 3;
const modelDownloadQueue = queue(
(task: { modelName: string }, cb) =>
pullModelHandlerProcessor({ modelName: task.modelName, callback: cb }),
MAX_PARALLEL_DOWNLOADS
);
let modelDownloadStatus: Record<string, any> = {};
let modelTransferring = false;
let modelTag = ''; let modelTag = '';
let digest = ''; let digest = '';
let pullProgress = null; let pullProgress = null;
...@@ -94,7 +95,6 @@ ...@@ -94,7 +95,6 @@
let deleteModelTag = ''; let deleteModelTag = '';
// External // External
let OPENAI_API_KEY = ''; let OPENAI_API_KEY = '';
let OPENAI_API_BASE_URL = ''; let OPENAI_API_BASE_URL = '';
...@@ -111,21 +111,18 @@ ...@@ -111,21 +111,18 @@
let importFiles; let importFiles;
let showDeleteConfirm = false; let showDeleteConfirm = false;
const importChats = async (_chats) => { // Auth
for (const chat of _chats) { let authEnabled = false;
console.log(chat); let authType = 'Basic';
await createNewChat(localStorage.token, chat); let authContent = '';
}
await chats.set(await getChatList(localStorage.token)); // Account
}; let currentPassword = '';
let newPassword = '';
let newPasswordConfirm = '';
const exportChats = async () => { // About
let blob = new Blob([JSON.stringify(await getAllChats(localStorage.token))], { let ollamaVersion = '';
type: 'application/json'
});
saveAs(blob, `chat-export-${Date.now()}.json`);
};
$: if (importFiles) { $: if (importFiles) {
console.log(importFiles); console.log(importFiles);
...@@ -140,25 +137,28 @@ ...@@ -140,25 +137,28 @@
reader.readAsText(importFiles[0]); reader.readAsText(importFiles[0]);
} }
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 () => {
let blob = new Blob([JSON.stringify(await getAllChats(localStorage.token))], {
type: 'application/json'
});
saveAs(blob, `chat-export-${Date.now()}.json`);
};
const deleteChats = async () => { const deleteChats = async () => {
await goto('/'); await goto('/');
await deleteAllChats(localStorage.token); await deleteAllChats(localStorage.token);
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
}; };
// Auth
let authEnabled = false;
let authType = 'Basic';
let authContent = '';
// Account
let currentPassword = '';
let newPassword = '';
let newPasswordConfirm = '';
// About
let ollamaVersion = '';
const updateOllamaAPIUrlHandler = async () => { const updateOllamaAPIUrlHandler = async () => {
API_BASE_URL = await updateOllamaAPIUrl(localStorage.token, API_BASE_URL); API_BASE_URL = await updateOllamaAPIUrl(localStorage.token, API_BASE_URL);
const _models = await getModels('ollama'); const _models = await getModels('ollama');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment