Unverified Commit 5166e92f authored by arkohut's avatar arkohut Committed by GitHub
Browse files

Merge branch 'dev' into support-py-for-run-code

parents b443d61c b6b71c08
...@@ -2,184 +2,149 @@ ...@@ -2,184 +2,149 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { settings, user, config, models } from '$lib/stores';
import { onMount, getContext } from 'svelte'; import { onMount, tick, getContext } from 'svelte';
import { page } from '$app/stores'; import { addNewModel, getModelById, getModelInfos } from '$lib/apis/models';
import { getModels } from '$lib/apis';
import { settings, user, config, modelfiles } from '$lib/stores';
import { splitStream } from '$lib/utils';
import { createModel } from '$lib/apis/ollama';
import { getModelfiles, updateModelfileByTagName } from '$lib/apis/modelfiles';
import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte'; import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
import Checkbox from '$lib/components/common/Checkbox.svelte';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
let loading = false;
let filesInputElement; let filesInputElement;
let inputFiles; let inputFiles;
let imageUrl = null;
let digest = ''; let showAdvanced = false;
let pullProgress = null; let showPreview = false;
let loading = false;
let success = false; let success = false;
let modelfile = null;
// /////////// // ///////////
// Modelfile // Model
// /////////// // ///////////
let title = ''; let id = '';
let tagName = ''; let name = '';
let desc = '';
// Raw Mode let params = {};
let content = ''; let capabilities = {
vision: true
};
let suggestions = [ let info = {
{ id: '',
content: '' base_model_id: null,
name: '',
meta: {
profile_image_url: null,
description: '',
suggestion_prompts: [
{
content: ''
}
]
},
params: {
system: ''
} }
];
let categories = {
character: false,
assistant: false,
writing: false,
productivity: false,
programming: false,
'data analysis': false,
lifestyle: false,
education: false,
business: false
}; };
onMount(() => { $: if (name) {
tagName = $page.url.searchParams.get('tag'); id = name.replace(/\s+/g, '-').toLowerCase();
}
if (tagName) { const submitHandler = async () => {
modelfile = $modelfiles.filter((modelfile) => modelfile.tagName === tagName)[0]; loading = true;
console.log(modelfile); info.id = id;
info.name = name;
info.meta.capabilities = capabilities;
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
imageUrl = modelfile.imageUrl; if ($models.find((m) => m.id === info.id)) {
title = modelfile.title; toast.error(
desc = modelfile.desc; `Error: A model with the ID '${info.id}' already exists. Please select a different ID to proceed.`
content = modelfile.content; );
suggestions = loading = false;
modelfile.suggestionPrompts.length != 0 success = false;
? modelfile.suggestionPrompts return success;
: [ }
{
content: '' if (info) {
} const res = await addNewModel(localStorage.token, {
]; ...info,
meta: {
...info.meta,
profile_image_url: info.meta.profile_image_url ?? '/favicon.png',
suggestion_prompts: info.meta.suggestion_prompts
? info.meta.suggestion_prompts.filter((prompt) => prompt.content !== '')
: null
},
params: { ...info.params, ...params }
});
for (const category of modelfile.categories) { if (res) {
categories[category.toLowerCase()] = true; toast.success('Model created successfully!');
await goto('/workspace/models');
await models.set(await getModels(localStorage.token));
} }
} else {
goto('/workspace/modelfiles');
} }
});
const updateModelfile = async (modelfile) => { loading = false;
await updateModelfileByTagName(localStorage.token, modelfile.tagName, modelfile); success = false;
await modelfiles.set(await getModelfiles(localStorage.token));
}; };
const updateHandler = async () => { const initModel = async (model) => {
loading = true; name = model.name;
await tick();
if (Object.keys(categories).filter((category) => categories[category]).length == 0) { id = model.id;
toast.error(
'Uh-oh! It looks like you missed selecting a category. Please choose one to complete your modelfile.'
);
}
if ( params = { ...params, ...model?.info?.params };
title !== '' && params.stop = params?.stop ? (params?.stop ?? []).join(',') : null;
desc !== '' &&
content !== '' &&
Object.keys(categories).filter((category) => categories[category]).length > 0
) {
const res = await createModel(localStorage.token, tagName, content);
if (res) { capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
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) { info = {
if ( ...info,
!data.digest && ...model.info
!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);
}
}
}
if (success) { onMount(async () => {
await updateModelfile({ window.addEventListener('message', async (event) => {
tagName: tagName, if (
imageUrl: imageUrl, ![
title: title, 'https://ollamahub.com',
desc: desc, 'https://www.ollamahub.com',
content: content, 'https://openwebui.com',
suggestionPrompts: suggestions.filter((prompt) => prompt.content !== ''), 'https://www.openwebui.com',
categories: Object.keys(categories).filter((category) => categories[category]) 'http://localhost:5173'
}); ].includes(event.origin)
await goto('/workspace/modelfiles'); )
} return;
const model = JSON.parse(event.data);
console.log(model);
initModel(model);
});
if (window.opener ?? false) {
window.opener.postMessage('loaded', '*');
} }
loading = false;
success = false; if (sessionStorage.model) {
}; const model = JSON.parse(sessionStorage.model);
sessionStorage.removeItem('model');
console.log(model);
initModel(model);
}
});
</script> </script>
<div class="w-full max-h-full"> <div class="w-full max-h-full">
...@@ -229,7 +194,7 @@ ...@@ -229,7 +194,7 @@
const compressedSrc = canvas.toDataURL('image/jpeg'); const compressedSrc = canvas.toDataURL('image/jpeg');
// Display the compressed image // Display the compressed image
imageUrl = compressedSrc; info.meta.profile_image_url = compressedSrc;
inputFiles = null; inputFiles = null;
}; };
...@@ -270,16 +235,18 @@ ...@@ -270,16 +235,18 @@
</div> </div>
<div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div> <div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div>
</button> </button>
<!-- <hr class="my-3 dark:border-gray-700" /> -->
<form <form
class="flex flex-col max-w-2xl mx-auto mt-4 mb-10" class="flex flex-col max-w-2xl mx-auto mt-4 mb-10"
on:submit|preventDefault={() => { on:submit|preventDefault={() => {
updateHandler(); submitHandler();
}} }}
> >
<div class="flex justify-center my-4"> <div class="flex justify-center my-4">
<div class="self-center"> <div class="self-center">
<button <button
class=" {imageUrl class=" {info.meta.profile_image_url
? '' ? ''
: 'p-6'} rounded-full dark:bg-gray-700 border border-dashed border-gray-200" : 'p-6'} rounded-full dark:bg-gray-700 border border-dashed border-gray-200"
type="button" type="button"
...@@ -287,9 +254,9 @@ ...@@ -287,9 +254,9 @@
filesInputElement.click(); filesInputElement.click();
}} }}
> >
{#if imageUrl} {#if info.meta.profile_image_url}
<img <img
src={imageUrl} src={info.meta.profile_image_url}
alt="modelfile profile" alt="modelfile profile"
class=" rounded-full w-20 h-20 object-cover" class=" rounded-full w-20 h-20 object-cover"
/> />
...@@ -298,7 +265,7 @@ ...@@ -298,7 +265,7 @@
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" viewBox="0 0 24 24"
fill="currentColor" fill="currentColor"
class="w-8" class="size-8"
> >
<path <path
fill-rule="evenodd" fill-rule="evenodd"
...@@ -318,22 +285,21 @@ ...@@ -318,22 +285,21 @@
<div> <div>
<input <input
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg" class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Name your modelfile')} placeholder={$i18n.t('Name your model')}
bind:value={title} bind:value={name}
required required
/> />
</div> </div>
</div> </div>
<div class="flex-1"> <div class="flex-1">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Model Tag Name')}*</div> <div class=" text-sm font-semibold mb-2">{$i18n.t('Model ID')}*</div>
<div> <div>
<input <input
class="px-3 py-1.5 text-sm w-full bg-transparent disabled:text-gray-500 border dark:border-gray-600 outline-none rounded-lg" class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Add a model tag name')} placeholder={$i18n.t('Add a model id')}
value={tagName} bind:value={id}
disabled
required required
/> />
</div> </div>
...@@ -341,130 +307,231 @@ ...@@ -341,130 +307,231 @@
</div> </div>
<div class="my-2"> <div class="my-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Description')}*</div> <div class=" text-sm font-semibold mb-2">{$i18n.t('Base Model (From)')}</div>
<div> <div>
<input <select
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg" class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Add a short description about what this modelfile does')} placeholder="Select a base model (e.g. llama3, gpt-4o)"
bind:value={desc} bind:value={info.base_model_id}
required required
>
<option value={null} class=" text-gray-900">{$i18n.t('Select a base model')}</option>
{#each $models.filter((m) => !m?.preset) as model}
<option value={model.id} class=" text-gray-900">{model.name}</option>
{/each}
</select>
</div>
</div>
<div class="my-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Description')}</div>
<div>
<input
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Add a short description about what this model does')}
bind:value={info.meta.description}
/> />
</div> </div>
</div> </div>
<div class="my-2"> <div class="my-2">
<div class="flex w-full justify-between"> <div class="flex w-full justify-between">
<div class=" self-center text-sm font-semibold">{$i18n.t('Modelfile')}</div> <div class=" self-center text-sm font-semibold">{$i18n.t('Model Params')}</div>
</div> </div>
<!-- <div class=" text-sm font-semibold mb-2"></div> -->
<div class="mt-2"> <div class="mt-2">
<div class=" text-xs font-semibold mb-2">{$i18n.t('Content')}*</div> <div class="my-1">
<div class=" text-xs font-semibold mb-2">{$i18n.t('System Prompt')}</div>
<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 model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
rows="4"
bind:value={info.params.system}
/>
</div>
</div>
<div> <div class="flex w-full justify-between">
<textarea <div class=" self-center text-xs font-semibold">
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg" {$i18n.t('Advanced Params')}
placeholder={`FROM llama2\nPARAMETER temperature 1\nSYSTEM """\nYou are Mario from Super Mario Bros, acting as an assistant.\n"""`} </div>
rows="6"
bind:value={content} <button
required class="p-1 px-3 text-xs flex rounded transition"
/> type="button"
on:click={() => {
showAdvanced = !showAdvanced;
}}
>
{#if showAdvanced}
<span class="ml-2 self-center">{$i18n.t('Hide')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Show')}</span>
{/if}
</button>
</div> </div>
{#if showAdvanced}
<div class="my-2">
<AdvancedParams
bind:params
on:change={(e) => {
info.params = { ...info.params, ...params };
}}
/>
</div>
{/if}
</div> </div>
</div> </div>
<div class="my-2"> <div class="my-2">
<div class="flex w-full justify-between mb-2"> <div class="flex w-full justify-between items-center">
<div class=" self-center text-sm font-semibold">{$i18n.t('Prompt suggestions')}</div> <div class="flex w-full justify-between items-center">
<div class=" self-center text-sm font-semibold">{$i18n.t('Prompt suggestions')}</div>
<button
class="p-1 text-xs flex rounded transition"
type="button"
on:click={() => {
if (info.meta.suggestion_prompts === null) {
info.meta.suggestion_prompts = [{ content: '' }];
} else {
info.meta.suggestion_prompts = null;
}
}}
>
{#if info.meta.suggestion_prompts === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
{/if}
</button>
</div>
<button {#if info.meta.suggestion_prompts !== null}
class="p-1 px-3 text-xs flex rounded transition" <button
type="button" class="p-1 px-2 text-xs flex rounded transition"
on:click={() => { type="button"
if (suggestions.length === 0 || suggestions.at(-1).content !== '') { on:click={() => {
suggestions = [...suggestions, { content: '' }]; if (
} info.meta.suggestion_prompts.length === 0 ||
}} info.meta.suggestion_prompts.at(-1).content !== ''
> ) {
<svg info.meta.suggestion_prompts = [...info.meta.suggestion_prompts, { content: '' }];
xmlns="http://www.w3.org/2000/svg" }
viewBox="0 0 20 20" }}
fill="currentColor"
class="w-4 h-4"
> >
<path <svg
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" xmlns="http://www.w3.org/2000/svg"
/> viewBox="0 0 20 20"
</svg> fill="currentColor"
</button> 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>
{/if}
</div> </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"
placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
bind:value={prompt.content}
/>
<button {#if info.meta.suggestion_prompts}
class="px-2" <div class="flex flex-col space-y-1 mt-2">
type="button" {#if info.meta.suggestion_prompts.length > 0}
on:click={() => { {#each info.meta.suggestion_prompts as prompt, promptIdx}
suggestions.splice(promptIdx, 1); <div class=" flex border dark:border-gray-600 rounded-lg">
suggestions = suggestions; <input
}} class="px-3 py-1.5 text-sm w-full bg-transparent outline-none border-r dark:border-gray-600"
> placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
<svg bind:value={prompt.content}
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> <button
</div> class="px-2"
{/each} type="button"
</div> on:click={() => {
info.meta.suggestion_prompts.splice(promptIdx, 1);
info.meta.suggestion_prompts = info.meta.suggestion_prompts;
}}
>
<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}
{:else}
<div class="text-xs text-center">No suggestion prompts</div>
{/if}
</div>
{/if}
</div> </div>
<div class="my-2"> <div class="my-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Categories')}</div> <div class="flex w-full justify-between">
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
<div class="grid grid-cols-4"> </div>
{#each Object.keys(categories) as category} <div class="flex flex-col">
<div class="flex space-x-2 text-sm"> {#each Object.keys(capabilities) as capability}
<input type="checkbox" bind:checked={categories[category]} /> <div class=" flex items-center gap-2">
<Checkbox
state={capabilities[capability] ? 'checked' : 'unchecked'}
on:change={(e) => {
capabilities[capability] = e.detail === 'checked';
}}
/>
<div class=" capitalize">{category}</div> <div class=" py-1.5 text-sm w-full capitalize">
{$i18n.t(capability)}
</div>
</div> </div>
{/each} {/each}
</div> </div>
</div> </div>
{#if pullProgress !== null} <div class="my-2 text-gray-500">
<div class="my-2"> <div class="flex w-full justify-between mb-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Pull Progress')}</div> <div class=" self-center text-sm font-semibold">{$i18n.t('JSON Preview')}</div>
<div class="w-full rounded-full dark:bg-gray-800">
<div <button
class="dark:bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full" class="p-1 px-3 text-xs flex rounded transition"
style="width: {Math.max(15, pullProgress ?? 0)}%" type="button"
> on:click={() => {
{pullProgress ?? 0}% showPreview = !showPreview;
</div> }}
</div> >
<div class="mt-1 text-xs dark:text-gray-500" style="font-size: 0.5rem;"> {#if showPreview}
{digest} <span class="ml-2 self-center">{$i18n.t('Hide')}</span>
</div> {:else}
<span class="ml-2 self-center">{$i18n.t('Show')}</span>
{/if}
</button>
</div> </div>
{/if}
<div class="my-2 flex justify-end"> {#if showPreview}
<div>
<textarea
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
rows="10"
value={JSON.stringify(info, null, 2)}
disabled
readonly
/>
</div>
{/if}
</div>
<div class="my-2 flex justify-end mb-20">
<button <button
class=" text-sm px-3 py-2 transition rounded-xl {loading class=" text-sm px-3 py-2 transition rounded-xl {loading
? ' cursor-not-allowed bg-gray-100 dark:bg-gray-800' ? ' cursor-not-allowed bg-gray-100 dark:bg-gray-800'
...@@ -472,7 +539,7 @@ ...@@ -472,7 +539,7 @@
type="submit" type="submit"
disabled={loading} disabled={loading}
> >
<div class=" self-center font-medium">{$i18n.t('Save & Update')}</div> <div class=" self-center font-medium">{$i18n.t('Save & Create')}</div>
{#if loading} {#if loading}
<div class="ml-1.5 self-center"> <div class="ml-1.5 self-center">
......
<script>
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
import { onMount, getContext } from 'svelte';
import { page } from '$app/stores';
import { settings, user, config, models } from '$lib/stores';
import { splitStream } from '$lib/utils';
import { getModelInfos, updateModelById } from '$lib/apis/models';
import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
import { getModels } from '$lib/apis';
import Checkbox from '$lib/components/common/Checkbox.svelte';
const i18n = getContext('i18n');
let loading = false;
let success = false;
let filesInputElement;
let inputFiles;
let digest = '';
let pullProgress = null;
let showAdvanced = false;
let showPreview = false;
// ///////////
// model
// ///////////
let model = null;
let id = '';
let name = '';
let info = {
id: '',
base_model_id: null,
name: '',
meta: {
profile_image_url: '/favicon.png',
description: '',
suggestion_prompts: null
},
params: {
system: ''
}
};
let params = {};
let capabilities = {
vision: true
};
const updateHandler = async () => {
loading = true;
info.id = id;
info.name = name;
info.meta.capabilities = capabilities;
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
const res = await updateModelById(localStorage.token, info.id, info);
if (res) {
toast.success('Model updated successfully');
await goto('/workspace/models');
await models.set(await getModels(localStorage.token));
}
loading = false;
success = false;
};
onMount(() => {
const _id = $page.url.searchParams.get('id');
if (_id) {
model = $models.find((m) => m.id === _id);
if (model) {
id = model.id;
name = model.name;
info = {
...info,
...JSON.parse(
JSON.stringify(
model?.info
? model?.info
: {
id: model.id,
name: model.name
}
)
)
};
if (model.preset && model.owned_by === 'ollama' && !info.base_model_id.includes(':')) {
info.base_model_id = `${info.base_model_id}:latest`;
}
params = { ...params, ...model?.info?.params };
params.stop = params?.stop ? (params?.stop ?? []).join(',') : null;
if (model?.info?.meta?.capabilities) {
capabilities = { ...capabilities, ...model?.info?.meta?.capabilities };
}
console.log(model);
} else {
goto('/workspace/models');
}
} else {
goto('/workspace/models');
}
});
</script>
<div class="w-full max-h-full">
<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');
// 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;
// Draw the image on the canvas
ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);
// Get the base64 representation of the compressed image
const compressedSrc = canvas.toDataURL('image/jpeg');
// Display the compressed image
info.meta.profile_image_url = compressedSrc;
inputFiles = null;
};
};
if (
inputFiles &&
inputFiles.length > 0 &&
['image/gif', 'image/webp', 'image/jpeg', 'image/png'].includes(inputFiles[0]['type'])
) {
reader.readAsDataURL(inputFiles[0]);
} else {
console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
inputFiles = null;
}
}}
/>
<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>
<div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div>
</button>
{#if model}
<form
class="flex flex-col max-w-2xl mx-auto mt-4 mb-10"
on:submit|preventDefault={() => {
updateHandler();
}}
>
<div class="flex justify-center my-4">
<div class="self-center">
<button
class=" {info?.meta?.profile_image_url
? ''
: 'p-6'} rounded-full dark:bg-gray-700 border border-dashed border-gray-200"
type="button"
on:click={() => {
filesInputElement.click();
}}
>
{#if info?.meta?.profile_image_url}
<img
src={info?.meta?.profile_image_url}
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>
<div class="my-2 flex space-x-2">
<div class="flex-1">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Name')}*</div>
<div>
<input
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Name your model')}
bind:value={name}
required
/>
</div>
</div>
<div class="flex-1">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Model ID')}*</div>
<div>
<input
class="px-3 py-1.5 text-sm w-full bg-transparent disabled:text-gray-500 border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Add a model id')}
value={id}
disabled
required
/>
</div>
</div>
</div>
{#if model.preset}
<div class="my-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Base Model (From)')}</div>
<div>
<select
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder="Select a base model (e.g. llama3, gpt-4o)"
bind:value={info.base_model_id}
required
>
<option value={null} class=" text-gray-900">{$i18n.t('Select a base model')}</option>
{#each $models.filter((m) => m.id !== model.id && !m?.preset) as model}
<option value={model.id} class=" text-gray-900">{model.name}</option>
{/each}
</select>
</div>
</div>
{/if}
<div class="my-2">
<div class=" text-sm font-semibold mb-2">{$i18n.t('Description')}</div>
<div>
<input
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
placeholder={$i18n.t('Add a short description about what this model does')}
bind:value={info.meta.description}
/>
</div>
</div>
<div class="my-2">
<div class="flex w-full justify-between">
<div class=" self-center text-sm font-semibold">{$i18n.t('Model Params')}</div>
</div>
<!-- <div class=" text-sm font-semibold mb-2"></div> -->
<div class="mt-2">
<div class="my-1">
<div class=" text-xs font-semibold mb-2">{$i18n.t('System Prompt')}</div>
<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 model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
rows="4"
bind:value={info.params.system}
/>
</div>
</div>
<div class="flex w-full justify-between">
<div class=" self-center text-xs font-semibold">
{$i18n.t('Advanced Params')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
type="button"
on:click={() => {
showAdvanced = !showAdvanced;
}}
>
{#if showAdvanced}
<span class="ml-2 self-center">{$i18n.t('Hide')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Show')}</span>
{/if}
</button>
</div>
{#if showAdvanced}
<div class="my-2">
<AdvancedParams
bind:params
on:change={(e) => {
info.params = { ...info.params, ...params };
}}
/>
</div>
{/if}
</div>
</div>
<div class="my-2">
<div class="flex w-full justify-between items-center">
<div class="flex w-full justify-between items-center">
<div class=" self-center text-sm font-semibold">{$i18n.t('Prompt suggestions')}</div>
<button
class="p-1 text-xs flex rounded transition"
type="button"
on:click={() => {
if (info.meta.suggestion_prompts === null) {
info.meta.suggestion_prompts = [{ content: '' }];
} else {
info.meta.suggestion_prompts = null;
}
}}
>
{#if info.meta.suggestion_prompts === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
{/if}
</button>
</div>
{#if info.meta.suggestion_prompts !== null}
<button
class="p-1 px-2 text-xs flex rounded transition"
type="button"
on:click={() => {
if (
info.meta.suggestion_prompts.length === 0 ||
info.meta.suggestion_prompts.at(-1).content !== ''
) {
info.meta.suggestion_prompts = [...info.meta.suggestion_prompts, { content: '' }];
}
}}
>
<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>
{/if}
</div>
{#if info.meta.suggestion_prompts}
<div class="flex flex-col space-y-1 mt-2">
{#if info.meta.suggestion_prompts.length > 0}
{#each info.meta.suggestion_prompts 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"
placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
bind:value={prompt.content}
/>
<button
class="px-2"
type="button"
on:click={() => {
info.meta.suggestion_prompts.splice(promptIdx, 1);
info.meta.suggestion_prompts = info.meta.suggestion_prompts;
}}
>
<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}
{:else}
<div class="text-xs text-center">No suggestion prompts</div>
{/if}
</div>
{/if}
</div>
<div class="my-2">
<div class="flex w-full justify-between">
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
</div>
<div class="flex flex-col">
{#each Object.keys(capabilities) as capability}
<div class=" flex items-center gap-2">
<Checkbox
state={capabilities[capability] ? 'checked' : 'unchecked'}
on:change={(e) => {
capabilities[capability] = e.detail === 'checked';
}}
/>
<div class=" py-1.5 text-sm w-full capitalize">
{$i18n.t(capability)}
</div>
</div>
{/each}
</div>
</div>
<div class="my-2 text-gray-500">
<div class="flex w-full justify-between mb-2">
<div class=" self-center text-sm font-semibold">{$i18n.t('JSON Preview')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
type="button"
on:click={() => {
showPreview = !showPreview;
}}
>
{#if showPreview}
<span class="ml-2 self-center">{$i18n.t('Hide')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Show')}</span>
{/if}
</button>
</div>
{#if showPreview}
<div>
<textarea
class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg"
rows="10"
value={JSON.stringify(info, null, 2)}
disabled
readonly
/>
</div>
{/if}
</div>
<div class="my-2 flex justify-end mb-20">
<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}
>
<div class=" self-center font-medium">{$i18n.t('Save & Update')}</div>
{#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>
{/if}
</div>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
import 'tippy.js/dist/tippy.css'; import 'tippy.js/dist/tippy.css';
import { WEBUI_BASE_URL } from '$lib/constants'; import { WEBUI_BASE_URL } from '$lib/constants';
import i18n, { initI18n } from '$lib/i18n'; import i18n, { initI18n, getLanguages } from '$lib/i18n';
setContext('i18n', i18n); setContext('i18n', i18n);
...@@ -43,7 +43,14 @@ ...@@ -43,7 +43,14 @@
} }
// Initialize i18n even if we didn't get a backend config, // Initialize i18n even if we didn't get a backend config,
// so `/error` can show something that's not `undefined`. // so `/error` can show something that's not `undefined`.
initI18n(backendConfig?.default_locale);
const languages = await getLanguages();
const browserLanguage = navigator.languages
? navigator.languages[0]
: navigator.language || navigator.userLanguage;
initI18n(languages.includes(browserLanguage) ? browserLanguage : backendConfig?.default_locale);
if (backendConfig) { if (backendConfig) {
// Save Backend Status to Store // Save Backend Status to Store
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
await goto('/'); await goto('/');
} }
loaded = true; loaded = true;
if (($config?.trusted_header_auth ?? false) || $config?.auth === false) { if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) {
await signInHandler(); await signInHandler();
} }
}); });
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
</div> --> </div> -->
<div class="w-full sm:max-w-md px-10 min-h-screen flex flex-col text-center"> <div class="w-full sm:max-w-md px-10 min-h-screen flex flex-col text-center">
{#if ($config?.trusted_header_auth ?? false) || $config?.auth === false} {#if ($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false}
<div class=" my-auto pb-10 w-full"> <div class=" my-auto pb-10 w-full">
<div <div
class="flex items-center justify-center gap-3 text-xl sm:text-2xl text-center font-bold dark:text-gray-200" class="flex items-center justify-center gap-3 text-xl sm:text-2xl text-center font-bold dark:text-gray-200"
...@@ -194,25 +194,27 @@ ...@@ -194,25 +194,27 @@
{mode === 'signin' ? $i18n.t('Sign in') : $i18n.t('Create Account')} {mode === 'signin' ? $i18n.t('Sign in') : $i18n.t('Create Account')}
</button> </button>
<div class=" mt-4 text-sm text-center"> {#if $config?.features.enable_signup}
{mode === 'signin' <div class=" mt-4 text-sm text-center">
? $i18n.t("Don't have an account?") {mode === 'signin'
: $i18n.t('Already have an account?')} ? $i18n.t("Don't have an account?")
: $i18n.t('Already have an account?')}
<button
class=" font-medium underline" <button
type="button" class=" font-medium underline"
on:click={() => { type="button"
if (mode === 'signin') { on:click={() => {
mode = 'signup'; if (mode === 'signin') {
} else { mode = 'signup';
mode = 'signin'; } else {
} mode = 'signin';
}} }
> }}
{mode === 'signin' ? $i18n.t('Sign up') : $i18n.t('Sign in')} >
</button> {mode === 'signin' ? $i18n.t('Sign up') : $i18n.t('Sign in')}
</div> </button>
</div>
{/if}
</div> </div>
</form> </form>
</div> </div>
......
<script lang="ts">
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
onMount(async () => {
window.addEventListener('message', async (event) => {
if (
![
'https://ollamahub.com',
'https://www.ollamahub.com',
'https://openwebui.com',
'https://www.openwebui.com',
'http://localhost:5173'
].includes(event.origin)
)
return;
const modelfile = JSON.parse(event.data);
sessionStorage.modelfile = JSON.stringify(modelfile);
goto('/workspace/modelfiles/create');
});
if (window.opener ?? false) {
window.opener.postMessage('loaded', '*');
}
});
</script>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { modelfiles, settings, chatId, WEBUI_NAME } from '$lib/stores'; import { settings, chatId, WEBUI_NAME, models } from '$lib/stores';
import { convertMessagesToHistory } from '$lib/utils'; import { convertMessagesToHistory } from '$lib/utils';
import { getChatByShareId } from '$lib/apis/chats'; import { getChatByShareId } from '$lib/apis/chats';
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
import Navbar from '$lib/components/layout/Navbar.svelte'; import Navbar from '$lib/components/layout/Navbar.svelte';
import { getUserById } from '$lib/apis/users'; import { getUserById } from '$lib/apis/users';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import { getModels } from '$lib/apis';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
...@@ -27,17 +28,6 @@ ...@@ -27,17 +28,6 @@
let showModelSelector = false; let showModelSelector = false;
let selectedModels = ['']; let selectedModels = [''];
let selectedModelfiles = {};
$: selectedModelfiles = selectedModels.reduce((a, tagName, i, arr) => {
const modelfile =
$modelfiles.filter((modelfile) => modelfile.tagName === tagName)?.at(0) ?? undefined;
return {
...a,
...(modelfile && { [tagName]: modelfile })
};
}, {});
let chat = null; let chat = null;
let user = null; let user = null;
...@@ -69,10 +59,6 @@ ...@@ -69,10 +59,6 @@
if (await loadSharedChat()) { if (await loadSharedChat()) {
await tick(); await tick();
loaded = true; loaded = true;
window.setTimeout(() => scrollToBottom(), 0);
const chatInput = document.getElementById('chat-textarea');
chatInput?.focus();
} else { } else {
await goto('/'); await goto('/');
} }
...@@ -84,6 +70,7 @@ ...@@ -84,6 +70,7 @@
////////////////////////// //////////////////////////
const loadSharedChat = async () => { const loadSharedChat = async () => {
await models.set(await getModels(localStorage.token));
await chatId.set($page.params.id); await chatId.set($page.params.id);
chat = await getChatByShareId(localStorage.token, $chatId).catch(async (error) => { chat = await getChatByShareId(localStorage.token, $chatId).catch(async (error) => {
await goto('/'); await goto('/');
...@@ -111,12 +98,6 @@ ...@@ -111,12 +98,6 @@
: convertMessagesToHistory(chatContent.messages); : convertMessagesToHistory(chatContent.messages);
title = chatContent.title; title = chatContent.title;
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
await settings.set({
..._settings,
system: chatContent.system ?? _settings.system,
options: chatContent.options ?? _settings.options
});
autoScroll = true; autoScroll = true;
await tick(); await tick();
...@@ -168,7 +149,6 @@ ...@@ -168,7 +149,6 @@
chatId={$chatId} chatId={$chatId}
readOnly={true} readOnly={true}
{selectedModels} {selectedModels}
{selectedModelfiles}
{processing} {processing}
bind:history bind:history
bind:messages bind:messages
......
...@@ -18,7 +18,11 @@ import { defineConfig } from 'vite'; ...@@ -18,7 +18,11 @@ import { defineConfig } from 'vite';
export default defineConfig({ export default defineConfig({
plugins: [sveltekit()], plugins: [sveltekit()],
define: { define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version) APP_VERSION: JSON.stringify(process.env.npm_package_version),
APP_BUILD_HASH: JSON.stringify(process.env.APP_BUILD_HASH || 'dev-build')
},
build: {
sourcemap: true
}, },
worker: { worker: {
format: 'es' format: 'es'
......
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