open-webui/src/lib/components/workspace/Models/ModelEditor.svelte

1043 lines
30 KiB
Svelte
Raw Normal View History

2024-11-07 08:18:48 +00:00
<script lang="ts">
import { toast } from 'svelte-sonner';
2024-11-07 08:18:48 +00:00
import { onMount, getContext, tick } from 'svelte';
import { models, tools, functions, user, config } from '$lib/stores';
import { WEBUI_BASE_URL } from '$lib/constants';
2024-11-07 08:18:48 +00:00
import { getTools } from '$lib/apis/tools';
import { getFunctions } from '$lib/apis/functions';
2024-11-07 08:18:48 +00:00
import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
import Tags from '$lib/components/common/Tags.svelte';
import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
import FiltersSelector from '$lib/components/workspace/Models/FiltersSelector.svelte';
import ActionsSelector from '$lib/components/workspace/Models/ActionsSelector.svelte';
import Capabilities from '$lib/components/workspace/Models/Capabilities.svelte';
import Textarea from '$lib/components/common/Textarea.svelte';
2024-11-16 02:21:41 +00:00
import AccessControl from '../common/AccessControl.svelte';
2025-06-25 22:44:45 +00:00
import Spinner from '$lib/components/common/Spinner.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import PencilSolid from '$lib/components/icons/PencilSolid.svelte';
import DefaultFiltersSelector from './DefaultFiltersSelector.svelte';
import DefaultFeatures from './DefaultFeatures.svelte';
import PromptSuggestions from './PromptSuggestions.svelte';
2025-11-30 08:47:34 +00:00
import AccessControlModal from '../common/AccessControlModal.svelte';
import LockClosed from '$lib/components/icons/LockClosed.svelte';
2024-11-07 08:18:48 +00:00
const i18n = getContext('i18n');
export let onSubmit: Function;
2024-11-16 06:04:33 +00:00
export let onBack: null | Function = null;
2024-11-07 08:18:48 +00:00
export let model = null;
export let edit = false;
2024-11-16 06:04:33 +00:00
2024-11-15 11:00:18 +00:00
export let preset = true;
2024-11-07 08:18:48 +00:00
let loading = false;
let success = false;
let filesInputElement;
let inputFiles;
let showAdvanced = false;
let showPreview = false;
2025-11-30 08:47:34 +00:00
let showAccessControlModal = false;
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
let loaded = false;
2024-11-07 08:18:48 +00:00
// ///////////
// model
// ///////////
let id = '';
let name = '';
// Translation support
let showTitleModal = false;
let titleTranslations = {};
let showPromptModal = false;
let currentPromptIdx = -1;
let currentPromptTranslations = {};
$: langCode = $i18n.language?.split('-')[0] || 'de';
$: LANGS = Array.isArray($config.features.translation_languages)
? [...new Set([...$config.features.translation_languages, langCode])]
: [langCode, 'de'];
// Keep name synchronized with the current language translation
$: name = titleTranslations[langCode] || '';
2025-01-21 07:44:47 +00:00
let enableDescription = true;
2024-11-07 08:18:48 +00:00
$: if (!edit) {
const currentName = titleTranslations[langCode] || '';
if (currentName) {
id = currentName
2024-11-07 08:18:48 +00:00
.replace(/\s+/g, '-')
.replace(/[^a-zA-Z0-9-]/g, '')
.toLowerCase();
}
}
let system = '';
2024-11-07 08:18:48 +00:00
let info = {
id: '',
base_model_id: null,
name: '',
meta: {
profile_image_url: `${WEBUI_BASE_URL}/static/favicon.png`,
2024-11-07 08:18:48 +00:00
description: '',
suggestion_prompts: null,
tags: []
},
params: {
system: ''
}
};
2024-11-29 21:24:37 +00:00
let params = {
system: ''
};
let knowledge = [];
let toolIds = [];
let filterIds = [];
let defaultFilterIds = [];
2024-11-07 08:18:48 +00:00
let capabilities = {
vision: true,
2025-05-16 21:13:13 +00:00
file_upload: true,
2025-05-16 20:59:00 +00:00
web_search: true,
image_generation: true,
code_interpreter: true,
citations: true,
2025-09-07 01:17:38 +00:00
status_updates: true,
2025-05-16 20:59:00 +00:00
usage: undefined
2024-11-07 08:18:48 +00:00
};
let defaultFeatureIds = [];
2024-11-07 08:18:48 +00:00
let actionIds = [];
2024-11-18 03:15:09 +00:00
let accessControl = {};
2024-11-16 02:21:41 +00:00
2024-11-07 08:18:48 +00:00
const addUsage = (base_model_id) => {
const baseModel = $models.find((m) => m.id === base_model_id);
if (baseModel) {
if (baseModel.owned_by === 'openai') {
2024-11-16 12:43:10 +00:00
capabilities.usage = baseModel?.meta?.capabilities?.usage ?? false;
2024-11-07 08:18:48 +00:00
} else {
delete capabilities.usage;
}
capabilities = capabilities;
}
};
// Translation helper functions
function createEmptyTranslations() {
const translations = {};
LANGS.forEach(lang => {
translations[lang] = '';
});
return translations;
}
function parseContentToObj(content) {
let parsed = {};
try {
parsed = typeof content === 'string' ? JSON.parse(content) : { ...content };
} catch {
parsed = { [LANGS[0] || 'de']: content || '' };
}
// ensure all languages from config exist
for (const lang of LANGS) {
if (parsed[lang] == null) parsed[lang] = '';
}
return parsed;
}
function initializeTitleTranslations(existingName) {
if (existingName) {
titleTranslations = parseContentToObj(existingName);
} else {
titleTranslations = createEmptyTranslations();
}
}
function getPromptTranslation(promptContent) {
const parsed = parseContentToObj(promptContent);
return parsed[langCode] || parsed[LANGS[0]] || '';
}
function openPromptTranslationModal(idx) {
currentPromptIdx = idx;
const promptContent = info.meta.suggestion_prompts[idx].content;
currentPromptTranslations = parseContentToObj(promptContent);
showPromptModal = true;
}
function savePromptTranslation() {
if (currentPromptIdx >= 0 && info.meta.suggestion_prompts[currentPromptIdx]) {
info.meta.suggestion_prompts[currentPromptIdx].content = JSON.stringify(currentPromptTranslations);
info.meta.suggestion_prompts = info.meta.suggestion_prompts;
}
showPromptModal = false;
currentPromptIdx = -1;
}
// Update name to store the full translation object
$: info.name = JSON.stringify(titleTranslations);
2024-11-07 08:18:48 +00:00
const submitHandler = async () => {
loading = true;
info.id = id;
// info.name is set by reactive statement from titleTranslations
2024-11-16 09:24:34 +00:00
2024-11-30 08:10:30 +00:00
if (id === '') {
2025-08-06 08:36:35 +00:00
toast.error($i18n.t('Model ID is required.'));
loading = false;
return;
2024-11-30 08:10:30 +00:00
}
if (!titleTranslations[langCode] || titleTranslations[langCode].trim() === '') {
2025-08-06 08:36:35 +00:00
toast.error($i18n.t('Model Name is required.'));
loading = false;
return;
}
if (knowledge.some((item) => item.status === 'uploading')) {
toast.error($i18n.t('Please wait until all files are uploaded.'));
loading = false;
return;
2024-11-30 08:10:30 +00:00
}
2025-05-28 23:33:11 +00:00
info.params = { ...info.params, ...params };
2025-05-28 23:37:13 +00:00
2024-11-16 09:24:34 +00:00
info.access_control = accessControl;
2024-11-07 08:18:48 +00:00
info.meta.capabilities = capabilities;
2025-01-21 07:44:47 +00:00
if (enableDescription) {
info.meta.description = info.meta.description.trim() === '' ? null : info.meta.description;
} else {
info.meta.description = null;
}
2024-11-07 08:18:48 +00:00
if (knowledge.length > 0) {
info.meta.knowledge = knowledge;
} else {
if (info.meta.knowledge) {
delete info.meta.knowledge;
}
}
if (toolIds.length > 0) {
info.meta.toolIds = toolIds;
} else {
if (info.meta.toolIds) {
delete info.meta.toolIds;
}
}
if (filterIds.length > 0) {
info.meta.filterIds = filterIds;
} else {
if (info.meta.filterIds) {
delete info.meta.filterIds;
}
}
if (defaultFilterIds.length > 0) {
info.meta.defaultFilterIds = defaultFilterIds;
} else {
if (info.meta.defaultFilterIds) {
delete info.meta.defaultFilterIds;
}
}
2024-11-07 08:18:48 +00:00
if (actionIds.length > 0) {
info.meta.actionIds = actionIds;
} else {
if (info.meta.actionIds) {
delete info.meta.actionIds;
}
}
if (defaultFeatureIds.length > 0) {
info.meta.defaultFeatureIds = defaultFeatureIds;
} else {
if (info.meta.defaultFeatureIds) {
delete info.meta.defaultFeatureIds;
}
}
info.params.system = system.trim() === '' ? null : system;
2024-11-07 08:18:48 +00:00
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
Object.keys(info.params).forEach((key) => {
if (info.params[key] === '' || info.params[key] === null) {
delete info.params[key];
}
});
await onSubmit(info);
loading = false;
success = false;
};
onMount(async () => {
2024-11-13 05:04:07 +00:00
await tools.set(await getTools(localStorage.token));
await functions.set(await getFunctions(localStorage.token));
2024-11-07 08:18:48 +00:00
// Scroll to top 'workspace-container' element
const workspaceContainer = document.getElementById('workspace-container');
if (workspaceContainer) {
workspaceContainer.scrollTop = 0;
}
if (model) {
// Initialize translations from model name
initializeTitleTranslations(model.name);
2024-11-07 08:18:48 +00:00
await tick();
id = model.id;
2025-01-21 07:44:47 +00:00
enableDescription = model?.meta?.description !== null;
2024-11-15 10:05:43 +00:00
if (model.base_model_id) {
2024-11-07 08:18:48 +00:00
const base_model = $models
2024-11-16 09:38:20 +00:00
.filter((m) => !m?.preset && !(m?.arena ?? false))
2024-11-15 10:05:43 +00:00
.find((m) => [model.base_model_id, `${model.base_model_id}:latest`].includes(m.id));
2024-11-07 08:18:48 +00:00
console.log('base_model', base_model);
if (base_model) {
2024-11-15 10:05:43 +00:00
model.base_model_id = base_model.id;
2024-11-07 08:18:48 +00:00
} else {
2024-11-15 10:05:43 +00:00
model.base_model_id = null;
2024-11-07 08:18:48 +00:00
}
}
system = model?.params?.system ?? '';
2024-11-15 10:05:43 +00:00
params = { ...params, ...model?.params };
2024-11-07 08:18:48 +00:00
params.stop = params?.stop
? (typeof params.stop === 'string' ? params.stop.split(',') : (params?.stop ?? [])).join(
','
)
: null;
2024-11-15 10:05:43 +00:00
knowledge = (model?.meta?.knowledge ?? []).map((item) => {
if (item?.collection_name && item?.type !== 'file') {
2024-11-07 08:18:48 +00:00
return {
id: item.collection_name,
name: item.name,
legacy: true
};
} else if (item?.collection_names) {
return {
name: item.name,
type: 'collection',
collection_names: item.collection_names,
legacy: true
};
} else {
return item;
}
});
toolIds = model?.meta?.toolIds ?? [];
filterIds = model?.meta?.filterIds ?? [];
defaultFilterIds = model?.meta?.defaultFilterIds ?? [];
actionIds = model?.meta?.actionIds ?? [];
2024-11-15 10:05:43 +00:00
capabilities = { ...capabilities, ...(model?.meta?.capabilities ?? {}) };
defaultFeatureIds = model?.meta?.defaultFeatureIds ?? [];
2024-11-07 08:18:48 +00:00
2024-11-18 03:15:09 +00:00
if ('access_control' in model) {
accessControl = model.access_control;
} else {
accessControl = {};
}
2024-11-16 02:21:41 +00:00
2024-11-16 09:38:20 +00:00
console.log(model?.access_control);
console.log(accessControl);
2024-11-07 08:18:48 +00:00
info = {
...info,
2024-11-07 08:53:39 +00:00
...JSON.parse(
JSON.stringify(
2024-11-15 10:05:43 +00:00
model
? model
2024-11-07 08:53:39 +00:00
: {
id: model.id,
name: model.name
}
)
)
2024-11-07 08:18:48 +00:00
};
console.log(model);
} else {
// Initialize empty translations for new model
titleTranslations = createEmptyTranslations();
}
2024-11-13 05:04:07 +00:00
loaded = true;
2024-11-07 08:18:48 +00:00
});
</script>
2024-11-13 05:04:07 +00:00
{#if loaded}
<!-- Translation Modal -->
{#if showTitleModal}
<div class="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50">
<div class="bg-white dark:bg-gray-800 p-4 rounded-md shadow-md w-[90%] max-w-md">
<div class="flex justify-between dark:text-gray-300 pt-4 pb-1">
<h2 class="text-sm font-bold mb-2">{$i18n.t('Edit Title Translations')}</h2>
<button class="text-xs px-2 py-1" on:click={() => (showTitleModal = false)}>
<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 LANGS as lang}
<div class="mb-2">
<label class="text-xs font-semibold block mb-1">{lang.toUpperCase()}</label>
<input
class="w-full text-sm p-1 border border-gray-300 dark:border-gray-700 rounded"
bind:value={titleTranslations[lang]}
placeholder={`Enter ${lang.toUpperCase()} title`}
/>
</div>
{/each}
<div class="flex justify-end space-x-2 mt-3">
<button
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
on:click={() => (showTitleModal = false)}
>
Save
</button>
</div>
</div>
</div>
{/if}
<!-- Prompt Translation Modal -->
{#if showPromptModal}
<div class="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50">
<div class="bg-white dark:bg-gray-800 p-4 rounded-md shadow-md w-[90%] max-w-md">
<div class="flex justify-between dark:text-gray-300 pt-4 pb-1">
<h2 class="text-sm font-bold mb-2">{$i18n.t('Edit Prompt Translations')}</h2>
<button class="text-xs px-2 py-1" on:click={() => (showPromptModal = false)}>
<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 LANGS as lang}
<div class="mb-2">
<label class="text-xs font-semibold block mb-1">{lang.toUpperCase()}</label>
<input
class="w-full text-sm p-1 border border-gray-300 dark:border-gray-700 rounded"
bind:value={currentPromptTranslations[lang]}
placeholder={`Enter ${lang.toUpperCase()} prompt`}
/>
</div>
{/each}
<div class="flex justify-end space-x-2 mt-3">
<button
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
on:click={savePromptTranslation}
>
Save
</button>
</div>
</div>
</div>
{/if}
2024-11-07 08:18:48 +00:00
2025-11-30 08:47:34 +00:00
<AccessControlModal
bind:show={showAccessControlModal}
bind:accessControl
accessRoles={['read', 'write']}
share={$user?.permissions?.sharing?.models || $user?.role === 'admin'}
sharePublic={$user?.permissions?.sharing?.public_models || $user?.role === 'admin'}
/>
2024-11-16 06:04:33 +00:00
{#if onBack}
<button
class="flex space-x-1"
on:click={() => {
onBack();
}}
>
<div class=" self-center">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="h-4 w-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>
2025-08-19 18:39:17 +00:00
<div class=" self-center text-sm font-medium">{$i18n.t('Back')}</div>
2024-11-16 06:04:33 +00:00
</button>
{/if}
2024-11-13 05:04:07 +00:00
<div class="w-full max-h-full flex justify-center">
<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 = 250 * aspectRatio;
newHeight = 250;
} else {
newWidth = 250;
newHeight = 250 / aspectRatio;
}
// Set the canvas size
canvas.width = 250;
canvas.height = 250;
// Calculate the position to center the image
const offsetX = (250 - newWidth) / 2;
const offsetY = (250 - 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();
// Display the compressed image
info.meta.profile_image_url = compressedSrc;
inputFiles = null;
2024-11-24 07:26:11 +00:00
filesInputElement.value = '';
2024-11-13 05:04:07 +00:00
};
2024-11-07 08:18:48 +00:00
};
2024-11-13 05:04:07 +00:00
if (
inputFiles &&
inputFiles.length > 0 &&
['image/gif', 'image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'].includes(
inputFiles[0]['type']
)
) {
reader.readAsDataURL(inputFiles[0]);
} else {
console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
inputFiles = null;
}
2024-11-07 08:18:48 +00:00
}}
2024-11-13 05:04:07 +00:00
/>
2024-11-16 06:04:33 +00:00
{#if !edit || (edit && model)}
2024-11-13 05:04:07 +00:00
<form
2024-11-13 07:00:47 +00:00
class="flex flex-col md:flex-row w-full gap-3 md:gap-6"
2024-11-13 05:04:07 +00:00
on:submit|preventDefault={() => {
submitHandler();
}}
>
2025-02-16 03:27:25 +00:00
<div class="self-center md:self-start flex justify-center my-2 shrink-0">
2024-11-13 05:04:07 +00:00
<div class="self-center">
2024-11-07 08:18:48 +00:00
<button
2025-02-16 03:27:25 +00:00
class="rounded-xl flex shrink-0 items-center {info.meta.profile_image_url !==
`${WEBUI_BASE_URL}/static/favicon.png`
2024-11-17 23:58:06 +00:00
? 'bg-transparent'
: 'bg-white'} shadow-xl group relative"
2024-11-07 08:18:48 +00:00
type="button"
on:click={() => {
2024-11-13 05:04:07 +00:00
filesInputElement.click();
2024-11-07 08:18:48 +00:00
}}
>
2024-11-13 05:04:07 +00:00
{#if info.meta.profile_image_url}
<img
src={info.meta.profile_image_url}
alt="model profile"
2024-11-24 07:26:11 +00:00
class="rounded-xl size-72 md:size-60 object-cover shrink-0"
2024-11-13 05:04:07 +00:00
/>
2024-11-07 08:18:48 +00:00
{:else}
2024-11-13 05:04:07 +00:00
<img
src="{WEBUI_BASE_URL}/static/favicon.png"
2024-11-13 05:04:07 +00:00
alt="model profile"
2024-11-24 07:26:11 +00:00
class=" rounded-xl size-72 md:size-60 object-cover shrink-0"
2024-11-13 05:04:07 +00:00
/>
2024-11-07 08:18:48 +00:00
{/if}
2024-11-13 05:04:07 +00:00
<div class="absolute bottom-0 right-0 z-10">
<div class="m-1.5">
<div
class="shadow-xl p-1 rounded-full border-2 border-white bg-gray-800 text-white group-hover:bg-gray-600 transition dark:border-black dark:bg-white dark:group-hover:bg-gray-200 dark:text-black"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="size-5"
>
<path
fill-rule="evenodd"
d="M2 4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4Zm10.5 5.707a.5.5 0 0 0-.146-.353l-1-1a.5.5 0 0 0-.708 0L9.354 9.646a.5.5 0 0 1-.708 0L6.354 7.354a.5.5 0 0 0-.708 0l-2 2a.5.5 0 0 0-.146.353V12a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5V9.707ZM12 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
clip-rule="evenodd"
/>
</svg>
</div>
</div>
</div>
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
<div
class="absolute top-0 bottom-0 left-0 right-0 bg-white dark:bg-black rounded-lg opacity-0 group-hover:opacity-20 transition"
></div>
</button>
2024-11-24 07:26:11 +00:00
<div class="flex w-full mt-1 justify-end">
<button
class="px-2 py-1 text-gray-500 rounded-lg text-xs"
on:click={() => {
info.meta.profile_image_url = `${WEBUI_BASE_URL}/static/favicon.png`;
2024-11-24 07:26:11 +00:00
}}
type="button"
>
2025-08-19 18:39:17 +00:00
{$i18n.t('Reset Image')}</button
2024-11-24 07:26:11 +00:00
>
</div>
2024-11-07 08:53:39 +00:00
</div>
2024-11-13 05:04:07 +00:00
</div>
2024-11-07 08:53:39 +00:00
2024-11-13 07:00:47 +00:00
<div class="w-full">
2024-11-13 05:04:07 +00:00
<div class="mt-2 my-2 flex flex-col">
<div class="flex-1">
<div class="flex items-center">
2024-11-13 05:04:07 +00:00
<input
2025-11-24 02:17:14 +00:00
class="text-3xl font-medium w-full bg-transparent outline-hidden"
2024-11-13 05:04:07 +00:00
placeholder={$i18n.t('Model Name')}
bind:value={titleTranslations[langCode]}
2024-11-13 05:04:07 +00:00
required
2024-11-07 08:53:39 +00:00
/>
{#if titleTranslations[langCode]}
<button class="ml-2" type="button" on:click={() => (showTitleModal = true)}>
<div class="self-center mr-2">
<PencilSolid />
</div>
</button>
{/if}
</div>
2024-11-07 08:53:39 +00:00
</div>
2024-11-13 05:04:07 +00:00
<div class="flex-1">
<div>
<input
2025-02-16 03:27:25 +00:00
class="text-xs w-full bg-transparent text-gray-500 outline-hidden"
2024-11-13 05:04:07 +00:00
placeholder={$i18n.t('Model ID')}
2024-11-30 08:10:30 +00:00
bind:value={id}
2024-11-13 05:04:07 +00:00
disabled={edit}
required
/>
2024-11-07 08:53:39 +00:00
</div>
</div>
2024-11-13 05:04:07 +00:00
</div>
2024-11-07 08:53:39 +00:00
2024-11-15 11:00:18 +00:00
{#if preset}
2024-11-13 05:04:07 +00:00
<div class="my-1">
2025-11-24 02:17:14 +00:00
<div class=" text-sm font-medium mb-1">{$i18n.t('Base Model (From)')}</div>
2024-11-13 05:04:07 +00:00
<div>
<select
2025-02-16 03:27:25 +00:00
class="text-sm w-full bg-transparent outline-hidden"
2025-08-14 00:15:16 +00:00
placeholder={$i18n.t('Select a base model (e.g. llama3, gpt-4o)')}
2024-11-13 05:04:07 +00:00
bind:value={info.base_model_id}
2024-11-07 08:53:39 +00:00
on:change={(e) => {
2024-11-13 05:04:07 +00:00
addUsage(e.target.value);
2024-11-07 08:53:39 +00:00
}}
2024-11-13 05:04:07 +00:00
required
>
<option value={null} class=" text-gray-900"
>{$i18n.t('Select a base model')}</option
>
{#each $models.filter((m) => (model ? m.id !== model.id : true) && !m?.preset && m?.owned_by !== 'arena' && !(m?.direct ?? false)) as model}
2024-11-13 05:04:07 +00:00
<option value={model.id} class=" text-gray-900">{model.name}</option>
{/each}
</select>
2024-11-07 08:53:39 +00:00
</div>
2024-11-13 05:04:07 +00:00
</div>
{/if}
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-1">
<div class="mb-1 flex w-full justify-between items-center">
2025-11-24 02:17:14 +00:00
<div class=" self-center text-sm font-medium">{$i18n.t('Description')}</div>
2024-11-07 08:53:39 +00:00
<button
2025-02-16 03:27:25 +00:00
class="p-1 text-xs flex rounded-sm transition"
2024-11-07 08:53:39 +00:00
type="button"
aria-pressed={enableDescription ? 'true' : 'false'}
aria-label={enableDescription
? $i18n.t('Custom description enabled')
: $i18n.t('Default description enabled')}
2024-11-07 08:53:39 +00:00
on:click={() => {
2025-01-21 07:44:47 +00:00
enableDescription = !enableDescription;
2024-11-07 08:53:39 +00:00
}}
>
2025-01-21 07:44:47 +00:00
{#if !enableDescription}
2024-11-07 08:53:39 +00:00
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
{/if}
</button>
</div>
2024-11-07 08:18:48 +00:00
2025-01-21 07:44:47 +00:00
{#if enableDescription}
2024-11-13 05:04:07 +00:00
<Textarea
2025-02-16 03:27:25 +00:00
className=" text-sm w-full bg-transparent outline-hidden resize-none overflow-y-hidden "
2024-11-13 05:04:07 +00:00
placeholder={$i18n.t('Add a short description about what this model does')}
bind:value={info.meta.description}
/>
2024-11-07 08:53:39 +00:00
{/if}
</div>
2024-11-07 08:18:48 +00:00
2025-01-21 07:44:47 +00:00
<div class=" mt-2 my-1">
2024-11-15 10:05:43 +00:00
<div class="">
<Tags
tags={info?.meta?.tags ?? []}
on:delete={(e) => {
const tagName = e.detail;
info.meta.tags = info.meta.tags.filter((tag) => tag.name !== tagName);
}}
on:add={(e) => {
const tagName = e.detail;
if (!(info?.meta?.tags ?? null)) {
info.meta.tags = [{ name: tagName }];
} else {
info.meta.tags = [...info.meta.tags, { name: tagName }];
}
}}
/>
</div>
</div>
2024-11-16 09:38:20 +00:00
<div class="my-2">
2025-09-21 07:12:24 +00:00
<div class="px-4 py-3 bg-gray-50 dark:bg-gray-950 rounded-3xl">
<AccessControl
bind:accessControl
accessRoles={['read', 'write']}
2025-11-20 23:32:34 +00:00
share={$user?.permissions?.sharing?.models || $user?.role === 'admin'}
sharePublic={$user?.permissions?.sharing?.public_models || $user?.role === 'admin'}
/>
2024-11-16 09:38:20 +00:00
</div>
</div>
2025-02-16 03:50:40 +00:00
<hr class=" border-gray-100 dark:border-gray-850 my-1.5" />
2024-11-07 08:53:39 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-2">
<div class="flex w-full justify-between">
2025-11-24 02:17:14 +00:00
<div class=" self-center text-sm font-medium">{$i18n.t('Model Params')}</div>
2024-11-13 05:04:07 +00:00
</div>
<div class="mt-2">
<div class="my-1">
2025-11-24 02:17:14 +00:00
<div class=" text-xs font-medium mb-2">{$i18n.t('System Prompt')}</div>
<div>
2024-11-13 05:04:07 +00:00
<Textarea
2025-02-16 03:27:25 +00:00
className=" text-sm w-full bg-transparent outline-hidden resize-none overflow-y-hidden "
2025-08-21 00:47:28 +00:00
placeholder={$i18n.t(
'Write your model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.'
)}
2024-11-13 05:04:07 +00:00
rows={4}
bind:value={system}
/>
</div>
2024-11-07 08:53:39 +00:00
</div>
2024-11-13 05:04:07 +00:00
<div class="flex w-full justify-between">
2025-11-24 02:17:14 +00:00
<div class=" self-center text-xs font-medium">
2024-11-13 05:04:07 +00:00
{$i18n.t('Advanced Params')}
</div>
2024-11-13 05:04:07 +00:00
<button
2025-02-16 03:27:25 +00:00
class="p-1 px-3 text-xs flex rounded-sm transition"
2024-11-13 05:04:07 +00:00
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>
2024-11-13 05:04:07 +00:00
{#if showAdvanced}
<div class="my-2">
2025-05-28 23:33:11 +00:00
<AdvancedParams admin={true} custom={true} bind:params />
2024-11-13 05:04:07 +00:00
</div>
2024-11-07 08:53:39 +00:00
{/if}
</div>
2024-11-13 05:04:07 +00:00
</div>
2025-11-24 02:17:14 +00:00
<hr class=" border-gray-100 dark:border-gray-850 my-2" />
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-2">
<div class="flex w-full justify-between items-center">
<div class="flex w-full justify-between items-center">
2025-11-24 02:17:14 +00:00
<div class=" self-center text-sm font-medium">
{$i18n.t('Prompts')}
2024-11-13 05:04:07 +00:00
</div>
<button
class="p-1 text-xs flex rounded-sm transition"
2024-11-13 05:04:07 +00:00
type="button"
on:click={() => {
if ((info?.meta?.suggestion_prompts ?? null) === null) {
2025-11-25 08:41:24 +00:00
info.meta.suggestion_prompts = [{ content: JSON.stringify(createEmptyTranslations()), title: ['', ''] }];
2024-11-13 05:04:07 +00:00
} else {
info.meta.suggestion_prompts = null;
}
}}
>
{#if (info?.meta?.suggestion_prompts ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
2024-11-13 05:04:07 +00:00
{:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
2024-11-13 05:04:07 +00:00
{/if}
</button>
</div>
{#if (info?.meta?.suggestion_prompts ?? null) !== null}
<button
2025-02-16 03:27:25 +00:00
class="p-1 px-2 text-xs flex rounded-sm transition"
2024-11-13 05:04:07 +00:00
type="button"
2025-11-25 08:41:24 +00:00
aria-label={$i18n.t('Add prompt suggestion')}
2024-11-13 05:04:07 +00:00
on:click={() => {
if (
info.meta.suggestion_prompts.length === 0 ||
getPromptTranslation(info.meta.suggestion_prompts.at(-1).content) !== ''
2024-11-13 05:04:07 +00:00
) {
info.meta.suggestion_prompts = [
...info.meta.suggestion_prompts,
2025-11-25 08:41:24 +00:00
{ content: JSON.stringify(createEmptyTranslations()), title: ['', ''] }
2024-11-13 05:04:07 +00:00
];
}
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
2024-11-13 05:04:07 +00:00
<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>
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
{#if info?.meta?.suggestion_prompts}
<div class="flex flex-col space-y-1 mt-1 mb-3">
{#if info.meta.suggestion_prompts.length > 0}
{#each info.meta.suggestion_prompts as prompt, promptIdx}
<div class=" flex rounded-lg items-center">
2024-11-13 05:04:07 +00:00
<input
2025-02-16 03:50:40 +00:00
class=" text-sm w-full bg-transparent outline-hidden border-r border-gray-100 dark:border-gray-850"
2024-11-13 05:04:07 +00:00
placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
value={getPromptTranslation(prompt.content)}
on:input={(e) => {
const translations = parseContentToObj(prompt.content);
translations[langCode] = e.target.value;
prompt.content = JSON.stringify(translations);
info.meta.suggestion_prompts = info.meta.suggestion_prompts;
}}
2024-11-13 05:04:07 +00:00
/>
{#if getPromptTranslation(prompt.content)}
<button
class="px-2"
type="button"
on:click={() => openPromptTranslationModal(promptIdx)}
>
<PencilSolid />
</button>
{/if}
2024-11-13 05:04:07 +00:00
<button
class="px-2"
type="button"
on:click={() => {
info.meta.suggestion_prompts.splice(promptIdx, 1);
info.meta.suggestion_prompts = info.meta.suggestion_prompts;
}}
>
2025-06-27 11:44:26 +00:00
<XMark className={'size-4'} />
2024-11-13 05:04:07 +00:00
</button>
</div>
{/each}
{:else}
2025-08-19 18:39:17 +00:00
<div class="text-xs text-center">{$i18n.t('No suggestion prompts')}</div>
2024-11-13 05:04:07 +00:00
{/if}
</div>
{/if}
</div>
2024-11-07 08:18:48 +00:00
2025-02-16 03:50:40 +00:00
<hr class=" border-gray-100 dark:border-gray-850 my-1.5" />
2024-11-13 05:04:07 +00:00
<div class="my-2">
2025-07-10 21:34:24 +00:00
<Knowledge bind:selectedItems={knowledge} />
2024-11-07 08:53:39 +00:00
</div>
2024-11-07 08:18:48 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-2">
<ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
</div>
2024-11-07 08:53:39 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-2">
<FiltersSelector
bind:selectedFilterIds={filterIds}
filters={$functions.filter((func) => func.type === 'filter')}
2024-11-07 08:18:48 +00:00
/>
</div>
{#if filterIds.length > 0}
{@const toggleableFilters = $functions.filter(
2025-09-12 21:50:24 +00:00
(func) =>
func.type === 'filter' &&
(filterIds.includes(func.id) || func?.is_global) &&
func?.meta?.toggle
)}
{#if toggleableFilters.length > 0}
<div class="my-2">
<DefaultFiltersSelector
bind:selectedFilterIds={defaultFilterIds}
filters={toggleableFilters}
/>
</div>
{/if}
{/if}
2024-11-13 05:04:07 +00:00
<div class="my-2">
<ActionsSelector
bind:selectedActionIds={actionIds}
actions={$functions.filter((func) => func.type === 'action')}
/>
</div>
2024-11-07 08:53:39 +00:00
2024-11-13 05:04:07 +00:00
<div class="my-2">
<Capabilities bind:capabilities />
2024-11-07 08:18:48 +00:00
</div>
2024-11-13 05:04:07 +00:00
{#if Object.keys(capabilities).filter((key) => capabilities[key]).length > 0}
{@const availableFeatures = Object.entries(capabilities)
.filter(
([key, value]) =>
value && ['web_search', 'code_interpreter', 'image_generation'].includes(key)
)
.map(([key, value]) => key)}
{#if availableFeatures.length > 0}
<div class="my-2">
<DefaultFeatures {availableFeatures} bind:featureIds={defaultFeatureIds} />
2024-11-13 05:04:07 +00:00
</div>
{/if}
{/if}
2024-11-13 05:04:07 +00:00
<div class="my-2 text-gray-300 dark:text-gray-700">
<div class="flex w-full justify-between mb-2">
2025-11-24 02:17:14 +00:00
<div class=" self-center text-sm font-medium">{$i18n.t('JSON Preview')}</div>
<button
2025-02-16 03:27:25 +00:00
class="p-1 px-3 text-xs flex rounded-sm transition"
2024-11-13 05:04:07 +00:00
type="button"
on:click={() => {
showPreview = !showPreview;
}}
>
2024-11-13 05:04:07 +00:00
{#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>
2024-11-07 08:53:39 +00:00
2024-11-13 05:04:07 +00:00
{#if showPreview}
<div>
<textarea
2025-02-16 03:27:25 +00:00
class="text-sm w-full bg-transparent outline-hidden resize-none"
2024-11-13 05:04:07 +00:00
rows="10"
value={JSON.stringify(info, null, 2)}
disabled
readonly
/>
2024-11-07 08:53:39 +00:00
</div>
{/if}
2024-11-13 05:04:07 +00:00
</div>
<div class="my-2 flex justify-end pb-20">
<button
class=" text-sm px-3 py-2 transition rounded-lg {loading
2024-11-16 01:36:46 +00:00
? ' cursor-not-allowed bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'
: 'bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'} flex w-full justify-center"
2024-11-13 05:04:07 +00:00
type="submit"
disabled={loading}
>
<div class=" self-center font-medium">
{#if edit}
{$i18n.t('Save & Update')}
{:else}
{$i18n.t('Save & Create')}
{/if}
</div>
{#if loading}
<div class="ml-1.5 self-center">
2025-06-25 22:44:45 +00:00
<Spinner />
2024-11-13 05:04:07 +00:00
</div>
{/if}
</button>
</div>
2024-11-07 08:53:39 +00:00
</div>
2024-11-13 05:04:07 +00:00
</form>
{/if}
</div>
{/if}