Commit daa5b552 by papapatrick Committed by GitHub

plugins: add wiki search (#2886)

* plugins: add wiki search

* 扁平化代码

* fix: url error
parent fe6c8897
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"duck-duck-scrape": "^2.2.5",
"lodash": "^4.17.21",
"axios": "^1.5.1", "axios": "^1.5.1",
"duck-duck-scrape": "^2.2.5",
"echarts": "5.4.1",
"expr-eval": "^2.0.2", "expr-eval": "^2.0.2",
"echarts": "5.4.1" "lodash": "^4.17.21",
"wikijs": "^6.4.1"
}, },
"devDependencies": { "devDependencies": {
"@fastgpt/global": "workspace:*", "@fastgpt/global": "workspace:*",
......
...@@ -24,7 +24,8 @@ const packagePluginList = [ ...@@ -24,7 +24,8 @@ const packagePluginList = [
'duckduckgo/searchNews', 'duckduckgo/searchNews',
'duckduckgo/searchVideo', 'duckduckgo/searchVideo',
'drawing', 'drawing',
'drawing/baseChart' 'drawing/baseChart',
'wiki'
]; ];
export const list = [...staticPluginList, ...packagePluginList]; export const list = [...staticPluginList, ...packagePluginList];
......
import { getErrText } from '@fastgpt/global/common/error/utils';
import { addLog } from '@fastgpt/service/common/system/log';
import { delay } from '@fastgpt/global/common/system/utils';
import wiki from 'wikijs';
type Props = {
query: string;
};
// Response type same as HTTP outputs
type Response = Promise<{
result: string;
}>;
const main = async (props: Props, retry = 3): Response => {
const { query } = props;
try {
const searchResults = await wiki({ apiUrl: 'https://zh.wikipedia.org/w/api.php' })
.page(query)
.then((page) => {
return page.summary();
});
return {
result: searchResults
};
} catch (error) {
console.log(error);
if (retry <= 0) {
addLog.warn('search wiki error', { error });
return {
result: getErrText(error, 'Failed to fetch data from wiki')
};
}
await delay(Math.random() * 5000);
return main(props, retry - 1);
}
};
export default main;
...@@ -228,6 +228,7 @@ export const iconPaths = { ...@@ -228,6 +228,7 @@ export const iconPaths = {
import('./icons/core/workflow/template/duckduckgo.svg'), import('./icons/core/workflow/template/duckduckgo.svg'),
'core/workflow/template/extractJson': () => 'core/workflow/template/extractJson': () =>
import('./icons/core/workflow/template/extractJson.svg'), import('./icons/core/workflow/template/extractJson.svg'),
'core/workflow/template/wiki': () => import('./icons/core/workflow/template/wiki.svg'),
'core/workflow/template/fetchUrl': () => import('./icons/core/workflow/template/fetchUrl.svg'), 'core/workflow/template/fetchUrl': () => import('./icons/core/workflow/template/fetchUrl.svg'),
'core/workflow/template/formInput': () => import('./icons/core/workflow/template/formInput.svg'), 'core/workflow/template/formInput': () => import('./icons/core/workflow/template/formInput.svg'),
'core/workflow/template/getTime': () => import('./icons/core/workflow/template/getTime.svg'), 'core/workflow/template/getTime': () => import('./icons/core/workflow/template/getTime.svg'),
......
<svg t="1728613783770" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4250" width="200" height="200"><path d="M530.077727 610.234325c-49.762357 97.384981-104.639199 199.047382-151.85864 295.595298-0.433882 0.433882-22.974247 0-22.974247-0.433882-71.867818-168.012551-147.146315-334.722434-219.044832-503.168868C118.774127 361.393887 60.486606 295.04476 20.521383 295.478641c0-4.681626-0.433882-15.315824-0.433882-21.703301l247.972675 0 0 21.269419c-29.360701 1.704828-80.827887 20.400632-66.349127 52.30425 33.608445 76.146261 158.6493 367.927697 192.257745 441.935248 22.974247-45.514613 88.455611-167.143765 115.27442-218.61095-21.269419-43.405579-89.757257-205.031677-111.460558-244.995877-14.881942-27.221991-55.281047-29.795607-85.478813-30.197766 0-6.821359 0-12.340049 0-21.269419l218.177068 0.403183 0 19.99745c-29.763884 0.867764-58.256822 11.905144-45.079708 39.995923 28.92682 61.23362 46.785559 104.205317 73.604368 160.354128 8.495488-16.587793 53.141314-106.34505 73.573669-154.401556 13.610996-31.469736-5.952572-43.808762-59.125609-45.080731 0.433882-5.54939 0-15.749706 0.433882-20.866237 68.053955-0.403183 170.120562-0.403183 188.413184-0.837064l0 20.834514c-34.44551 1.270946-70.162989 19.563568-88.889493 48.490388l-90.594321 188.010001c9.766434 24.679076 96.981798 218.61095 105.910145 239.880369l187.576119-432.571996c-13.177114-35.282574-55.714929-42.940998-72.301699-43.37488 0-5.51869 0-14.044878 0-21.269419l195.636702 1.704828 0.433882 0.837064-0.433882 18.726503c-42.940998 1.270946-68.892043 24.245194-85.478813 61.667501-38.290071 88.48631-158.246117 367.493815-237.772358 549.117362l-20.834514 0L530.077727 610.234325z" fill="#3E3A39" p-id="4251"></path></svg>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment