From 69a1b56e8950f9fccc98c79626f1ca16848f8079 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:38:41 +0800 Subject: [PATCH 01/12] Update wikipedia.py --- graph/component/wikipedia.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/graph/component/wikipedia.py b/graph/component/wikipedia.py index 9e67875961e..48abefaf6e7 100644 --- a/graph/component/wikipedia.py +++ b/graph/component/wikipedia.py @@ -30,9 +30,16 @@ class WikipediaParam(ComponentParamBase): def __init__(self): super().__init__() self.top_n = 10 + self.lang = 'en' def check(self): self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.lang, "Wikipedia languages", + ['af', 'pl', 'ar', 'ast', 'az', 'bg', 'nan', 'bn', 'be', 'ca', 'cs', 'cy', 'da', 'de', + 'et', 'el', 'en', 'es', 'eo', 'eu', 'fa', 'fr', 'gl', 'ko', 'hy', 'hi', 'hr', 'id', + 'it', 'he', 'ka', 'lld', 'la', 'lv', 'lt', 'hu', 'mk', 'arz', 'ms', 'min', 'my', 'nl', + 'ja', 'nb', 'nn', 'ce', 'uz', 'pt', 'kk', 'ro', 'ru', 'ceb', 'sk', 'sl', 'sr', 'sh', + 'fi', 'sv', 'ta', 'tt', 'th', 'tg', 'azb', 'tr', 'uk', 'ur', 'vi', 'war', 'zh', 'yue']) class Wikipedia(ComponentBase, ABC): @@ -45,9 +52,11 @@ def _run(self, history, **kwargs): return Wikipedia.be_output(self._param.no) wiki_res = [] - for wiki_key in wikipedia.search(ans, results=self._param.top_n): + wikipedia.set_lang(self._param.lang) + wiki_engine = wikipedia + for wiki_key in wiki_engine.search(ans, results=self._param.top_n): try: - page = wikipedia.page(title=wiki_key, auto_suggest=False) + page = wiki_engine.page(title=wiki_key, auto_suggest=False) wiki_res.append({"content": '' + page.title + ' ' + page.summary}) except Exception as e: print(e) From 268c0c7eb7fb7df47600341af51ca37a3241411e Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:37:28 +0800 Subject: [PATCH 02/12] Update requirements.txt --- requirements.txt | 176 ++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 125 deletions(-) diff --git a/requirements.txt b/requirements.txt index 43eddf5b18f..9d02e96486e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,153 +1,79 @@ -accelerate==0.27.2 -aiohttp==3.9.5 -aiosignal==1.3.1 -annotated-types==0.6.0 -anyio==4.3.0 -argon2-cffi==23.1.0 -argon2-cffi-bindings==21.2.0 Aspose.Slides==24.2.0 -attrs==23.2.0 -blinker==1.7.0 -cachelib==0.12.0 +BCEmbedding==0.1.3 +boto3==1.34.140 +botocore==1.34.140 cachetools==5.3.3 -certifi==2024.2.2 -cffi==1.16.0 -charset-normalizer==3.3.2 -click==8.1.7 -coloredlogs==15.0.1 -cryptography==42.0.5 +chardet==5.2.0 +cn2an==0.5.22 dashscope==1.14.1 -datasets==2.17.1 datrie==0.8.2 demjson3==3.0.6 -dill==0.3.8 -distro==1.9.0 -elastic-transport==8.12.0 +discord.py==2.3.2 +duckduckgo_search==6.1.9 +elastic_transport==8.12.0 elasticsearch==8.12.1 -elasticsearch-dsl==8.12.0 -et-xmlfile==1.1.0 -filelock==3.13.1 +elasticsearch_dsl==8.12.0 fastembed==0.2.6 -FlagEmbedding==1.2.5 -Flask==3.0.2 -Flask-Cors==4.0.0 -Flask-Login==0.6.3 -Flask-Session==0.6.0 -flatbuffers==23.5.26 -frozenlist==1.4.1 -fsspec==2023.10.0 -h11==0.14.0 +fasttext==0.9.3 +filelock==3.15.4 +FlagEmbedding==1.2.10 +Flask==3.0.3 +Flask_Cors==4.0.0 +Flask_Login==0.6.3 +flask_session==0.8.0 +groq==0.9.0 hanziconv==0.3.2 -httpcore==1.0.4 +html_text==0.6.2 httpx==0.27.0 -huggingface-hub==0.20.3 -humanfriendly==10.0 -idna==3.6 -install==1.3.5 +huggingface_hub==0.20.3 +infinity_emb==0.0.51 itsdangerous==2.1.2 -Jinja2==3.1.3 -joblib==1.3.2 -lxml==5.1.0 -MarkupSafe==2.1.5 +Markdown==3.6 minio==7.2.4 -mpmath==1.3.0 -multidict==6.0.5 -multiprocess==0.70.16 -networkx==3.2.1 +mistralai==0.4.2 nltk==3.8.1 numpy==1.26.4 -nvidia-cublas-cu12==12.1.3.1 -nvidia-cuda-cupti-cu12==12.1.105 -nvidia-cuda-nvrtc-cu12==12.1.105 -nvidia-cuda-runtime-cu12==12.1.105 -nvidia-cudnn-cu12==8.9.2.26 -nvidia-cufft-cu12==11.0.2.54 -nvidia-curand-cu12==10.3.2.106 -nvidia-cusolver-cu12==11.4.5.107 -nvidia-cusparse-cu12==12.1.0.106 -nvidia-nccl-cu12==2.19.3 -nvidia-nvjitlink-cu12==12.3.101 -nvidia-nvtx-cu12==12.1.105 -ollama==0.1.9 -onnxruntime-gpu==1.17.1 -openai==1.12.0 -opencv-python==4.9.0.80 +ollama==0.2.1 +onnxruntime==1.17.3 +onnxruntime_gpu==1.17.1 +openai==1.35.14 +opencv_python==4.9.0.80 +opencv_python_headless==4.9.0.80 openpyxl==3.1.2 -packaging==23.2 -pandas==2.2.1 -pdfminer.six==20221105 +pandas==2.2.2 pdfplumber==0.10.4 peewee==3.17.1 -pillow==10.3.0 -protobuf==4.25.3 -psutil==5.9.8 -pyarrow==15.0.0 -pyarrow-hotfix==0.6 +Pillow==10.4.0 +pipreqs==0.5.0 +protobuf==5.27.2 pyclipper==1.3.0.post5 -pycparser==2.21 -pycryptodome -pycryptodome-test-vectors -pycryptodomex -pydantic==2.6.2 -pydantic_core==2.16.3 -PyJWT==2.8.0 -PyMySQL==1.1.1 +pycryptodomex==3.20.0 PyPDF2==3.0.1 -pypdfium2==4.27.0 -python-dateutil==2.8.2 -python-docx==1.1.0 +pytest==8.2.2 python-dotenv==1.0.1 -python-pptx==0.6.23 -PyYAML==6.0.1 +python_dateutil==2.8.2 +python_pptx==0.6.23 +readability_lxml==0.8.1 redis==5.0.3 -regex==2023.12.25 -requests==2.31.0 -ruamel.yaml==0.18.6 -ruamel.yaml.clib==0.2.8 -safetensors==0.4.2 -scikit-learn==1.4.1.post1 -scipy==1.12.0 -sentence-transformers==2.4.0 -shapely==2.0.3 +Requests==2.32.3 +roman_numbers==1.0.2 +ruamel.base==1.0.0 +scikit_learn==1.4.1.post1 +selenium==4.22.0 +setuptools==69.5.1 +Shapely==2.0.5 six==1.16.0 -sniffio==1.3.1 StrEnum==0.4.15 -sympy==1.12 -threadpoolctl==3.3.0 tika==2.6.0 tiktoken==0.6.0 -tokenizers==0.15.2 -torch==2.2.1 -tqdm==4.66.2 +torch==2.3.0 transformers==4.38.1 -triton==2.2.0 -typing_extensions==4.10.0 -tzdata==2024.1 -urllib3==2.2.1 +umap==0.1.1 +volcengine==1.0.146 +webdriver_manager==4.0.1 Werkzeug==3.0.3 -xgboost==2.0.3 -XlsxWriter==3.2.0 +wikipedia==1.4.0 +word2number==1.1 +xgboost==2.1.0 xpinyin==0.7.6 -xxhash==3.4.1 -yarl==1.9.4 zhipuai==2.0.1 -BCEmbedding -loguru==0.7.2 -umap-learn -fasttext==0.9.2 -pybind11==2.13.1 -volcengine==1.0.141 -readability-lxml==0.8.1 -html_text==0.6.2 -selenium==4.21.0 -webdriver-manager==4.0.1 -cn2an==0.5.22 -roman-numbers==1.0.2 -word2number==1.1 -markdown==3.6 -mistralai==0.4.2 -boto3==1.34.140 -duckduckgo_search==6.1.9 -google-generativeai==0.7.2 -groq==0.9.0 -wikipedia==1.4.0 From 92cf45134adabff305b38d2f7fea9d768a030995 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Fri, 19 Jul 2024 18:23:24 +0800 Subject: [PATCH 03/12] Update llm_service.py --- api/db/services/llm_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/db/services/llm_service.py b/api/db/services/llm_service.py index 5906927b7bc..a994d6103eb 100644 --- a/api/db/services/llm_service.py +++ b/api/db/services/llm_service.py @@ -70,7 +70,7 @@ def model_instance(cls, tenant_id, llm_type, elif llm_type == LLMType.SPEECH2TEXT.value: mdlnm = tenant.asr_id elif llm_type == LLMType.IMAGE2TEXT.value: - mdlnm = tenant.img2txt_id + mdlnm = tenant.img2txt_id if not llm_name else llm_name elif llm_type == LLMType.CHAT.value: mdlnm = tenant.llm_id if not llm_name else llm_name elif llm_type == LLMType.RERANK: From ad5a5b8bed32a47c073f0484feb235bcff6e94cd Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Fri, 19 Jul 2024 18:24:37 +0800 Subject: [PATCH 04/12] Update index.tsx --- web/src/components/llm-setting-items/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/llm-setting-items/index.tsx b/web/src/components/llm-setting-items/index.tsx index a8365d616e8..c31d7aabeea 100644 --- a/web/src/components/llm-setting-items/index.tsx +++ b/web/src/components/llm-setting-items/index.tsx @@ -46,7 +46,7 @@ const LlmSettingItems = ({ prefix, formItemLayout = {} }: IProps) => { {...formItemLayout} rules={[{ required: true, message: t('modelMessage') }]} > - Date: Mon, 22 Jul 2024 18:27:56 +0800 Subject: [PATCH 05/12] Update init_data.py --- api/db/init_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/db/init_data.py b/api/db/init_data.py index 0acfe7b12a5..61fd0e6de01 100644 --- a/api/db/init_data.py +++ b/api/db/init_data.py @@ -121,6 +121,8 @@ def init_llm_factory(): LLMFactoriesService.filter_delete([LLMFactoriesService.model.name == "QAnything"]) LLMService.filter_delete([LLMService.model.fid == "QAnything"]) TenantLLMService.filter_update([TenantLLMService.model.llm_factory == "QAnything"], {"llm_factory": "Youdao"}) + TenantService.filter_update([1 == 1], { + "parser_ids": "naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio"}) ## insert openai two embedding models to the current openai user. print("Start to insert 2 OpenAI embedding models...") tenant_ids = set([row["tenant_id"] for row in TenantLLMService.get_openai_models()]) From addfea5f889c6464e904c68357589ed32f6562d1 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:45:54 +0800 Subject: [PATCH 06/12] Update __init__.py --- agent/component/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/component/__init__.py b/agent/component/__init__.py index 43fa3eeb803..ccd59f9e93c 100644 --- a/agent/component/__init__.py +++ b/agent/component/__init__.py @@ -20,6 +20,7 @@ from .deepl import DeepL, DeepLParam from .github import GitHub, GitHubParam from .baidufanyi import BaiduFanyi, BaiduFanyiParam +from .qweather import QWeather, QWeatherParam def component_class(class_name): m = importlib.import_module("agent.component") From 7cf0381dea5edfcf87778ac75494e523eb1848bf Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:13:22 +0800 Subject: [PATCH 07/12] Update switch.py --- agent/component/switch.py | 96 +++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/agent/component/switch.py b/agent/component/switch.py index 21b78efd0e9..0ed343ffab5 100644 --- a/agent/component/switch.py +++ b/agent/component/switch.py @@ -14,64 +14,100 @@ # limitations under the License. # from abc import ABC - -import pandas as pd from agent.component.base import ComponentBase, ComponentParamBase class SwitchParam(ComponentParamBase): - """ Define the Switch component parameters. """ + def __init__(self): super().__init__() """ { - "cpn_id": "categorize:0", - "not": False, - "operator": "gt/gte/lt/lte/eq/in", - "value": "", + "logical_operator" : "and | or" + "items" : [ + {"cpn_id": "categorize:0", "operator": "contains", "value": ""}, + {"cpn_id": "categorize:0", "operator": "contains", "value": ""},...], "to": "" } """ self.conditions = [] - self.default = "" + self.end_cpn_id = "" + self.operators = ['contains', 'not contains', 'start with', 'end with', 'empty', 'not empty', '=', '≠', '>', + '<', '≥', '≤'] def check(self): self.check_empty(self.conditions, "[Switch] conditions") - self.check_empty(self.default, "[Switch] Default path") for cond in self.conditions: if not cond["to"]: raise ValueError(f"[Switch] 'To' can not be empty!") - - def operators(self, field, op, value): - if op == "gt": - return float(field) > float(value) - if op == "gte": - return float(field) >= float(value) - if op == "lt": - return float(field) < float(value) - if op == "lte": - return float(field) <= float(value) - if op == "eq": - return str(field) == str(value) - if op == "in": - return str(field).find(str(value)) >= 0 - return False + if cond["logical_operator"] not in ["and", "or"] and len(cond["items"]) == 1: + raise ValueError(f"[Switch] Please set logical_operator correctly!") class Switch(ComponentBase, ABC): component_name = "Switch" - def _run(self, history, **kwargs): + def _run(self, **kwargs): + for cond in self._param.conditions: - input = self._canvas.get_component(cond["cpn_id"])["obj"].output()[1] - if self._param.operators(input.iloc[0, 0], cond["operator"], cond["value"]): - if not cond["not"]: - return pd.DataFrame([{"content": cond["to"]}]) + if len(cond["items"]) == 1: + out = self._canvas.get_component(cond["items"][0]["cpn_id"])["obj"].output()[1] + cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) + if self.process_operator(cpn_input, cond["items"][0]["operator"], cond["items"][0]["value"]): + return Switch.be_output(cond["to"]) + + if cond["logical_operator"] == "and": + res = True + for item in cond["items"]: + out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1] + cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) + if not self.process_operator(cpn_input, item["operator"], item["value"]): + res = False + break + if res: + return Switch.be_output(cond["to"]) - return pd.DataFrame([{"content": self._param.default}]) + res = False + for item in cond["items"]: + out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1] + cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) + if self.process_operator(cpn_input, item["operator"], item["value"]): + res = True + break + if res: + return Switch.be_output(cond["to"]) + return Switch.be_output(self._param.end_cpn_id) + def process_operator(self, input: str, operator: str, value: str) -> bool: + if not isinstance(input, str) or not isinstance(value, str): + raise ValueError('Invalid input or value type: string') + if operator == "contains": + return True if value in input else False + elif operator == "not contains": + return True if value not in input else False + elif operator == "start with": + return True if input.startswith(value) else False + elif operator == "end with": + return True if input.endswith(value) else False + elif operator == "empty": + return True if not input else False + elif operator == "not empty": + return True if input else False + elif operator == "=": + return True if input == value else False + elif operator == "≠": + return True if input != value else False + elif operator == ">": + return True if input > value else False + elif operator == "<": + return True if input < value else False + elif operator == "≥": + return True if input >= value else False + elif operator == "≤": + return True if input <= value else False + raise ValueError('Not supported operator' + operator) From fb585aa403b044d4ec758d106775b11e823bd62c Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:27:37 +0800 Subject: [PATCH 08/12] Add files via upload --- .../baidu_generate_and_switch.json | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 agent/test/dsl_examples/baidu_generate_and_switch.json diff --git a/agent/test/dsl_examples/baidu_generate_and_switch.json b/agent/test/dsl_examples/baidu_generate_and_switch.json new file mode 100644 index 00000000000..c52032a9d63 --- /dev/null +++ b/agent/test/dsl_examples/baidu_generate_and_switch.json @@ -0,0 +1,130 @@ +{ + "components": { + "begin": { + "obj":{ + "component_name": "Begin", + "params": { + "prologue": "Hi there!" + } + }, + "downstream": ["answer:0"], + "upstream": [] + }, + "answer:0": { + "obj": { + "component_name": "Answer", + "params": {} + }, + "downstream": ["baidu:0"], + "upstream": ["begin", "message:0","message:1"] + }, + "baidu:0": { + "obj": { + "component_name": "Baidu", + "params": {} + }, + "downstream": ["generate:0"], + "upstream": ["answer:0"] + }, + "generate:0": { + "obj": { + "component_name": "Generate", + "params": { + "llm_id": "deepseek-chat", + "prompt": "You are an intelligent assistant. Please answer the user's question based on what Baidu searched. First, please output the user's question and the content searched by Baidu, and then answer yes, no, or i don't know.Here is the user's question:{user_input}The above is the user's question.Here is what Baidu searched for:{baidu}The above is the content searched by Baidu.", + "temperature": 0.2 + }, + "parameters": [ + { + "component_id": "answer:0", + "id": "69415446-49bf-4d4b-8ec9-ac86066f7709", + "key": "user_input" + }, + { + "component_id": "baidu:0", + "id": "83363c2a-00a8-402f-a45c-ddc4097d7d8b", + "key": "baidu" + } + ] + }, + "downstream": ["switch:0"], + "upstream": ["baidu:0"] + }, + "switch:0": { + "obj": { + "component_name": "Switch", + "params": { + "conditions": [ + { + "logical_operator" : "or", + "items" : [ + {"cpn_id": "generate:0", "operator": "contains", "value": "yes"}, + {"cpn_id": "generate:0", "operator": "contains", "value": "YES"}, + {"cpn_id": "generate:0", "operator": "contains", "value": "Yes"} + ], + "to": "message:0" + }, + { + "logical_operator" : "and", + "items" : [ + {"cpn_id": "generate:0", "operator": "contains", "value": "no"}, + {"cpn_id": "generate:0", "operator": "not contains", "value": "yes"}, + {"cpn_id": "generate:0", "operator": "not contains", "value": "know"} + ], + "to": "message:1" + }, + { + "logical_operator" : "", + "items" : [ + {"cpn_id": "generate:0", "operator": "contains", "value": "know"} + ], + "to": "message:2" + } + ], + "end_cpn_id": "answer:0" + + } + }, + "downstream": ["message:0","message:1"], + "upstream": ["generate:0"] + }, + "message:0": { + "obj": { + "component_name": "Message", + "params": { + "messages": ["YES YES YES YES YES YES YES YES YES YES YES YES"] + } + }, + + "upstream": ["switch:0"], + "downstream": ["answer:0"] + }, + "message:1": { + "obj": { + "component_name": "Message", + "params": { + "messages": ["NO NO NO NO NO NO NO NO NO NO NO NO NO NO"] + } + }, + + "upstream": ["switch:0"], + "downstream": ["answer:0"] + }, + "message:2": { + "obj": { + "component_name": "Message", + "params": { + "messages": ["I DON'T KNOW---------------------------"] + } + }, + + "upstream": ["switch:0"], + "downstream": ["answer:0"] + } + }, + "history": [], + "messages": [], + "reference": {}, + "path": [], + "answer": [] +} From b662973eed9084a0b7ea050ce8af050c5e81941b Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:40:06 +0800 Subject: [PATCH 09/12] Update switch.py --- agent/component/switch.py | 42 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/agent/component/switch.py b/agent/component/switch.py index 0ed343ffab5..76a27068c08 100644 --- a/agent/component/switch.py +++ b/agent/component/switch.py @@ -34,7 +34,7 @@ def __init__(self): } """ self.conditions = [] - self.end_cpn_id = "" + self.end_cpn_id = "answer:0" self.operators = ['contains', 'not contains', 'start with', 'end with', 'empty', 'not empty', '=', '≠', '>', '<', '≥', '≤'] @@ -42,32 +42,37 @@ def check(self): self.check_empty(self.conditions, "[Switch] conditions") for cond in self.conditions: if not cond["to"]: raise ValueError(f"[Switch] 'To' can not be empty!") - if cond["logical_operator"] not in ["and", "or"] and len(cond["items"]) == 1: + if cond["logical_operator"] not in ["and", "or"] and len(cond["items"]) > 1: raise ValueError(f"[Switch] Please set logical_operator correctly!") class Switch(ComponentBase, ABC): component_name = "Switch" - def _run(self, **kwargs): - + def _run(self, history, **kwargs): + print(self._param.conditions) + print("len_conditions::::", len(self._param.conditions)) for cond in self._param.conditions: + if len(cond["items"]) == 1: out = self._canvas.get_component(cond["items"][0]["cpn_id"])["obj"].output()[1] cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) if self.process_operator(cpn_input, cond["items"][0]["operator"], cond["items"][0]["value"]): return Switch.be_output(cond["to"]) + continue if cond["logical_operator"] == "and": res = True for item in cond["items"]: out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1] cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) + print(str(self.process_operator(cpn_input, item["operator"], item["value"]))) if not self.process_operator(cpn_input, item["operator"], item["value"]): res = False break if res: return Switch.be_output(cond["to"]) + continue res = False for item in cond["items"]: @@ -82,17 +87,18 @@ def _run(self, **kwargs): return Switch.be_output(self._param.end_cpn_id) def process_operator(self, input: str, operator: str, value: str) -> bool: + print("input:", input, "operator:", operator, "value:", value) if not isinstance(input, str) or not isinstance(value, str): raise ValueError('Invalid input or value type: string') if operator == "contains": - return True if value in input else False + return True if value.lower() in input.lower() else False elif operator == "not contains": - return True if value not in input else False + return True if value.lower() not in input.lower() else False elif operator == "start with": - return True if input.startswith(value) else False + return True if input.lower().startswith(value.lower()) else False elif operator == "end with": - return True if input.endswith(value) else False + return True if input.lower().endswith(value.lower()) else False elif operator == "empty": return True if not input else False elif operator == "not empty": @@ -102,12 +108,24 @@ def process_operator(self, input: str, operator: str, value: str) -> bool: elif operator == "≠": return True if input != value else False elif operator == ">": - return True if input > value else False + try: + return True if float(input) > float(value) else False + except Exception as e: + return True if input > value else False elif operator == "<": - return True if input < value else False + try: + return True if float(input) < float(value) else False + except Exception as e: + return True if input < value else False elif operator == "≥": - return True if input >= value else False + try: + return True if float(input) >= float(value) else False + except Exception as e: + return True if input >= value else False elif operator == "≤": - return True if input <= value else False + try: + return True if float(input) <= float(value) else False + except Exception as e: + return True if input <= value else False raise ValueError('Not supported operator' + operator) From dcabaf3fe87940f3eaa05fcd6366425881774d6e Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:42:50 +0800 Subject: [PATCH 10/12] Update switch.py --- agent/component/switch.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/agent/component/switch.py b/agent/component/switch.py index 76a27068c08..72cfaccf241 100644 --- a/agent/component/switch.py +++ b/agent/component/switch.py @@ -50,8 +50,6 @@ class Switch(ComponentBase, ABC): component_name = "Switch" def _run(self, history, **kwargs): - print(self._param.conditions) - print("len_conditions::::", len(self._param.conditions)) for cond in self._param.conditions: if len(cond["items"]) == 1: @@ -66,7 +64,6 @@ def _run(self, history, **kwargs): for item in cond["items"]: out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1] cpn_input = "" if "content" not in out.columns else " ".join(out["content"]) - print(str(self.process_operator(cpn_input, item["operator"], item["value"]))) if not self.process_operator(cpn_input, item["operator"], item["value"]): res = False break @@ -87,7 +84,6 @@ def _run(self, history, **kwargs): return Switch.be_output(self._param.end_cpn_id) def process_operator(self, input: str, operator: str, value: str) -> bool: - print("input:", input, "operator:", operator, "value:", value) if not isinstance(input, str) or not isinstance(value, str): raise ValueError('Invalid input or value type: string') From fa4167d958fe63de4914451be98f87860619df89 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:45:40 +0800 Subject: [PATCH 11/12] Update baidu_generate_and_switch.json --- agent/test/dsl_examples/baidu_generate_and_switch.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agent/test/dsl_examples/baidu_generate_and_switch.json b/agent/test/dsl_examples/baidu_generate_and_switch.json index c52032a9d63..1c5731b8a07 100644 --- a/agent/test/dsl_examples/baidu_generate_and_switch.json +++ b/agent/test/dsl_examples/baidu_generate_and_switch.json @@ -59,8 +59,7 @@ "logical_operator" : "or", "items" : [ {"cpn_id": "generate:0", "operator": "contains", "value": "yes"}, - {"cpn_id": "generate:0", "operator": "contains", "value": "YES"}, - {"cpn_id": "generate:0", "operator": "contains", "value": "Yes"} + {"cpn_id": "generate:0", "operator": "contains", "value": "yeah"} ], "to": "message:0" }, From 0cc3ef1d65921df5c2477513d976c0c824ba3b80 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:47:07 +0800 Subject: [PATCH 12/12] Update baidu_generate_and_switch.json --- agent/test/dsl_examples/baidu_generate_and_switch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/test/dsl_examples/baidu_generate_and_switch.json b/agent/test/dsl_examples/baidu_generate_and_switch.json index 1c5731b8a07..90069cfafc0 100644 --- a/agent/test/dsl_examples/baidu_generate_and_switch.json +++ b/agent/test/dsl_examples/baidu_generate_and_switch.json @@ -68,7 +68,7 @@ "items" : [ {"cpn_id": "generate:0", "operator": "contains", "value": "no"}, {"cpn_id": "generate:0", "operator": "not contains", "value": "yes"}, - {"cpn_id": "generate:0", "operator": "not contains", "value": "know"} + {"cpn_id": "generate:0", "operator": "not contains", "value": "know"} ], "to": "message:1" },