From 60a16b4485dbd69e13ac93e4f7503b0528e86f51 Mon Sep 17 00:00:00 2001 From: Jiangween <2374131516@qq.com> Date: Tue, 31 Dec 2024 17:42:16 +0800 Subject: [PATCH 1/2] perf(plugin): improve searXNG empty result handling and documentation --- .../guide/plugins/searxng_plugin_guide.md | 16 ++ packages/plugins/src/searchXNG/template.json | 175 +++++++++++++++++- 2 files changed, 186 insertions(+), 5 deletions(-) diff --git a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md index 36e1d2c60694..48ba52f3e457 100644 --- a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md +++ b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md @@ -160,6 +160,22 @@ default_doi_resolver: 'oadoi.org' } ``` +* 搜索结果为空时会返回友好提示: + +```Bash +{ + "result": "未找到相关搜索结果,可能原因: +1. 搜索引擎未返回结果 +2. 搜索请求超时 +3. 搜索内容过于专业或生僻 + +建议: +1. 尝试使用不同的关键词 +2. 确认搜索服务是否正常 +3. 稍后重试" +} +``` + * 失败时通过 Promise.reject 可能返回错误信息: ```Bash diff --git a/packages/plugins/src/searchXNG/template.json b/packages/plugins/src/searchXNG/template.json index 639c19813433..41fc928a5787 100644 --- a/packages/plugins/src/searchXNG/template.json +++ b/packages/plugins/src/searchXNG/template.json @@ -55,7 +55,8 @@ "maxFiles": 5, "canSelectFile": true, "canSelectImg": true, - "required": true + "required": true, + "toolDescription": "部署的searXNG服务的链接" } ], "outputs": [ @@ -83,8 +84,8 @@ "flowNodeType": "pluginOutput", "showStatus": false, "position": { - "x": 1763.7518709731714, - "y": -55.56127656499825 + "x": 2552.194334325031, + "y": 26.438723435001748 }, "version": "481", "inputs": [ @@ -95,7 +96,7 @@ "key": "result", "label": "result", "description": " 检索结果", - "value": ["hjnVuJAOwyXV", "lEyy5QqyIBrK"] + "value": ["sKOiypglFFCu", "qLUQfhG0ILRX"] }, { "renderTypeList": ["reference"], @@ -369,6 +370,164 @@ "version": "4811", "inputs": [], "outputs": [] + }, + { + "nodeId": "sKOiypglFFCu", + "name": "代码运行", + "intro": "执行一段简单的脚本代码,通常用于进行复杂的数据处理。", + "avatar": "core/workflow/template/codeRun", + "flowNodeType": "code", + "showStatus": true, + "position": { + "x": 1947.3672830609507, + "y": -214.56127656499825 + }, + "version": "482", + "inputs": [ + { + "key": "system_addInputParam", + "renderTypeList": ["addInputParam"], + "valueType": "dynamic", + "label": "", + "required": false, + "description": "workflow:these_variables_will_be_input_parameters_for_code_execution", + "customInputConfig": { + "selectValueTypeList": [ + "string", + "number", + "boolean", + "object", + "arrayString", + "arrayNumber", + "arrayBoolean", + "arrayObject", + "arrayAny", + "any", + "chatHistory", + "datasetQuote", + "dynamic", + "selectApp", + "selectDataset" + ], + "showDescription": false, + "showDefaultValue": true + }, + "valueDesc": "", + "debugLabel": "", + "toolDescription": "" + }, + { + "key": "codeType", + "renderTypeList": ["hidden"], + "label": "", + "value": "js", + "valueDesc": "", + "description": "", + "debugLabel": "", + "toolDescription": "" + }, + { + "key": "code", + "renderTypeList": ["custom"], + "label": "", + "value": "function main({data1}){\n // 检查结果是否为空\n if(!data1 || !data1.results || data1.results.length === 0) {\n return {\n result: \"未找到相关搜索结果,可能原因:\\n1. 搜索引擎未返回结果\\n2. 搜索请求超时\\n3. 搜索内容过于专业或生僻\\n\\n建议:\\n1. 尝试使用不同的关键词\\n2. 确认搜索服务是否正常\\n3. 稍后重试\"\n }\n }\n \n // 返回正常结果\n return {\n result: data1\n }\n}", + "valueDesc": "", + "description": "", + "debugLabel": "", + "toolDescription": "" + }, + { + "renderTypeList": ["reference"], + "valueType": "string", + "canEdit": true, + "key": "data1", + "label": "data1", + "customInputConfig": { + "selectValueTypeList": [ + "string", + "number", + "boolean", + "object", + "arrayString", + "arrayNumber", + "arrayBoolean", + "arrayObject", + "arrayAny", + "any", + "chatHistory", + "datasetQuote", + "dynamic", + "selectApp", + "selectDataset" + ], + "showDescription": false, + "showDefaultValue": true + }, + "required": true, + "value": ["hjnVuJAOwyXV", "lEyy5QqyIBrK"], + "valueDesc": "", + "description": "", + "debugLabel": "", + "toolDescription": "" + } + ], + "outputs": [ + { + "id": "system_rawResponse", + "key": "system_rawResponse", + "label": "workflow:full_response_data", + "valueType": "object", + "type": "static", + "description": "" + }, + { + "id": "error", + "key": "error", + "label": "workflow:execution_error", + "description": "代码运行错误信息,成功时返回空", + "valueType": "object", + "type": "static" + }, + { + "id": "system_addOutputParam", + "key": "system_addOutputParam", + "type": "dynamic", + "valueType": "dynamic", + "label": "", + "customFieldConfig": { + "selectValueTypeList": [ + "string", + "number", + "boolean", + "object", + "arrayString", + "arrayNumber", + "arrayBoolean", + "arrayObject", + "arrayAny", + "any", + "chatHistory", + "datasetQuote", + "dynamic", + "selectApp", + "selectDataset" + ], + "showDescription": false, + "showDefaultValue": false + }, + "description": "将代码中 return 的对象作为输出,传递给后续的节点。变量名需要对应 return 的 key", + "valueDesc": "" + }, + { + "id": "qLUQfhG0ILRX", + "type": "dynamic", + "key": "result", + "valueType": "string", + "label": "result", + "valueDesc": "", + "description": "" + } + ] } ], "edges": [ @@ -380,8 +539,14 @@ }, { "source": "hjnVuJAOwyXV", - "target": "pluginOutput", + "target": "sKOiypglFFCu", "sourceHandle": "hjnVuJAOwyXV-source-right", + "targetHandle": "sKOiypglFFCu-target-left" + }, + { + "source": "sKOiypglFFCu", + "target": "pluginOutput", + "sourceHandle": "sKOiypglFFCu-source-right", "targetHandle": "pluginOutput-target-left" } ], From 35ac63edf8d53b06fdc6d87ce7f5fba3b3a0f574 Mon Sep 17 00:00:00 2001 From: Jiangween <2374131516@qq.com> Date: Thu, 2 Jan 2025 15:44:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=92=8C=E4=BB=A3=E7=A0=81=E9=83=A8=E5=88=86=E6=97=A0?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=9A=84=E7=BB=93=E6=9E=9C=E7=9A=84=E5=8F=8D?= =?UTF-8?q?=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guide/plugins/searxng_plugin_guide.md | 14 +- packages/plugins/src/searchXNG/index.ts | 10 + packages/plugins/src/searchXNG/template.json | 175 +----------------- 3 files changed, 20 insertions(+), 179 deletions(-) diff --git a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md index 48ba52f3e457..6652d7ff1458 100644 --- a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md +++ b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md @@ -164,15 +164,11 @@ default_doi_resolver: 'oadoi.org' ```Bash { - "result": "未找到相关搜索结果,可能原因: -1. 搜索引擎未返回结果 -2. 搜索请求超时 -3. 搜索内容过于专业或生僻 - -建议: -1. 尝试使用不同的关键词 -2. 确认搜索服务是否正常 -3. 稍后重试" + "result": "[]", + "error": { + "message": "No search results", + "code": 500 + } } ``` diff --git a/packages/plugins/src/searchXNG/index.ts b/packages/plugins/src/searchXNG/index.ts index c325f64a1b7b..eebe87adc7f4 100644 --- a/packages/plugins/src/searchXNG/index.ts +++ b/packages/plugins/src/searchXNG/index.ts @@ -48,6 +48,16 @@ const main = async (props: Props, retry = 3): Response => { }); }); + if (results.length === 0) { + return { + result: JSON.stringify([]), + error: { + message: 'No search results', + code: 500 + } + }; + } + return { result: JSON.stringify(results.slice(0, 10)) }; diff --git a/packages/plugins/src/searchXNG/template.json b/packages/plugins/src/searchXNG/template.json index 41fc928a5787..639c19813433 100644 --- a/packages/plugins/src/searchXNG/template.json +++ b/packages/plugins/src/searchXNG/template.json @@ -55,8 +55,7 @@ "maxFiles": 5, "canSelectFile": true, "canSelectImg": true, - "required": true, - "toolDescription": "部署的searXNG服务的链接" + "required": true } ], "outputs": [ @@ -84,8 +83,8 @@ "flowNodeType": "pluginOutput", "showStatus": false, "position": { - "x": 2552.194334325031, - "y": 26.438723435001748 + "x": 1763.7518709731714, + "y": -55.56127656499825 }, "version": "481", "inputs": [ @@ -96,7 +95,7 @@ "key": "result", "label": "result", "description": " 检索结果", - "value": ["sKOiypglFFCu", "qLUQfhG0ILRX"] + "value": ["hjnVuJAOwyXV", "lEyy5QqyIBrK"] }, { "renderTypeList": ["reference"], @@ -370,164 +369,6 @@ "version": "4811", "inputs": [], "outputs": [] - }, - { - "nodeId": "sKOiypglFFCu", - "name": "代码运行", - "intro": "执行一段简单的脚本代码,通常用于进行复杂的数据处理。", - "avatar": "core/workflow/template/codeRun", - "flowNodeType": "code", - "showStatus": true, - "position": { - "x": 1947.3672830609507, - "y": -214.56127656499825 - }, - "version": "482", - "inputs": [ - { - "key": "system_addInputParam", - "renderTypeList": ["addInputParam"], - "valueType": "dynamic", - "label": "", - "required": false, - "description": "workflow:these_variables_will_be_input_parameters_for_code_execution", - "customInputConfig": { - "selectValueTypeList": [ - "string", - "number", - "boolean", - "object", - "arrayString", - "arrayNumber", - "arrayBoolean", - "arrayObject", - "arrayAny", - "any", - "chatHistory", - "datasetQuote", - "dynamic", - "selectApp", - "selectDataset" - ], - "showDescription": false, - "showDefaultValue": true - }, - "valueDesc": "", - "debugLabel": "", - "toolDescription": "" - }, - { - "key": "codeType", - "renderTypeList": ["hidden"], - "label": "", - "value": "js", - "valueDesc": "", - "description": "", - "debugLabel": "", - "toolDescription": "" - }, - { - "key": "code", - "renderTypeList": ["custom"], - "label": "", - "value": "function main({data1}){\n // 检查结果是否为空\n if(!data1 || !data1.results || data1.results.length === 0) {\n return {\n result: \"未找到相关搜索结果,可能原因:\\n1. 搜索引擎未返回结果\\n2. 搜索请求超时\\n3. 搜索内容过于专业或生僻\\n\\n建议:\\n1. 尝试使用不同的关键词\\n2. 确认搜索服务是否正常\\n3. 稍后重试\"\n }\n }\n \n // 返回正常结果\n return {\n result: data1\n }\n}", - "valueDesc": "", - "description": "", - "debugLabel": "", - "toolDescription": "" - }, - { - "renderTypeList": ["reference"], - "valueType": "string", - "canEdit": true, - "key": "data1", - "label": "data1", - "customInputConfig": { - "selectValueTypeList": [ - "string", - "number", - "boolean", - "object", - "arrayString", - "arrayNumber", - "arrayBoolean", - "arrayObject", - "arrayAny", - "any", - "chatHistory", - "datasetQuote", - "dynamic", - "selectApp", - "selectDataset" - ], - "showDescription": false, - "showDefaultValue": true - }, - "required": true, - "value": ["hjnVuJAOwyXV", "lEyy5QqyIBrK"], - "valueDesc": "", - "description": "", - "debugLabel": "", - "toolDescription": "" - } - ], - "outputs": [ - { - "id": "system_rawResponse", - "key": "system_rawResponse", - "label": "workflow:full_response_data", - "valueType": "object", - "type": "static", - "description": "" - }, - { - "id": "error", - "key": "error", - "label": "workflow:execution_error", - "description": "代码运行错误信息,成功时返回空", - "valueType": "object", - "type": "static" - }, - { - "id": "system_addOutputParam", - "key": "system_addOutputParam", - "type": "dynamic", - "valueType": "dynamic", - "label": "", - "customFieldConfig": { - "selectValueTypeList": [ - "string", - "number", - "boolean", - "object", - "arrayString", - "arrayNumber", - "arrayBoolean", - "arrayObject", - "arrayAny", - "any", - "chatHistory", - "datasetQuote", - "dynamic", - "selectApp", - "selectDataset" - ], - "showDescription": false, - "showDefaultValue": false - }, - "description": "将代码中 return 的对象作为输出,传递给后续的节点。变量名需要对应 return 的 key", - "valueDesc": "" - }, - { - "id": "qLUQfhG0ILRX", - "type": "dynamic", - "key": "result", - "valueType": "string", - "label": "result", - "valueDesc": "", - "description": "" - } - ] } ], "edges": [ @@ -539,14 +380,8 @@ }, { "source": "hjnVuJAOwyXV", - "target": "sKOiypglFFCu", - "sourceHandle": "hjnVuJAOwyXV-source-right", - "targetHandle": "sKOiypglFFCu-target-left" - }, - { - "source": "sKOiypglFFCu", "target": "pluginOutput", - "sourceHandle": "sKOiypglFFCu-source-right", + "sourceHandle": "hjnVuJAOwyXV-source-right", "targetHandle": "pluginOutput-target-left" } ],