+page.svelte 4.32 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<script lang="ts">
	import { toast } from 'svelte-sonner';
	import fileSaver from 'file-saver';
	const { saveAs } = fileSaver;

	import { onMount, getContext } from 'svelte';

	import { WEBUI_NAME, modelfiles, settings, showSidebar, user } from '$lib/stores';
	import { createModel, deleteModel } from '$lib/apis/ollama';
	import {
		createNewModelfile,
		deleteModelfileByTagName,
		getModelfiles
	} from '$lib/apis/modelfiles';
	import { goto } from '$app/navigation';
	import MenuLines from '$lib/components/icons/MenuLines.svelte';
	import Tooltip from '$lib/components/common/Tooltip.svelte';
	import Modelfiles from '$lib/components/workspace/Modelfiles.svelte';
	import Prompts from '$lib/components/workspace/Prompts.svelte';
	import Documents from '$lib/components/workspace/Documents.svelte';
	import Playground from '$lib/components/workspace/Playground.svelte';

	const i18n = getContext('i18n');

	let tab = '';

	let localModelfiles = [];
	let importFiles;
	let modelfilesImportInputElement: HTMLInputElement;

	const deleteModelHandler = async (tagName) => {
		let success = null;

		success = await deleteModel(localStorage.token, tagName).catch((err) => {
			toast.error(err);
			return null;
		});

		if (success) {
			toast.success($i18n.t(`Deleted {{tagName}}`, { tagName }));
		}

		return success;
	};

	const deleteModelfile = async (tagName) => {
		await deleteModelHandler(tagName);
		await deleteModelfileByTagName(localStorage.token, tagName);
		await modelfiles.set(await getModelfiles(localStorage.token));
	};

	const shareModelfile = async (modelfile) => {
		toast.success($i18n.t('Redirecting you to OpenWebUI Community'));

		const url = 'https://openwebui.com';

		const tab = await window.open(`${url}/modelfiles/create`, '_blank');
		window.addEventListener(
			'message',
			(event) => {
				if (event.origin !== url) return;
				if (event.data === 'loaded') {
					tab.postMessage(JSON.stringify(modelfile), '*');
				}
			},
			false
		);
	};

	const saveModelfiles = async (modelfiles) => {
		let blob = new Blob([JSON.stringify(modelfiles)], {
			type: 'application/json'
		});
		saveAs(blob, `modelfiles-export-${Date.now()}.json`);
	};

	onMount(() => {
		localModelfiles = JSON.parse(localStorage.getItem('modelfiles') ?? '[]');

		if (localModelfiles) {
			console.log(localModelfiles);
		}
	});
</script>

<svelte:head>
	<title>
		{$i18n.t('Workspace')} | {$WEBUI_NAME}
	</title>
</svelte:head>

Timothy J. Baek's avatar
Timothy J. Baek committed
92
93
94
95
96
97
98
99
100
101
102
103
104
<div class=" flex flex-col w-full min-h-screen">
	<div class=" px-4 pt-3 mb-1.5">
		<div class=" flex items-center">
			<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
				<button
					id="sidebar-toggle-button"
					class="cursor-pointer p-2 flex rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
					on:click={() => {
						showSidebar.set(!$showSidebar);
					}}
				>
					<div class=" m-auto self-center">
						<MenuLines />
Timothy J. Baek's avatar
Timothy J. Baek committed
105
					</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
106
				</button>
Timothy J. Baek's avatar
Timothy J. Baek committed
107
			</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
108
			<div class="flex items-center text-xl font-semibold">{$i18n.t('Workspace')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
109
110
		</div>
	</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

	<div class="px-4 mb-1">
		<div
			class="flex scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-xl bg-transparent/10 p-1"
		>
			<button
				class="min-w-fit rounded-lg p-1.5 px-3 {tab === ''
					? 'bg-gray-50 dark:bg-gray-850'
					: ''} transition"
				type="button"
				on:click={() => {
					tab = '';
				}}>Modelfiles</button
			>

			<button
				class="min-w-fit rounded-lg p-1.5 px-3 {tab === 'prompts'
					? 'bg-gray-50 dark:bg-gray-850'
					: ''} transition"
				type="button"
				on:click={() => {
					tab = 'prompts';
				}}>Prompts</button
			>

			<button
				class="min-w-fit rounded-lg p-1.5 px-3 {tab === 'documents'
					? 'bg-gray-50 dark:bg-gray-850'
					: ''} transition"
				type="button"
				on:click={() => {
					tab = 'documents';
				}}>Documents</button
			>

			<button
				class="min-w-fit rounded-lg p-1.5 px-3 {tab === 'playground'
					? 'bg-gray-50 dark:bg-gray-850'
					: ''} transition"
				type="button"
				on:click={() => {
					tab = 'playground';
				}}>Playground</button
			>
		</div>
	</div>

	<hr class=" my-2 dark:border-gray-850" />

	<div class=" py-1 px-5 h-full">
		{#if tab === ''}
			<Modelfiles />
		{:else if tab === 'prompts'}
			<Prompts />
		{:else if tab === 'documents'}
			<Documents />
		{:else if tab === 'playground'}
			<Playground />
		{/if}
	</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
171
</div>