From a62b0924dfa02c98c4ab73926c15190c1a055d9a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 11 Jul 2024 00:02:59 -0500 Subject: [PATCH 01/72] Update config.json --- backend/data/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/data/config.json b/backend/data/config.json index 6c0ad2b9fb..7c7acde917 100644 --- a/backend/data/config.json +++ b/backend/data/config.json @@ -1,7 +1,7 @@ { "version": 0, "ui": { - "default_locale": "en-US", + "default_locale": "", "prompt_suggestions": [ { "title": ["Help me study", "vocabulary for a college entrance exam"], From 0ef27bfc5e74743d678bbbdbe29314c50221fbf1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 10:40:10 -0700 Subject: [PATCH 02/72] refac --- backend/apps/socket/main.py | 31 ++++++++++++++++++++ backend/main.py | 57 ++++++++++++++----------------------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/backend/apps/socket/main.py b/backend/apps/socket/main.py index 123ff31cd2..d3fece56d0 100644 --- a/backend/apps/socket/main.py +++ b/backend/apps/socket/main.py @@ -137,3 +137,34 @@ async def disconnect(sid): await sio.emit("user-count", {"count": len(USER_POOL)}) else: print(f"Unknown session ID {sid} disconnected") + + +async def get_event_emitter(request_info): + async def __event_emitter__(event_data): + await sio.emit( + "chat-events", + { + "chat_id": request_info["chat_id"], + "message_id": request_info["id"], + "data": event_data, + }, + to=request_info["session_id"], + ) + + return __event_emitter__ + + +async def get_event_call(request_info): + async def __event_call__(event_data): + response = await sio.call( + "chat-events", + { + "chat_id": request_info["chat_id"], + "message_id": request_info["id"], + "data": event_data, + }, + to=request_info["session_id"], + ) + return response + + return __event_call__ diff --git a/backend/main.py b/backend/main.py index 89252e1641..869f889086 100644 --- a/backend/main.py +++ b/backend/main.py @@ -29,7 +29,7 @@ from starlette.middleware.sessions import SessionMiddleware from starlette.responses import StreamingResponse, Response, RedirectResponse -from apps.socket.main import sio, app as socket_app +from apps.socket.main import sio, app as socket_app, get_event_emitter, get_event_call from apps.ollama.main import ( app as ollama_app, get_all_models as get_ollama_models, @@ -632,24 +632,12 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): message_id = body["id"] del body["id"] - async def __event_emitter__(data): - await sio.emit( - "chat-events", - { - "chat_id": chat_id, - "message_id": message_id, - "data": data, - }, - to=session_id, - ) - - async def __event_call__(data): - response = await sio.call( - "chat-events", - {"chat_id": chat_id, "message_id": message_id, "data": data}, - to=session_id, - ) - return response + __event_emitter__ = await get_event_emitter( + {"chat_id": chat_id, "message_id": message_id, "session_id": session_id} + ) + __event_call__ = await get_event_call( + {"chat_id": chat_id, "message_id": message_id, "session_id": session_id} + ) # Initialize data_items to store additional data to be sent to the client data_items = [] @@ -1107,24 +1095,21 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)): else: pass - async def __event_emitter__(event_data): - await sio.emit( - "chat-events", - { - "chat_id": data["chat_id"], - "message_id": data["id"], - "data": event_data, - }, - to=data["session_id"], - ) + __event_emitter__ = await get_event_emitter( + { + "chat_id": data["chat_id"], + "message_id": data["id"], + "session_id": data["session_id"], + } + ) - async def __event_call__(event_data): - response = await sio.call( - "chat-events", - {"chat_id": data["chat_id"], "message_id": data["id"], "data": event_data}, - to=data["session_id"], - ) - return response + __event_call__ = await get_event_call( + { + "chat_id": data["chat_id"], + "message_id": data["id"], + "session_id": data["session_id"], + } + ) def get_priority(function_id): function = Functions.get_function_by_id(function_id) From b094153af25f4792ec0998a8e5ae2a858067c164 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 10:41:13 -0700 Subject: [PATCH 03/72] fix --- backend/apps/socket/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/apps/socket/main.py b/backend/apps/socket/main.py index d3fece56d0..18ce7a6072 100644 --- a/backend/apps/socket/main.py +++ b/backend/apps/socket/main.py @@ -145,7 +145,7 @@ async def get_event_emitter(request_info): "chat-events", { "chat_id": request_info["chat_id"], - "message_id": request_info["id"], + "message_id": request_info["message_id"], "data": event_data, }, to=request_info["session_id"], @@ -160,7 +160,7 @@ async def get_event_call(request_info): "chat-events", { "chat_id": request_info["chat_id"], - "message_id": request_info["id"], + "message_id": request_info["message_id"], "data": event_data, }, to=request_info["session_id"], From 7ba7b959a81d6ddace59c3c45ae67b7d7b416660 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 11:00:42 -0700 Subject: [PATCH 04/72] feat: message event --- src/lib/components/chat/Chat.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index a6800f5127..2bd65e88f5 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -156,6 +156,8 @@ } else { message.citations = [data]; } + } else if (type === 'message') { + message.content += data.content; } else if (type === 'confirmation') { eventCallback = cb; showEventConfirmation = true; From 9ab97b834aa47d733317c5e1fcd3c481c0b2fae8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 13:22:24 -0700 Subject: [PATCH 05/72] revert: reset vector db --- src/lib/apis/rag/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/apis/rag/index.ts b/src/lib/apis/rag/index.ts index b32e544eef..5c0a47b357 100644 --- a/src/lib/apis/rag/index.ts +++ b/src/lib/apis/rag/index.ts @@ -425,7 +425,7 @@ export const resetUploadDir = async (token: string) => { export const resetVectorDB = async (token: string) => { let error = null; - const res = await fetch(`${RAG_API_BASE_URL}/reset`, { + const res = await fetch(`${RAG_API_BASE_URL}/reset/db`, { method: 'GET', headers: { Accept: 'application/json', From f462744fc8d9a164fde286966084b8156058e4c3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 13:43:44 -0700 Subject: [PATCH 06/72] refac --- backend/apps/ollama/main.py | 10 ++++++---- backend/apps/openai/main.py | 2 ++ backend/apps/webui/main.py | 11 +++++++++-- backend/main.py | 22 ++++++++++++++++------ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index fd4ba7b060..09df6cc33b 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -728,8 +728,10 @@ async def generate_chat_completion( ) payload = { - **form_data.model_dump(exclude_none=True), + **form_data.model_dump(exclude_none=True, exclude=["metadata"]), } + if "metadata" in payload: + del payload["metadata"] model_id = form_data.model model_info = Models.get_model_by_id(model_id) @@ -894,9 +896,9 @@ async def generate_openai_chat_completion( ): form_data = OpenAIChatCompletionForm(**form_data) - payload = { - **form_data.model_dump(exclude_none=True), - } + payload = {**form_data} + if "metadata" in payload: + del payload["metadata"] model_id = form_data.model model_info = Models.get_model_by_id(model_id) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 7c67c40ae9..8cd321802f 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -357,6 +357,8 @@ async def generate_chat_completion( ): idx = 0 payload = {**form_data} + if "metadata" in payload: + del payload["metadata"] model_id = form_data.get("model") model_info = Models.get_model_by_id(model_id) diff --git a/backend/apps/webui/main.py b/backend/apps/webui/main.py index ab28868ae4..7a0be2d22d 100644 --- a/backend/apps/webui/main.py +++ b/backend/apps/webui/main.py @@ -20,7 +20,6 @@ from apps.webui.routers import ( ) from apps.webui.models.functions import Functions from apps.webui.models.models import Models - from apps.webui.utils import load_function_module_by_id from utils.misc import stream_message_template @@ -53,7 +52,7 @@ import uuid import time import json -from typing import Iterator, Generator +from typing import Iterator, Generator, Optional from pydantic import BaseModel app = FastAPI() @@ -193,6 +192,14 @@ async def generate_function_chat_completion(form_data, user): model_id = form_data.get("model") model_info = Models.get_model_by_id(model_id) + metadata = None + if "metadata" in form_data: + metadata = form_data["metadata"] + del form_data["metadata"] + + if metadata: + print(metadata) + if model_info: if model_info.base_model_id: form_data["model"] = model_info.base_model_id diff --git a/backend/main.py b/backend/main.py index 869f889086..1ce3f699a7 100644 --- a/backend/main.py +++ b/backend/main.py @@ -618,6 +618,12 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): content={"detail": str(e)}, ) + # `task` field is used to determine the type of the request, e.g. `title_generation`, `query_generation`, etc. + task = None + if "task" in body: + task = body["task"] + del body["task"] + # Extract session_id, chat_id and message_id from the request body session_id = None if "session_id" in body: @@ -632,6 +638,8 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): message_id = body["id"] del body["id"] + + __event_emitter__ = await get_event_emitter( {"chat_id": chat_id, "message_id": message_id, "session_id": session_id} ) @@ -691,6 +699,13 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): if len(citations) > 0: data_items.append({"citations": citations}) + body["metadata"] = { + "session_id": session_id, + "chat_id": chat_id, + "message_id": message_id, + "task": task, + } + modified_body_bytes = json.dumps(body).encode("utf-8") # Replace the request body with the modified one request._body = modified_body_bytes @@ -811,9 +826,6 @@ def filter_pipeline(payload, user): if "detail" in res: raise Exception(r.status_code, res["detail"]) - if "pipeline" not in app.state.MODELS[model_id] and "task" in payload: - del payload["task"] - return payload @@ -1024,11 +1036,9 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u status_code=status.HTTP_404_NOT_FOUND, detail="Model not found", ) - model = app.state.MODELS[model_id] - pipe = model.get("pipe") - if pipe: + if model.get("pipe"): return await generate_function_chat_completion(form_data, user=user) if model["owned_by"] == "ollama": return await generate_ollama_chat_completion(form_data, user=user) From 7d7a29cfb907593c873c6d9edcff2a0bbef61720 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 13:53:47 -0700 Subject: [PATCH 07/72] fix --- backend/main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/main.py b/backend/main.py index 1ce3f699a7..636bbf646d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -618,12 +618,6 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): content={"detail": str(e)}, ) - # `task` field is used to determine the type of the request, e.g. `title_generation`, `query_generation`, etc. - task = None - if "task" in body: - task = body["task"] - del body["task"] - # Extract session_id, chat_id and message_id from the request body session_id = None if "session_id" in body: @@ -703,7 +697,6 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): "session_id": session_id, "chat_id": chat_id, "message_id": message_id, - "task": task, } modified_body_bytes = json.dumps(body).encode("utf-8") @@ -1038,6 +1031,15 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u ) model = app.state.MODELS[model_id] + # `task` field is used to determine the type of the request, e.g. `title_generation`, `query_generation`, etc. + task = None + if "task" in form_data: + task = form_data["task"] + del form_data["task"] + + if "metadata" in form_data: + form_data["metadata"]['task'] = task + if model.get("pipe"): return await generate_function_chat_completion(form_data, user=user) if model["owned_by"] == "ollama": From 4dd77b785ad4af9b9b14905679acdeb8ebab6940 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 14:12:44 -0700 Subject: [PATCH 08/72] fix --- backend/apps/ollama/main.py | 2 +- backend/main.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 09df6cc33b..9df8719e9d 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -895,8 +895,8 @@ async def generate_openai_chat_completion( user=Depends(get_verified_user), ): form_data = OpenAIChatCompletionForm(**form_data) + payload = {**form_data.model_dump(exclude_none=True, exclude=["metadata"])} - payload = {**form_data} if "metadata" in payload: del payload["metadata"] diff --git a/backend/main.py b/backend/main.py index 636bbf646d..01c2fde2ad 100644 --- a/backend/main.py +++ b/backend/main.py @@ -317,7 +317,7 @@ async def get_function_call_response( {"role": "user", "content": f"Query: {prompt}"}, ], "stream": False, - "task": TASKS.FUNCTION_CALLING, + "task": str(TASKS.FUNCTION_CALLING), } try: @@ -632,8 +632,6 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): message_id = body["id"] del body["id"] - - __event_emitter__ = await get_event_emitter( {"chat_id": chat_id, "message_id": message_id, "session_id": session_id} ) @@ -1037,12 +1035,16 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u task = form_data["task"] del form_data["task"] - if "metadata" in form_data: - form_data["metadata"]['task'] = task + if task: + if "metadata" in form_data: + form_data["metadata"]["task"] = task + else: + form_data["metadata"] = {"task": task} if model.get("pipe"): return await generate_function_chat_completion(form_data, user=user) if model["owned_by"] == "ollama": + print("generate_ollama_chat_completion") return await generate_ollama_chat_completion(form_data, user=user) else: return await generate_openai_chat_completion(form_data, user=user) @@ -1311,7 +1313,7 @@ async def generate_title(form_data: dict, user=Depends(get_verified_user)): "stream": False, "max_tokens": 50, "chat_id": form_data.get("chat_id", None), - "task": TASKS.TITLE_GENERATION, + "task": str(TASKS.TITLE_GENERATION), } log.debug(payload) @@ -1364,7 +1366,7 @@ async def generate_search_query(form_data: dict, user=Depends(get_verified_user) "messages": [{"role": "user", "content": content}], "stream": False, "max_tokens": 30, - "task": TASKS.QUERY_GENERATION, + "task": str(TASKS.QUERY_GENERATION), } print(payload) @@ -1421,7 +1423,7 @@ Message: """{{prompt}}""" "stream": False, "max_tokens": 4, "chat_id": form_data.get("chat_id", None), - "task": TASKS.EMOJI_GENERATION, + "task": str(TASKS.EMOJI_GENERATION), } log.debug(payload) From 8dcb3d78dccc85cb88847dccfae6b196dd9330dc Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 15:20:56 -0700 Subject: [PATCH 09/72] refac --- backend/apps/webui/main.py | 26 +++++++++++++++++++++++++- backend/constants.py | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/backend/apps/webui/main.py b/backend/apps/webui/main.py index 7a0be2d22d..3253704822 100644 --- a/backend/apps/webui/main.py +++ b/backend/apps/webui/main.py @@ -47,6 +47,8 @@ from config import ( OAUTH_PICTURE_CLAIM, ) +from apps.socket.main import get_event_call, get_event_emitter + import inspect import uuid import time @@ -197,8 +199,21 @@ async def generate_function_chat_completion(form_data, user): metadata = form_data["metadata"] del form_data["metadata"] + __event_emitter__ = None + __event_call__ = None + __task__ = None + if metadata: - print(metadata) + if ( + metadata.get("session_id") + and metadata.get("chat_id") + and metadata.get("message_id") + ): + __event_emitter__ = await get_event_emitter(metadata) + __event_call__ = await get_event_call(metadata) + + if metadata.get("task"): + __task__ = metadata.get("task") if model_info: if model_info.base_model_id: @@ -314,6 +329,15 @@ async def generate_function_chat_completion(form_data, user): params = {**params, "__user__": __user__} + if "__event_emitter__" in sig.parameters: + params = {**params, "__event_emitter__": __event_emitter__} + + if "__event_call__" in sig.parameters: + params = {**params, "__event_call__": __event_call__} + + if "__task__" in sig.parameters: + params = {**params, "__task__": __task__} + if form_data["stream"]: async def stream_content(): diff --git a/backend/constants.py b/backend/constants.py index 7c366c2224..b9c7fc430d 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -95,8 +95,8 @@ class TASKS(str, Enum): def __str__(self) -> str: return super().__str__() - DEFAULT = lambda task="": f"{task if task else 'default'}" - TITLE_GENERATION = "Title Generation" - EMOJI_GENERATION = "Emoji Generation" - QUERY_GENERATION = "Query Generation" - FUNCTION_CALLING = "Function Calling" + DEFAULT = lambda task="": f"{task if task else 'generation'}" + TITLE_GENERATION = "title_generation" + EMOJI_GENERATION = "emoji_generation" + QUERY_GENERATION = "query_generation" + FUNCTION_CALLING = "function_calling" From 9f9122b6d7f573a20bf895e1522a229e26952163 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 16:24:59 -0700 Subject: [PATCH 10/72] enh: ChatValves --- backend/apps/webui/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/apps/webui/main.py b/backend/apps/webui/main.py index 3253704822..570cad9f19 100644 --- a/backend/apps/webui/main.py +++ b/backend/apps/webui/main.py @@ -165,6 +165,10 @@ async def get_pipe_models(): f"{function_module.name}{manifold_pipe_name}" ) + pipe_flag = {"type": pipe.type} + if hasattr(function_module, "ChatValves"): + pipe_flag["valves_spec"] = function_module.ChatValves.schema() + pipe_models.append( { "id": manifold_pipe_id, @@ -172,10 +176,14 @@ async def get_pipe_models(): "object": "model", "created": pipe.created_at, "owned_by": "openai", - "pipe": {"type": pipe.type}, + "pipe": pipe_flag, } ) else: + pipe_flag = {"type": "pipe"} + if hasattr(function_module, "ChatValves"): + pipe_flag["valves_spec"] = function_module.ChatValves.schema() + pipe_models.append( { "id": pipe.id, @@ -183,7 +191,7 @@ async def get_pipe_models(): "object": "model", "created": pipe.created_at, "owned_by": "openai", - "pipe": {"type": "pipe"}, + "pipe": pipe_flag, } ) From 97098edfeb765ea98e832ed0e59b7801e91d992f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 17:18:18 -0700 Subject: [PATCH 11/72] feat: chat valves --- src/lib/components/chat/Chat.svelte | 15 ++- src/lib/components/chat/ChatControls.svelte | 8 ++ .../components/chat/Controls/Controls.svelte | 15 +++ .../components/chat/Settings/Valves.svelte | 87 +---------------- src/lib/components/common/Valves.svelte | 95 +++++++++++++++++++ .../workspace/common/ValvesModal.svelte | 87 +---------------- 6 files changed, 136 insertions(+), 171 deletions(-) create mode 100644 src/lib/components/common/Valves.svelte diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 2bd65e88f5..1acf3aa3ff 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -104,6 +104,7 @@ }; let params = {}; + let valves = {}; $: if (history.currentId !== null) { let _messages = []; @@ -1541,6 +1542,18 @@ - + { + const model = $models.find((m) => m.id === e); + + if (model) { + return [...a, model]; + } + return a; + }, [])} + bind:show={showControls} + bind:params + bind:valves + /> {/if} diff --git a/src/lib/components/chat/ChatControls.svelte b/src/lib/components/chat/ChatControls.svelte index 612af33785..72c083e999 100644 --- a/src/lib/components/chat/ChatControls.svelte +++ b/src/lib/components/chat/ChatControls.svelte @@ -6,7 +6,11 @@ export let show = false; + export let models = []; + export let chatId = null; + export let valves = {}; + export let params = {}; let largeScreen = false; @@ -43,6 +47,8 @@ on:close={() => { show = false; }} + {models} + bind:valves bind:params /> @@ -56,6 +62,8 @@ on:close={() => { show = false; }} + {models} + bind:valves bind:params /> diff --git a/src/lib/components/chat/Controls/Controls.svelte b/src/lib/components/chat/Controls/Controls.svelte index 2cb3bceeb7..a7095b8d6f 100644 --- a/src/lib/components/chat/Controls/Controls.svelte +++ b/src/lib/components/chat/Controls/Controls.svelte @@ -5,7 +5,10 @@ import XMark from '$lib/components/icons/XMark.svelte'; import AdvancedParams from '../Settings/Advanced/AdvancedParams.svelte'; + import Valves from '$lib/components/common/Valves.svelte'; + export let models = []; + export let valves = {}; export let params = {}; @@ -23,6 +26,18 @@
+ {#if models.length === 1 && models[0]?.pipe?.valves_spec} +
+
Valves
+ +
+ +
+
+ +
+ {/if} +
System Prompt
diff --git a/src/lib/components/chat/Settings/Valves.svelte b/src/lib/components/chat/Settings/Valves.svelte index ca97ade05c..579779162c 100644 --- a/src/lib/components/chat/Settings/Valves.svelte +++ b/src/lib/components/chat/Settings/Valves.svelte @@ -19,6 +19,7 @@ import Tooltip from '$lib/components/common/Tooltip.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; import Switch from '$lib/components/common/Switch.svelte'; + import Valves from '$lib/components/common/Valves.svelte'; const dispatch = createEventDispatcher(); @@ -170,91 +171,7 @@
{#if !loading} - {#if valvesSpec} - {#each Object.keys(valvesSpec.properties) as property, idx} -
-
-
- {valvesSpec.properties[property].title} - - {#if (valvesSpec?.required ?? []).includes(property)} - *required - {/if} -
- - -
- - {#if (valves[property] ?? null) !== null} - -
-
- {#if valvesSpec.properties[property]?.enum ?? null} - - {:else if (valvesSpec.properties[property]?.type ?? null) === 'boolean'} -
-
- {valves[property] ? 'Enabled' : 'Disabled'} -
- -
- -
-
- {:else} - - {/if} -
-
- {/if} - - {#if (valvesSpec.properties[property]?.description ?? null) !== null} -
- {valvesSpec.properties[property].description} -
- {/if} -
- {/each} - {:else} -
No valves
- {/if} + {:else} {/if} diff --git a/src/lib/components/common/Valves.svelte b/src/lib/components/common/Valves.svelte new file mode 100644 index 0000000000..f15a4fb23a --- /dev/null +++ b/src/lib/components/common/Valves.svelte @@ -0,0 +1,95 @@ + + +{#if valvesSpec} + {#each Object.keys(valvesSpec.properties) as property, idx} +
+
+
+ {valvesSpec.properties[property].title} + + {#if (valvesSpec?.required ?? []).includes(property)} + *required + {/if} +
+ + +
+ + {#if (valves[property] ?? null) !== null} + +
+
+ {#if valvesSpec.properties[property]?.enum ?? null} + + {:else if (valvesSpec.properties[property]?.type ?? null) === 'boolean'} +
+
+ {valves[property] ? 'Enabled' : 'Disabled'} +
+ +
+ +
+
+ {:else} + + {/if} +
+
+ {/if} + + {#if (valvesSpec.properties[property]?.description ?? null) !== null} +
+ {valvesSpec.properties[property].description} +
+ {/if} +
+ {/each} +{:else} +
No valves
+{/if} diff --git a/src/lib/components/workspace/common/ValvesModal.svelte b/src/lib/components/workspace/common/ValvesModal.svelte index 12315f9e67..1f23c510ec 100644 --- a/src/lib/components/workspace/common/ValvesModal.svelte +++ b/src/lib/components/workspace/common/ValvesModal.svelte @@ -13,6 +13,7 @@ import { getToolValvesById, getToolValvesSpecById, updateToolValvesById } from '$lib/apis/tools'; import Spinner from '../../common/Spinner.svelte'; import Switch from '$lib/components/common/Switch.svelte'; + import Valves from '$lib/components/common/Valves.svelte'; const i18n = getContext('i18n'); const dispatch = createEventDispatcher(); @@ -127,91 +128,7 @@ >
{#if !loading} - {#if valvesSpec} - {#each Object.keys(valvesSpec.properties) as property, idx} -
-
-
- {valvesSpec.properties[property].title} - - {#if (valvesSpec?.required ?? []).includes(property)} - *required - {/if} -
- - -
- - {#if (valves[property] ?? null) !== null} - -
-
- {#if valvesSpec.properties[property]?.enum ?? null} - - {:else if (valvesSpec.properties[property]?.type ?? null) === 'boolean'} -
-
- {valves[property] ? 'Enabled' : 'Disabled'} -
- -
- -
-
- {:else} - - {/if} -
-
- {/if} - - {#if (valvesSpec.properties[property]?.description ?? null) !== null} -
- {valvesSpec.properties[property].description} -
- {/if} -
- {/each} - {:else} -
No valves
- {/if} + {:else} {/if} From 90c3d68f00876873bdcc71eabb4c82c8577576b1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 11 Jul 2024 17:30:24 -0700 Subject: [PATCH 12/72] enh: input type event call --- src/lib/components/chat/Chat.svelte | 22 +++++++++++++++++-- .../components/common/ConfirmDialog.svelte | 17 +++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 1acf3aa3ff..8d82acb767 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -78,6 +78,8 @@ let showEventConfirmation = false; let eventConfirmationTitle = ''; let eventConfirmationMessage = ''; + let eventConfirmationInput = false; + let eventConfirmationInputPlaceholder = ''; let eventCallback = null; let showModelSelector = true; @@ -161,10 +163,21 @@ message.content += data.content; } else if (type === 'confirmation') { eventCallback = cb; + + eventConfirmationInput = false; showEventConfirmation = true; eventConfirmationTitle = data.title; eventConfirmationMessage = data.message; + } else if (type === 'input') { + eventCallback = cb; + + eventConfirmationInput = true; + showEventConfirmation = true; + + eventConfirmationTitle = data.title; + eventConfirmationMessage = data.message; + eventConfirmationInputPlaceholder = data.placeholder; } else { console.log('Unknown message type', data); } @@ -1411,8 +1424,14 @@ bind:show={showEventConfirmation} title={eventConfirmationTitle} message={eventConfirmationMessage} + input={eventConfirmationInput} + inputPlaceholder={eventConfirmationInputPlaceholder} on:confirm={(e) => { - eventCallback(true); + if (e.detail) { + eventCallback(e.detail); + } else { + eventCallback(true); + } }} on:cancel={() => { eventCallback(false); @@ -1545,7 +1564,6 @@ { const model = $models.find((m) => m.id === e); - if (model) { return [...a, model]; } diff --git a/src/lib/components/common/ConfirmDialog.svelte b/src/lib/components/common/ConfirmDialog.svelte index 2096a41cf7..9373704369 100644 --- a/src/lib/components/common/ConfirmDialog.svelte +++ b/src/lib/components/common/ConfirmDialog.svelte @@ -13,9 +13,14 @@ export let cancelLabel = $i18n.t('Cancel'); export let confirmLabel = $i18n.t('Confirm'); + export let input = false; + export let inputPlaceholder = ''; + export let show = false; + let modalElement = null; let mounted = false; + let inputValue = ''; const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') { @@ -73,6 +78,16 @@ {:else} {$i18n.t('This action cannot be undone. Do you wish to continue?')} {/if} + + {#if input} +