From faf3e81bf082e17d4d4de0b2f4e99e912be63c36 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 12 Nov 2024 21:04:07 -0800 Subject: [PATCH] fix --- .../workspace/Models/ModelEditor.svelte | 862 +++++++++--------- 1 file changed, 439 insertions(+), 423 deletions(-) diff --git a/src/lib/components/workspace/Models/ModelEditor.svelte b/src/lib/components/workspace/Models/ModelEditor.svelte index 81f7fe635..4b6350903 100644 --- a/src/lib/components/workspace/Models/ModelEditor.svelte +++ b/src/lib/components/workspace/Models/ModelEditor.svelte @@ -14,6 +14,9 @@ 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'; + import { getTools } from '$lib/apis/tools'; + import { getFunctions } from '$lib/apis/functions'; + import { getKnowledgeItems } from '$lib/apis/knowledge'; const i18n = getContext('i18n'); @@ -30,6 +33,8 @@ let showAdvanced = false; let showPreview = false; + let loaded = false; + // /////////// // model // /////////// @@ -138,6 +143,10 @@ }; onMount(async () => { + await tools.set(await getTools(localStorage.token)); + await functions.set(await getFunctions(localStorage.token)); + await knowledgeCollections.set(await getKnowledgeItems(localStorage.token)); + // Scroll to top 'workspace-container' element const workspaceContainer = document.getElementById('workspace-container'); if (workspaceContainer) { @@ -215,292 +224,206 @@ console.log(model); } + + loaded = true; }); -
- { - let reader = new FileReader(); - reader.onload = (event) => { - let originalImageUrl = `${event.target.result}`; +{#if loaded} +
+ { + let reader = new FileReader(); + reader.onload = (event) => { + let originalImageUrl = `${event.target.result}`; - const img = new Image(); - img.src = originalImageUrl; + const img = new Image(); + img.src = originalImageUrl; - img.onload = function () { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); + 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 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; - } + // 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; + // 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; + // 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); + // 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(); + // Get the base64 representation of the compressed image + const compressedSrc = canvas.toDataURL(); - // Display the compressed image - info.meta.profile_image_url = compressedSrc; + // Display the compressed image + info.meta.profile_image_url = compressedSrc; - inputFiles = null; + inputFiles = null; + }; }; - }; - 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; - } - }} - /> - - {#if !edit || model} -
{ - submitHandler(); + 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; + } }} - > -
-
- -
-
- -
-
-
-
- -
-
- -
- -
- -
-
-
- - {#if !edit || model.preset} -
-
{$i18n.t('Base Model (From)')}
- -
- -
-
- {/if} - -
-
-
{$i18n.t('Description')}
+ /> + {#if !edit || model} + { + submitHandler(); + }} + > +
+
- - {#if info.meta.description !== null} -