From 9696bb561f52a5933ae5fc4781f27d5f9a1efb31 Mon Sep 17 00:00:00 2001 From: qbc Date: Wed, 21 Aug 2024 15:30:04 +0800 Subject: [PATCH] Add support of html configs when running as_gradio command (#414) --- src/agentscope/studio/static/js/workstation.js | 1 + src/agentscope/web/workstation/workflow_dag.py | 16 ++++++++++++++++ src/agentscope/web/workstation/workflow_node.py | 10 +++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/agentscope/studio/static/js/workstation.js b/src/agentscope/studio/static/js/workstation.js index 946822d75..fceaac016 100644 --- a/src/agentscope/studio/static/js/workstation.js +++ b/src/agentscope/studio/static/js/workstation.js @@ -1728,6 +1728,7 @@ function showExportHTMLPopup() { // Remove the html attribute from the nodes to avoid inconsistencies in html removeHtmlFromUsers(rawData); + sortElementsByPosition(rawData); const exportData = JSON.stringify(rawData, null, 4); diff --git a/src/agentscope/web/workstation/workflow_dag.py b/src/agentscope/web/workstation/workflow_dag.py index 242a8b36c..d9ffe43f7 100644 --- a/src/agentscope/web/workstation/workflow_dag.py +++ b/src/agentscope/web/workstation/workflow_dag.py @@ -310,6 +310,22 @@ def build_dag(config: dict) -> ASDiGraph: """ dag = ASDiGraph() + # for html json file, + # retrieve the contents of config["drawflow"]["Home"]["data"], + # and remove the node whose class is "welcome" + if ( + "drawflow" in config + and "Home" in config["drawflow"] + and "data" in config["drawflow"]["Home"] + ): + config = config["drawflow"]["Home"]["data"] + + config = { + k: v + for k, v in config.items() + if not ("class" in v and v["class"] == "welcome") + } + for node_id, node_info in config.items(): config[node_id] = sanitize_node_data(node_info) diff --git a/src/agentscope/web/workstation/workflow_node.py b/src/agentscope/web/workstation/workflow_node.py index 827905a22..183f67883 100644 --- a/src/agentscope/web/workstation/workflow_node.py +++ b/src/agentscope/web/workstation/workflow_node.py @@ -717,7 +717,7 @@ def __init__( def compile(self) -> dict: return { - "imports": "from agentscope.service import ServiceFactory\n" + "imports": "from agentscope.service import ServiceToolkit\n" "from functools import partial\n" "from agentscope.service import bing_search", "inits": f"{self.var_name} = partial(bing_search," @@ -745,7 +745,7 @@ def __init__( def compile(self) -> dict: return { - "imports": "from agentscope.service import ServiceFactory\n" + "imports": "from agentscope.service import ServiceToolkit\n" "from functools import partial\n" "from agentscope.service import google_search", "inits": f"{self.var_name} = partial(google_search," @@ -773,7 +773,7 @@ def __init__( def compile(self) -> dict: return { - "imports": "from agentscope.service import ServiceFactory\n" + "imports": "from agentscope.service import ServiceToolkit\n" "from agentscope.service import execute_python_code", "inits": f"{self.var_name} = execute_python_code", "execs": "", @@ -799,7 +799,7 @@ def __init__( def compile(self) -> dict: return { - "imports": "from agentscope.service import ServiceFactory\n" + "imports": "from agentscope.service import ServiceToolkit\n" "from agentscope.service import read_text_file", "inits": f"{self.var_name} = read_text_file", "execs": "", @@ -825,7 +825,7 @@ def __init__( def compile(self) -> dict: return { - "imports": "from agentscope.service import ServiceFactory\n" + "imports": "from agentscope.service import ServiceToolkit\n" "from agentscope.service import write_text_file", "inits": f"{self.var_name} = write_text_file", "execs": "",