Skip to content

Commit 4a2d4a8

Browse files
committed
add summarizer
1 parent f250596 commit 4a2d4a8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

server/services/utils.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,14 @@ export async function braveSearch(opts, apiKey = process.env.BRAVE_SEARCH_API_KE
383383
delete opts[key];
384384
}
385385
}
386+
Object.assign(opts, {
387+
summary: true,
388+
extra_snippets: true,
389+
});
386390
const url = `https://api.search.brave.com/res/v1/web/search?${new URLSearchParams(opts)}`;
387391
const response = await fetch(url, {
388392
headers: {
389393
"Accept": "application/json",
390-
"Accept-Encoding": "gzip",
391394
"X-Subscription-Token": apiKey,
392395
},
393396
});
@@ -396,7 +399,22 @@ export async function braveSearch(opts, apiKey = process.env.BRAVE_SEARCH_API_KE
396399
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
397400
}
398401

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;
400418
}
401419

402420
/**

0 commit comments

Comments
 (0)