refac: frontend

This commit is contained in:
Timothy Jaeryang Baek
2024-11-15 02:05:43 -08:00
parent 2ab5b2fd71
commit d9dc04f1a1
20 changed files with 1340 additions and 1407 deletions

View File

@@ -17,6 +17,7 @@
import { getTools } from '$lib/apis/tools';
import { getFunctions } from '$lib/apis/functions';
import { getKnowledgeItems } from '$lib/apis/knowledge';
import AccessPermissions from '../common/AccessPermissionsModal.svelte';
const i18n = getContext('i18n');
@@ -82,7 +83,7 @@
if (baseModel) {
if (baseModel.owned_by === 'openai') {
capabilities.usage = baseModel.info?.meta?.capabilities?.usage ?? false;
capabilities.usage = basemodel?.meta?.capabilities?.usage ?? false;
} else {
delete capabilities.usage;
}
@@ -159,33 +160,31 @@
id = model.id;
if (model.info.base_model_id) {
if (model.base_model_id) {
const base_model = $models
.filter((m) => !m?.preset && m?.owned_by !== 'arena')
.find((m) =>
[model.info.base_model_id, `${model.info.base_model_id}:latest`].includes(m.id)
);
.find((m) => [model.base_model_id, `${model.base_model_id}:latest`].includes(m.id));
console.log('base_model', base_model);
if (base_model) {
model.info.base_model_id = base_model.id;
model.base_model_id = base_model.id;
} else {
model.info.base_model_id = null;
model.base_model_id = null;
}
}
params = { ...params, ...model?.info?.params };
params = { ...params, ...model?.params };
params.stop = params?.stop
? (typeof params.stop === 'string' ? params.stop.split(',') : (params?.stop ?? [])).join(
','
)
: null;
toolIds = model?.info?.meta?.toolIds ?? [];
filterIds = model?.info?.meta?.filterIds ?? [];
actionIds = model?.info?.meta?.actionIds ?? [];
knowledge = (model?.info?.meta?.knowledge ?? []).map((item) => {
toolIds = model?.meta?.toolIds ?? [];
filterIds = model?.meta?.filterIds ?? [];
actionIds = model?.meta?.actionIds ?? [];
knowledge = (model?.meta?.knowledge ?? []).map((item) => {
if (item?.collection_name) {
return {
id: item.collection_name,
@@ -203,7 +202,7 @@
return item;
}
});
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
capabilities = { ...capabilities, ...(model?.meta?.capabilities ?? {}) };
if (model?.owned_by === 'openai') {
capabilities.usage = false;
}
@@ -212,8 +211,8 @@
...info,
...JSON.parse(
JSON.stringify(
model?.info
? model?.info
model
? model
: {
id: model.id,
name: model.name
@@ -441,6 +440,26 @@
{/if}
</div>
<div class="my-1">
<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>
<hr class=" dark:border-gray-850 my-1.5" />
<div class="my-2">
@@ -620,28 +639,8 @@
<Capabilities bind:capabilities />
</div>
<div class="my-1">
<div class="flex w-full justify-between items-center">
<div class=" self-center text-sm font-semibold">{$i18n.t('Tags')}</div>
</div>
<div class="mt-2">
<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 class="my-2">
<AccessPermissions />
</div>
<div class="my-2 text-gray-300 dark:text-gray-700">

View File

@@ -23,7 +23,6 @@
export let cloneHandler: Function;
export let exportHandler: Function;
export let moveToTopHandler: Function;
export let hideHandler: Function;
export let deleteHandler: Function;
export let onClose: Function;
@@ -83,71 +82,6 @@
<div class="flex items-center">{$i18n.t('Export')}</div>
</DropdownMenu.Item>
{#if user?.role === 'admin'}
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {
moveToTopHandler();
}}
>
<ArrowUpCircle />
<div class="flex items-center">{$i18n.t('Move to Top')}</div>
</DropdownMenu.Item>
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {
hideHandler();
}}
>
{#if model?.info?.meta?.hidden ?? false}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M3.98 8.223A10.477 10.477 0 0 0 1.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88"
/>
</svg>
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z"
/>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
/>
</svg>
{/if}
<div class="flex items-center">
{#if model?.info?.meta?.hidden ?? false}
{$i18n.t('Show Model')}
{:else}
{$i18n.t('Hide Model')}
{/if}
</div>
</DropdownMenu.Item>
{/if}
<hr class="border-gray-100 dark:border-gray-800 my-1" />
<DropdownMenu.Item