From 11de7599e5dd90a730870f06e427f2e5fd9fabe8 Mon Sep 17 00:00:00 2001 From: so95 Date: Thu, 27 Feb 2025 15:15:33 +0700 Subject: [PATCH] Feat: add data type invoke (#5126) ### What problem does this PR solve? ``` Invoke agent To be able to interact dynamically with the API, there is a customizable Data Type JSON or FormData, the default is JSON ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Kevin Hu --- agent/component/exesql.py | 2 -- agent/component/invoke.py | 36 +++++++++++++------ web/src/locales/en.ts | 4 ++- web/src/pages/flow/constant.tsx | 1 + web/src/pages/flow/form/invoke-form/index.tsx | 9 +++++ 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/agent/component/exesql.py b/agent/component/exesql.py index ea04947e..d61239d4 100644 --- a/agent/component/exesql.py +++ b/agent/component/exesql.py @@ -79,7 +79,6 @@ class ExeSQL(Generate, ABC): ans = self.get_input() ans = "".join([str(a) for a in ans["content"]]) if "content" in ans else "" ans = self._refactor(ans) - logging.info("db_type: ", self._param.db_type) if self._param.db_type in ["mysql", "mariadb"]: db = pymysql.connect(db=self._param.database, user=self._param.username, host=self._param.host, port=self._param.port, password=self._param.password) @@ -128,7 +127,6 @@ class ExeSQL(Generate, ABC): single_sql = self._refactor(single_sql) if self._loop > self._param.loop: sql_res.append({"content": "Can't query the correct data via SQL statement."}) - # raise Exception("Maximum loop time exceeds. Can't query the correct data via SQL statement.") db.close() if not sql_res: return ExeSQL.be_output("") diff --git a/agent/component/invoke.py b/agent/component/invoke.py index 22a279ce..c2bd58bd 100644 --- a/agent/component/invoke.py +++ b/agent/component/invoke.py @@ -35,12 +35,14 @@ class InvokeParam(ComponentParamBase): self.url = "" self.timeout = 60 self.clean_html = False + self.datatype = "json" # New parameter to determine data posting type def check(self): self.check_valid_value(self.method.lower(), "Type of content from the crawler", ['get', 'post', 'put']) self.check_empty(self.url, "End point URL") self.check_positive_integer(self.timeout, "Timeout time in second") self.check_boolean(self.clean_html, "Clean HTML") + self.check_valid_value(self.datatype.lower(), "Data post type", ['json', 'formdata']) # Check for valid datapost value class Invoke(ComponentBase, ABC): @@ -94,22 +96,36 @@ class Invoke(ComponentBase, ABC): return Invoke.be_output(response.text) if method == 'put': - response = requests.put(url=url, - json=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) + if self._param.datatype.lower() == 'json': + response = requests.put(url=url, + json=args, + headers=headers, + proxies=proxies, + timeout=self._param.timeout) + else: + response = requests.put(url=url, + data=args, + headers=headers, + proxies=proxies, + timeout=self._param.timeout) if self._param.clean_html: sections = HtmlParser()(None, response.content) return Invoke.be_output("\n".join(sections)) return Invoke.be_output(response.text) if method == 'post': - response = requests.post(url=url, - json=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) + if self._param.datatype.lower() == 'json': + response = requests.post(url=url, + json=args, + headers=headers, + proxies=proxies, + timeout=self._param.timeout) + else: + response = requests.post(url=url, + data=args, + headers=headers, + proxies=proxies, + timeout=self._param.timeout) if self._param.clean_html: sections = HtmlParser()(None, response.content) return Invoke.be_output("\n".join(sections)) diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index af0e31b5..27fc7c0b 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -528,6 +528,7 @@ This auto-tag feature enhances retrieval by adding another layer of domain-speci 'Allows sentence rewriting with the specified language or defaults to the latest question if not selected.', avatarHidden: 'Hide avatar', locale: 'Locale', + selectLanguage: 'Select a language', reasoning: 'Reasoning', reasoningTip: 'It will trigger reasoning process like Deepseek-R1/OpenAI o1. Integrates an agentic search process into the reasoning workflow, allowing models itself to dynamically retrieve external knowledge whenever they encounter uncertain information.', @@ -845,7 +846,7 @@ This auto-tag feature enhances retrieval by adding another layer of domain-speci bingDescription: 'A component that searches from https://www.bing.com/, allowing you to specify the number of search results using TopN. It supplements the existing knowledge bases. Please note that this requires an API key from microsoft.com.', apiKey: 'API KEY', - country: 'Country&Region', + country: 'Country & Region', language: 'Language', googleScholar: 'Google Scholar', googleScholarDescription: @@ -1187,6 +1188,7 @@ This delimiter is used to split the input text into several text pieces echo of addCategory: 'Add category', categoryName: 'Category name', nextStep: 'Next step', + datatype: 'MINE type of the HTTP request', insertVariableTip: `Enter / Insert variables`, }, footer: { diff --git a/web/src/pages/flow/constant.tsx b/web/src/pages/flow/constant.tsx index 132f8ff7..5a8df53f 100644 --- a/web/src/pages/flow/constant.tsx +++ b/web/src/pages/flow/constant.tsx @@ -606,6 +606,7 @@ export const initialInvokeValues = { }`, proxy: 'http://', clean_html: false, + datatype: 'json', }; export const initialTemplateValues = { diff --git a/web/src/pages/flow/form/invoke-form/index.tsx b/web/src/pages/flow/form/invoke-form/index.tsx index 521f1c95..a62723eb 100644 --- a/web/src/pages/flow/form/invoke-form/index.tsx +++ b/web/src/pages/flow/form/invoke-form/index.tsx @@ -69,6 +69,15 @@ const InvokeForm = ({ onValuesChange, form, node }: IOperatorForm) => { > + + +