From f3114aef1065c27ffbe0d1f21146fc627735347a Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Wed, 24 Jan 2024 17:01:37 +0100 Subject: [PATCH] [Assistant] Delete avatar button instead of reset (#725) * Add rate-limited image generating endpoint * Add generate avatar button * add little padding for firefox focus ring * format * fix upload image bug * Fix uploads, replace reset by delete * left-align buttons * rm avatar generation feature * final changes to delete feature * sys prompt min height * padding * Add object-cover everywhere --------- Co-authored-by: Victor Mustar --- .env | 4 +- src/lib/components/AssistantSettings.svelte | 109 ++++++++++-------- src/lib/components/NavConversationItem.svelte | 2 +- src/lib/utils/generateAvatar.ts | 24 ---- src/routes/+layout.server.ts | 3 - src/routes/settings/+layout.svelte | 2 +- .../[assistantId]/edit/+page.server.ts | 45 +++----- .../settings/assistants/new/+page.server.ts | 30 ----- 8 files changed, 77 insertions(+), 142 deletions(-) delete mode 100644 src/lib/utils/generateAvatar.ts diff --git a/.env b/.env index 421fce63526..c14a1ae41b9 100644 --- a/.env +++ b/.env @@ -129,6 +129,4 @@ EXPOSE_API=true # PUBLIC_APP_DATA_SHARING=1 # PUBLIC_APP_DISCLAIMER=1 -ENABLE_ASSISTANTS=false #set to true to enable assistants feature -ASSISTANTS_GENERATE_AVATAR=true #requires an hf token, uses the model description and name to generate an avatar using a text to image model -TEXT_TO_IMAGE_MODEL="runwayml/stable-diffusion-v1-5" +ENABLE_ASSISTANTS=false #set to true to enable assistants feature \ No newline at end of file diff --git a/src/lib/components/AssistantSettings.svelte b/src/lib/components/AssistantSettings.svelte index 6511ee7bee0..85394e8d6cf 100644 --- a/src/lib/components/AssistantSettings.svelte +++ b/src/lib/components/AssistantSettings.svelte @@ -7,8 +7,8 @@ import { applyAction, enhance } from "$app/forms"; import { base } from "$app/paths"; import CarbonPen from "~icons/carbon/pen"; + import CarbonUpload from "~icons/carbon/upload"; import { useSettingsStore } from "$lib/stores/settings"; - import { page } from "$app/stores"; import IconLoading from "./icons/IconLoading.svelte"; type ActionData = { @@ -41,10 +41,19 @@ let inputMessage3 = assistant?.exampleInputs[2] ?? ""; let inputMessage4 = assistant?.exampleInputs[3] ?? ""; + function resetErrors() { + if (form) { + form.errors = []; + form.error = false; + } + } + function onFilesChange(e: Event) { const inputEl = e.target as HTMLInputElement; if (inputEl.files?.length) { files = inputEl.files; + resetErrors(); + deleteExistingAvatar = false; } } @@ -52,9 +61,9 @@ return returnForm?.errors.find((error) => error.field === field)?.message ?? ""; } - let loading = false; + let deleteExistingAvatar = false; - let generateAvatar = false; + let loading = false;
{ loading = true; - const avatar = formData.get("avatar"); - - if (avatar && typeof avatar !== "string" && avatar.size > 0 && compress) { - await compress(avatar, { + if (files?.[0] && files[0].size > 0 && compress) { + await compress(files[0], { maxWidth: 500, maxHeight: 500, quality: 1, @@ -75,6 +82,16 @@ }); } + if (deleteExistingAvatar === true) { + if (assistant?.avatar) { + // if there is an avatar we explicitly removei t + formData.set("avatar", "null"); + } else { + // else we just remove it from the input + formData.delete("avatar"); + } + } + return async ({ result }) => { loading = false; await applyAction(result); @@ -93,73 +110,72 @@

{/if} -
+
-