File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -383,11 +383,14 @@ export async function braveSearch(opts, apiKey = process.env.BRAVE_SEARCH_API_KE
383
383
delete opts [ key ] ;
384
384
}
385
385
}
386
+ Object . assign ( opts , {
387
+ summary : true ,
388
+ extra_snippets : true ,
389
+ } ) ;
386
390
const url = `https://api.search.brave.com/res/v1/web/search?${ new URLSearchParams ( opts ) } ` ;
387
391
const response = await fetch ( url , {
388
392
headers : {
389
393
"Accept" : "application/json" ,
390
- "Accept-Encoding" : "gzip" ,
391
394
"X-Subscription-Token" : apiKey ,
392
395
} ,
393
396
} ) ;
@@ -396,7 +399,22 @@ export async function braveSearch(opts, apiKey = process.env.BRAVE_SEARCH_API_KE
396
399
throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` ) ;
397
400
}
398
401
399
- return await response . json ( ) ;
402
+ const data = await response . json ( ) ;
403
+ if ( data . summarizer ) {
404
+ const opts = {
405
+ key : data . summarizer . key ,
406
+ } ;
407
+ const summarizerResponse = await fetch ( `https://api.search.brave.com/res/v1/summarizer/search?${ new URLSearchParams ( opts ) } ` , {
408
+ headers : {
409
+ "Accept" : "application/json" ,
410
+ "X-Subscription-Token" : apiKey ,
411
+ } ,
412
+ } ) ;
413
+ const summarizerData = await summarizerResponse . json ( ) ;
414
+ data . summary = summarizerData ;
415
+ }
416
+
417
+ return data ;
400
418
}
401
419
402
420
/**
You can’t perform that action at this time.
0 commit comments