+page.svelte 20.1 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
<script>
2
	import { v4 as uuidv4 } from 'uuid';
Jannik Streidl's avatar
Jannik Streidl committed
3
	import { toast } from 'svelte-sonner';
Timothy J. Baek's avatar
Timothy J. Baek committed
4
	import { goto } from '$app/navigation';
Timothy J. Baek's avatar
Timothy J. Baek committed
5
	import { settings, user, config, modelfiles, models } from '$lib/stores';
6

Timothy J. Baek's avatar
Timothy J. Baek committed
7
	import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
8
	import { splitStream } from '$lib/utils';
9
	import { onMount, tick, getContext } from 'svelte';
10
	import { createModel } from '$lib/apis/ollama';
11
	import { createNewModelfile, getModelfileByTagName, getModelfiles } from '$lib/apis/modelfiles';
Timothy J. Baek's avatar
Timothy J. Baek committed
12

13
14
	const i18n = getContext('i18n');

Timothy J. Baek's avatar
Timothy J. Baek committed
15
16
17
18
19
	let loading = false;

	let filesInputElement;
	let inputFiles;
	let imageUrl = null;
20
21
22
23
24
25
26
	let digest = '';
	let pullProgress = null;
	let success = false;

	// ///////////
	// Modelfile
	// ///////////
Timothy J. Baek's avatar
Timothy J. Baek committed
27
28

	let title = '';
29
	let tagName = '';
Timothy J. Baek's avatar
Timothy J. Baek committed
30
31
32
33
34
	let desc = '';

	let raw = true;
	let advanced = false;

Timothy J. Baek's avatar
Timothy J. Baek committed
35
36
37
38
	// Raw Mode
	let content = '';

	// Builder Mode
Timothy J. Baek's avatar
Timothy J. Baek committed
39
40
41
42
43
44
	let model = '';
	let system = '';
	let template = '';
	let options = {
		// Advanced
		seed: 0,
Timothy J. Baek's avatar
Timothy J. Baek committed
45
		stop: '',
Timothy J. Baek's avatar
Timothy J. Baek committed
46
47
48
49
50
51
52
53
54
		temperature: '',
		repeat_penalty: '',
		repeat_last_n: '',
		mirostat: '',
		mirostat_eta: '',
		mirostat_tau: '',
		top_k: '',
		top_p: '',
		tfs_z: '',
55
56
		num_ctx: '',
		num_predict: ''
Timothy J. Baek's avatar
Timothy J. Baek committed
57
	};
Timothy J. Baek's avatar
Timothy J. Baek committed
58

59
60
	let modelfileCreator = null;

61
	$: tagName = title !== '' ? `${title.replace(/\s+/g, '-').toLowerCase()}:latest` : '';
62

Timothy J. Baek's avatar
Timothy J. Baek committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
	$: if (!raw) {
		content = `FROM ${model}
${template !== '' ? `TEMPLATE """${template}"""` : ''}
${options.seed !== 0 ? `PARAMETER seed ${options.seed}` : ''}
${options.stop !== '' ? `PARAMETER stop ${options.stop}` : ''}
${options.temperature !== '' ? `PARAMETER temperature ${options.temperature}` : ''}
${options.repeat_penalty !== '' ? `PARAMETER repeat_penalty ${options.repeat_penalty}` : ''}
${options.repeat_last_n !== '' ? `PARAMETER repeat_last_n ${options.repeat_last_n}` : ''}
${options.mirostat !== '' ? `PARAMETER mirostat ${options.mirostat}` : ''}
${options.mirostat_eta !== '' ? `PARAMETER mirostat_eta ${options.mirostat_eta}` : ''}
${options.mirostat_tau !== '' ? `PARAMETER mirostat_tau ${options.mirostat_tau}` : ''}
${options.top_k !== '' ? `PARAMETER top_k ${options.top_k}` : ''}
${options.top_p !== '' ? `PARAMETER top_p ${options.top_p}` : ''}
${options.tfs_z !== '' ? `PARAMETER tfs_z ${options.tfs_z}` : ''}
${options.num_ctx !== '' ? `PARAMETER num_ctx ${options.num_ctx}` : ''}
78
${options.num_predict !== '' ? `PARAMETER num_predict ${options.num_predict}` : ''}
Timothy J. Baek's avatar
Timothy J. Baek committed
79
80
SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
	}
Timothy J. Baek's avatar
Timothy J. Baek committed
81
82
83
84
85
86
87

	let suggestions = [
		{
			content: ''
		}
	];

Timothy J. Baek's avatar
Timothy J. Baek committed
88
	let categories = {
Timothy J. Baek's avatar
Timothy J. Baek committed
89
90
91
92
93
94
95
96
97
		character: false,
		assistant: false,
		writing: false,
		productivity: false,
		programming: false,
		'data analysis': false,
		lifestyle: false,
		education: false,
		business: false
Timothy J. Baek's avatar
Timothy J. Baek committed
98
99
	};

100
	const saveModelfile = async (modelfile) => {
101
102
		await createNewModelfile(localStorage.token, modelfile);
		await modelfiles.set(await getModelfiles(localStorage.token));
103
104
	};

Timothy J. Baek's avatar
Timothy J. Baek committed
105
106
	const submitHandler = async () => {
		loading = true;
Timothy J. Baek's avatar
Timothy J. Baek committed
107
108
109
110
111

		if (Object.keys(categories).filter((category) => categories[category]).length == 0) {
			toast.error(
				'Uh-oh! It looks like you missed selecting a category. Please choose one to complete your modelfile.'
			);
112
113
114
115
116
			loading = false;
			success = false;
			return success;
		}

117
118
119
120
		if (
			$models.map((model) => model.name).includes(tagName) ||
			(await getModelfileByTagName(localStorage.token, tagName).catch(() => false))
		) {
121
122
123
124
125
126
			toast.error(
				`Uh-oh! It looks like you already have a model named '${tagName}'. Please choose a different name to complete your modelfile.`
			);
			loading = false;
			success = false;
			return success;
Timothy J. Baek's avatar
Timothy J. Baek committed
127
128
		}

Timothy J. Baek's avatar
Timothy J. Baek committed
129
130
131
132
		if (
			title !== '' &&
			desc !== '' &&
			content !== '' &&
133
134
			Object.keys(categories).filter((category) => categories[category]).length > 0 &&
			!$models.includes(tagName)
Timothy J. Baek's avatar
Timothy J. Baek committed
135
		) {
136
			const res = await createModel(localStorage.token, tagName, content);
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

			if (res) {
				const reader = res.body
					.pipeThrough(new TextDecoderStream())
					.pipeThrough(splitStream('\n'))
					.getReader();

				while (true) {
					const { value, done } = await reader.read();
					if (done) break;

					try {
						let lines = value.split('\n');

						for (const line of lines) {
							if (line !== '') {
								console.log(line);
								let data = JSON.parse(line);
								console.log(data);

								if (data.error) {
									throw data.error;
								}
								if (data.detail) {
									throw data.detail;
								}

								if (data.status) {
									if (
										!data.digest &&
										!data.status.includes('writing') &&
										!data.status.includes('sha256')
									) {
										toast.success(data.status);

										if (data.status === 'success') {
											success = true;
										}
									} else {
										if (data.digest) {
											digest = data.digest;

											if (data.completed) {
												pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
											} else {
												pullProgress = 100;
											}
										}
									}
								}
							}
						}
					} catch (error) {
						console.log(error);
						toast.error(error);
					}
				}
Timothy J. Baek's avatar
Timothy J. Baek committed
194
			}
195
196
197
198
199
200
201
202
203

			if (success) {
				await saveModelfile({
					tagName: tagName,
					imageUrl: imageUrl,
					title: title,
					desc: desc,
					content: content,
					suggestionPrompts: suggestions.filter((prompt) => prompt.content !== ''),
204
205
					categories: Object.keys(categories).filter((category) => categories[category]),
					user: modelfileCreator !== null ? modelfileCreator : undefined
206
207
208
				});
				await goto('/modelfiles');
			}
Timothy J. Baek's avatar
Timothy J. Baek committed
209
210
		}
		loading = false;
211
		success = false;
Timothy J. Baek's avatar
Timothy J. Baek committed
212
	};
213

Timothy J. Baek's avatar
Timothy J. Baek committed
214
	onMount(async () => {
215
216
		window.addEventListener('message', async (event) => {
			if (
Timothy J. Baek's avatar
Timothy J. Baek committed
217
218
219
220
221
222
223
				![
					'https://ollamahub.com',
					'https://www.ollamahub.com',
					'https://openwebui.com',
					'https://www.openwebui.com',
					'http://localhost:5173'
				].includes(event.origin)
224
225
226
227
228
229
230
231
			)
				return;
			const modelfile = JSON.parse(event.data);
			console.log(modelfile);

			imageUrl = modelfile.imageUrl;
			title = modelfile.title;
			await tick();
232
233
234
			tagName = `${modelfile.user.username === 'hub' ? '' : `hub/`}${modelfile.user.username}/${
				modelfile.tagName
			}`;
235
236
237
238
239
240
241
242
243
244
245
			desc = modelfile.desc;
			content = modelfile.content;
			suggestions =
				modelfile.suggestionPrompts.length != 0
					? modelfile.suggestionPrompts
					: [
							{
								content: ''
							}
					  ];

246
247
248
249
			modelfileCreator = {
				username: modelfile.user.username,
				name: modelfile.user.name
			};
250
251
252
253
			for (const category of modelfile.categories) {
				categories[category.toLowerCase()] = true;
			}
		});
Timothy J. Baek's avatar
Timothy J. Baek committed
254
255
256
257

		if (window.opener ?? false) {
			window.opener.postMessage('loaded', '*');
		}
Timothy J. Baek's avatar
Timothy J. Baek committed
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

		if (sessionStorage.modelfile) {
			const modelfile = JSON.parse(sessionStorage.modelfile);
			console.log(modelfile);
			imageUrl = modelfile.imageUrl;
			title = modelfile.title;
			await tick();
			tagName = modelfile.tagName;
			desc = modelfile.desc;
			content = modelfile.content;
			suggestions =
				modelfile.suggestionPrompts.length != 0
					? modelfile.suggestionPrompts
					: [
							{
								content: ''
							}
					  ];

			for (const category of modelfile.categories) {
				categories[category.toLowerCase()] = true;
			}

			sessionStorage.removeItem('modelfile');
		}
283
	});
Timothy J. Baek's avatar
Timothy J. Baek committed
284
285
</script>

Timothy J. Baek's avatar
Timothy J. Baek committed
286
<div class="min-h-screen max-h-[100dvh] w-full flex justify-center dark:text-white">
Timothy J. Baek's avatar
Timothy J. Baek committed
287
	<div class=" flex flex-col justify-between w-full overflow-y-auto">
Timothy J. Baek's avatar
Timothy J. Baek committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
		<div class="max-w-2xl mx-auto w-full px-3 md:px-0 my-10">
			<input
				bind:this={filesInputElement}
				bind:files={inputFiles}
				type="file"
				hidden
				accept="image/*"
				on:change={() => {
					let reader = new FileReader();
					reader.onload = (event) => {
						let originalImageUrl = `${event.target.result}`;

						const img = new Image();
						img.src = originalImageUrl;

						img.onload = function () {
							const canvas = document.createElement('canvas');
							const ctx = canvas.getContext('2d');

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
							// Calculate the aspect ratio of the image
							const aspectRatio = img.width / img.height;

							// Calculate the new width and height to fit within 100x100
							let newWidth, newHeight;
							if (aspectRatio > 1) {
								newWidth = 100 * aspectRatio;
								newHeight = 100;
							} else {
								newWidth = 100;
								newHeight = 100 / aspectRatio;
							}

							// Set the canvas size
							canvas.width = 100;
							canvas.height = 100;

							// Calculate the position to center the image
							const offsetX = (100 - newWidth) / 2;
							const offsetY = (100 - newHeight) / 2;
Timothy J. Baek's avatar
Timothy J. Baek committed
327

328
329
							// Draw the image on the canvas
							ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);
Timothy J. Baek's avatar
Timothy J. Baek committed
330
331

							// Get the base64 representation of the compressed image
332
							const compressedSrc = canvas.toDataURL('image/jpeg');
Timothy J. Baek's avatar
Timothy J. Baek committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

							// Display the compressed image
							imageUrl = compressedSrc;

							inputFiles = null;
						};
					};

					if (
						inputFiles &&
						inputFiles.length > 0 &&
						['image/gif', 'image/jpeg', 'image/png'].includes(inputFiles[0]['type'])
					) {
						reader.readAsDataURL(inputFiles[0]);
					} else {
						console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
						inputFiles = null;
					}
				}}
			/>

354
			<div class=" text-2xl font-semibold mb-6">{$i18n.t('My Modelfiles')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

			<button
				class="flex space-x-1"
				on:click={() => {
					history.back();
				}}
			>
				<div class=" self-center">
					<svg
						xmlns="http://www.w3.org/2000/svg"
						viewBox="0 0 20 20"
						fill="currentColor"
						class="w-4 h-4"
					>
						<path
							fill-rule="evenodd"
							d="M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z"
							clip-rule="evenodd"
						/>
					</svg>
				</div>
376
				<div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
			</button>
			<hr class="my-3 dark:border-gray-700" />

			<form
				class="flex flex-col"
				on:submit|preventDefault={() => {
					submitHandler();
				}}
			>
				<div class="flex justify-center my-4">
					<div class="self-center">
						<button
							class=" {imageUrl
								? ''
								: 'p-6'} rounded-full dark:bg-gray-700 border border-dashed border-gray-200"
							type="button"
							on:click={() => {
								filesInputElement.click();
							}}
						>
							{#if imageUrl}
								<img
									src={imageUrl}
									alt="modelfile profile"
									class=" rounded-full w-20 h-20 object-cover"
								/>
							{:else}
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 24 24"
									fill="currentColor"
									class="w-8"
								>
									<path
										fill-rule="evenodd"
										d="M12 3.75a.75.75 0 01.75.75v6.75h6.75a.75.75 0 010 1.5h-6.75v6.75a.75.75 0 01-1.5 0v-6.75H4.5a.75.75 0 010-1.5h6.75V4.5a.75.75 0 01.75-.75z"
										clip-rule="evenodd"
									/>
								</svg>
							{/if}
						</button>
					</div>
				</div>

421
422
				<div class="my-2 flex space-x-2">
					<div class="flex-1">
423
						<div class=" text-sm font-semibold mb-2">{$i18n.t('Name')}*</div>
424
425
426
427

						<div>
							<input
								class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
428
								placeholder={$i18n.t('Name your modelfile')}
429
430
431
432
433
434
435
								bind:value={title}
								required
							/>
						</div>
					</div>

					<div class="flex-1">
436
						<div class=" text-sm font-semibold mb-2">{$i18n.t('Model Tag Name')}*</div>
437
438
439
440

						<div>
							<input
								class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
441
								placeholder={$i18n.t('Add a model tag name')}
442
443
444
445
								bind:value={tagName}
								required
							/>
						</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
446
447
448
449
					</div>
				</div>

				<div class="my-2">
450
					<div class=" text-sm font-semibold mb-2">{$i18n.t('Description')}*</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
451
452
453
454

					<div>
						<input
							class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
455
							placeholder={$i18n.t('Add a short description about what this modelfile does')}
Timothy J. Baek's avatar
Timothy J. Baek committed
456
457
458
459
460
461
462
463
							bind:value={desc}
							required
						/>
					</div>
				</div>

				<div class="my-2">
					<div class="flex w-full justify-between">
464
						<div class=" self-center text-sm font-semibold">{$i18n.t('Modelfile')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
465
466
467
468
469
470
471
472
473

						<button
							class="p-1 px-3 text-xs flex rounded transition"
							type="button"
							on:click={() => {
								raw = !raw;
							}}
						>
							{#if raw}
474
								<span class="ml-2 self-center"> {$i18n.t('Raw Format')} </span>
Timothy J. Baek's avatar
Timothy J. Baek committed
475
							{:else}
476
								<span class="ml-2 self-center"> {$i18n.t('Builder Mode')} </span>
Timothy J. Baek's avatar
Timothy J. Baek committed
477
478
479
480
481
482
483
484
							{/if}
						</button>
					</div>

					<!-- <div class=" text-sm font-semibold mb-2"></div> -->

					{#if raw}
						<div class="mt-2">
485
							<div class=" text-xs font-semibold mb-2">{$i18n.t('Content')}*</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
486
487
488
489
490
491
492
493
494
495
496
497

							<div>
								<textarea
									class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
									placeholder={`FROM llama2\nPARAMETER temperature 1\nSYSTEM """\nYou are Mario from Super Mario Bros, acting as an assistant.\n"""`}
									rows="6"
									bind:value={content}
									required
								/>
							</div>

							<div class="text-xs text-gray-400 dark:text-gray-500">
498
499
								{$i18n.t('Not sure what to write? Switch to')}
								<button
Timothy J. Baek's avatar
Timothy J. Baek committed
500
501
502
503
									class="text-gray-500 dark:text-gray-300 font-medium cursor-pointer"
									type="button"
									on:click={() => {
										raw = !raw;
504
									}}>{$i18n.t('Builder Mode')}</button
Timothy J. Baek's avatar
Timothy J. Baek committed
505
506
507
508
								>
								or
								<a
									class=" text-gray-500 dark:text-gray-300 font-medium"
Timothy J. Baek's avatar
Timothy J. Baek committed
509
									href="https://openwebui.com"
Timothy J. Baek's avatar
Timothy J. Baek committed
510
511
									target="_blank"
								>
512
									{$i18n.t('Click here to check other modelfiles.')}
Timothy J. Baek's avatar
Timothy J. Baek committed
513
514
515
516
517
								</a>
							</div>
						</div>
					{:else}
						<div class="my-2">
518
							<div class=" text-xs font-semibold mb-2">{$i18n.t('From (Base Model)')}*</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
519
520
521
522
523
524
525
526
527

							<div>
								<input
									class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
									placeholder="Write a modelfile base model name (e.g. llama2, mistral)"
									bind:value={model}
									required
								/>
							</div>
528
529

							<div class="mt-1 text-xs text-gray-400 dark:text-gray-500">
530
531
								{$i18n.t('To access the available model names for downloading,')}
								<a
532
									class=" text-gray-500 dark:text-gray-300 font-medium"
533
									href="https://ollama.com/library"
534
									target="_blank">{$i18n.t('click here.')}</a
535
536
								>
							</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
537
538
						</div>

539
						<div class="my-1">
540
							<div class=" text-xs font-semibold mb-2">{$i18n.t('System Prompt')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
541
542
543
544
545
546
547
548
549
550
551
552

							<div>
								<textarea
									class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg -mb-1"
									placeholder={`Write your modelfile system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
									rows="4"
									bind:value={system}
								/>
							</div>
						</div>

						<div class="flex w-full justify-between">
553
554
555
							<div class=" self-center text-sm font-semibold">
								{$i18n.t('Modelfile Advanced Settings')}
							</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
556
557
558
559
560
561
562
563
564

							<button
								class="p-1 px-3 text-xs flex rounded transition"
								type="button"
								on:click={() => {
									advanced = !advanced;
								}}
							>
								{#if advanced}
Ased Mammad's avatar
Ased Mammad committed
565
									<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
Timothy J. Baek's avatar
Timothy J. Baek committed
566
								{:else}
Ased Mammad's avatar
Ased Mammad committed
567
									<span class="ml-2 self-center">{$i18n.t('Default')}</span>
Timothy J. Baek's avatar
Timothy J. Baek committed
568
569
570
571
572
573
								{/if}
							</button>
						</div>

						{#if advanced}
							<div class="my-2">
574
								<div class=" text-xs font-semibold mb-2">{$i18n.t('Template')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
575
576
577
578
579
580
581
582
583
584
585
586

								<div>
									<textarea
										class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg -mb-1"
										placeholder="Write your modelfile template content here"
										rows="4"
										bind:value={template}
									/>
								</div>
							</div>

							<div class="my-2">
587
								<div class=" text-xs font-semibold mb-2">{$i18n.t('Parameters')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
588
589

								<div>
Timothy J. Baek's avatar
Timothy J. Baek committed
590
									<AdvancedParams bind:options />
Timothy J. Baek's avatar
Timothy J. Baek committed
591
592
593
594
595
596
597
598
								</div>
							</div>
						{/if}
					{/if}
				</div>

				<div class="my-2">
					<div class="flex w-full justify-between mb-2">
599
						<div class=" self-center text-sm font-semibold">{$i18n.t('Prompt suggestions')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
600
601
602
603
604

						<button
							class="p-1 px-3 text-xs flex rounded transition"
							type="button"
							on:click={() => {
Timothy J. Baek's avatar
Timothy J. Baek committed
605
606
607
								if (suggestions.length === 0 || suggestions.at(-1).content !== '') {
									suggestions = [...suggestions, { content: '' }];
								}
Timothy J. Baek's avatar
Timothy J. Baek committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
							}}
						>
							<svg
								xmlns="http://www.w3.org/2000/svg"
								viewBox="0 0 20 20"
								fill="currentColor"
								class="w-4 h-4"
							>
								<path
									d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
								/>
							</svg>
						</button>
					</div>
					<div class="flex flex-col space-y-1">
						{#each suggestions as prompt, promptIdx}
							<div class=" flex border dark:border-gray-600 rounded-lg">
								<input
									class="px-3 py-1.5 text-sm w-full bg-transparent outline-none border-r dark:border-gray-600"
627
									placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
Timothy J. Baek's avatar
Timothy J. Baek committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
									bind:value={prompt.content}
								/>

								<button
									class="px-2"
									type="button"
									on:click={() => {
										suggestions.splice(promptIdx, 1);
										suggestions = suggestions;
									}}
								>
									<svg
										xmlns="http://www.w3.org/2000/svg"
										viewBox="0 0 20 20"
										fill="currentColor"
										class="w-4 h-4"
									>
										<path
											d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
										/>
									</svg>
								</button>
							</div>
						{/each}
					</div>
				</div>

				<div class="my-2">
656
					<div class=" text-sm font-semibold mb-2">{$i18n.t('Categories')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
657
658
659
660
661

					<div class="grid grid-cols-4">
						{#each Object.keys(categories) as category}
							<div class="flex space-x-2 text-sm">
								<input type="checkbox" bind:checked={categories[category]} />
Timothy J. Baek's avatar
Timothy J. Baek committed
662
								<div class="capitalize">{category}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
663
664
665
666
667
							</div>
						{/each}
					</div>
				</div>

668
669
				{#if pullProgress !== null}
					<div class="my-2">
670
						<div class=" text-sm font-semibold mb-2">{$i18n.t('Pull Progress')}</div>
671
672
						<div class="w-full rounded-full dark:bg-gray-800">
							<div
Timothy J. Baek's avatar
Timothy J. Baek committed
673
								class="dark:bg-gray-600 bg-gray-500 text-xs font-medium text-gray-100 text-center p-0.5 leading-none rounded-full"
674
675
676
677
678
679
680
681
682
683
684
								style="width: {Math.max(15, pullProgress ?? 0)}%"
							>
								{pullProgress ?? 0}%
							</div>
						</div>
						<div class="mt-1 text-xs dark:text-gray-500" style="font-size: 0.5rem;">
							{digest}
						</div>
					</div>
				{/if}

Timothy J. Baek's avatar
Timothy J. Baek committed
685
686
687
688
689
690
691
692
				<div class="my-2 flex justify-end">
					<button
						class=" text-sm px-3 py-2 transition rounded-xl {loading
							? ' cursor-not-allowed bg-gray-100 dark:bg-gray-800'
							: ' bg-gray-50 hover:bg-gray-100 dark:bg-gray-700 dark:hover:bg-gray-800'} flex"
						type="submit"
						disabled={loading}
					>
693
						<div class=" self-center font-medium">{$i18n.t('Save & Create')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

						{#if loading}
							<div class="ml-1.5 self-center">
								<svg
									class=" w-4 h-4"
									viewBox="0 0 24 24"
									fill="currentColor"
									xmlns="http://www.w3.org/2000/svg"
									><style>
										.spinner_ajPY {
											transform-origin: center;
											animation: spinner_AtaB 0.75s infinite linear;
										}
										@keyframes spinner_AtaB {
											100% {
												transform: rotate(360deg);
											}
										}
									</style><path
										d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
										opacity=".25"
									/><path
										d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
										class="spinner_ajPY"
									/></svg
								>
							</div>
						{/if}
					</button>
				</div>
			</form>
		</div>
	</div>
</div>