File tree Expand file tree Collapse file tree 7 files changed +632
-70
lines changed
web/components/common/Icon
icons/core/workflow/template Expand file tree Collapse file tree 7 files changed +632
-70
lines changed Original file line number Diff line number Diff line change 3
3
"version" : " 1.0.0" ,
4
4
"type" : " module" ,
5
5
"dependencies" : {
6
- "duck-duck-scrape" : " ^2.2.5" ,
7
- "lodash" : " ^4.17.21" ,
8
6
"axios" : " ^1.5.1" ,
7
+ "duck-duck-scrape" : " ^2.2.5" ,
8
+ "echarts" : " 5.4.1" ,
9
9
"expr-eval" : " ^2.0.2" ,
10
- "echarts" : " 5.4.1"
10
+ "lodash" : " ^4.17.21" ,
11
+ "wikijs" : " ^6.4.1"
11
12
},
12
13
"devDependencies" : {
13
14
"@fastgpt/global" : " workspace:*" ,
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ const packagePluginList = [
24
24
'duckduckgo/searchNews' ,
25
25
'duckduckgo/searchVideo' ,
26
26
'drawing' ,
27
- 'drawing/baseChart'
27
+ 'drawing/baseChart' ,
28
+ 'wiki'
28
29
] ;
29
30
30
31
export const list = [ ...staticPluginList , ...packagePluginList ] ;
Original file line number Diff line number Diff line change
1
+ import { getErrText } from '@fastgpt/global/common/error/utils' ;
2
+ import { addLog } from '@fastgpt/service/common/system/log' ;
3
+ import { delay } from '@fastgpt/global/common/system/utils' ;
4
+ import wiki from 'wikijs' ;
5
+
6
+ type Props = {
7
+ query : string ;
8
+ } ;
9
+
10
+ // Response type same as HTTP outputs
11
+ type Response = Promise < {
12
+ result : string ;
13
+ } > ;
14
+
15
+ const main = async ( props : Props , retry = 3 ) : Response => {
16
+ const { query } = props ;
17
+
18
+ try {
19
+ const searchResults = await wiki ( { apiUrl : 'https://zh.wikipedia.org/w/api.php' } )
20
+ . page ( query )
21
+ . then ( ( page ) => {
22
+ return page . summary ( ) ;
23
+ } ) ;
24
+
25
+ return {
26
+ result : searchResults
27
+ } ;
28
+ } catch ( error ) {
29
+ console . log ( error ) ;
30
+
31
+ if ( retry <= 0 ) {
32
+ addLog . warn ( 'search wiki error' , { error } ) ;
33
+ return {
34
+ result : getErrText ( error , 'Failed to fetch data from wiki' )
35
+ } ;
36
+ }
37
+
38
+ await delay ( Math . random ( ) * 5000 ) ;
39
+ return main ( props , retry - 1 ) ;
40
+ }
41
+ } ;
42
+
43
+ export default main ;
You can’t perform that action at this time.
0 commit comments