Tavily: allow requesting images

a2a6afb73164a0275e9260c8710c3b9c6cbe13aa

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -2Showing whitespace changes
src/endpoints/search.js+10 -2
@@ -220,7 +220,7 @@ router.post('/tavily', jsonParser, async (request, response) => {
220220 return response.sendStatus(400);
221221 }
222222
223223 const { query, include_images } = request.body;
224224
225225 const body = {
226226 query: query,
@@ -229,7 +229,7 @@ router.post('/tavily', jsonParser, async (request, response) => {
229229 topic: 'general',
230230 include_answer: true,
231231 include_raw_content: false,
232232 include_images: false!!include_images,
233233 include_image_descriptions: false,
234234 include_domains: [],
235235 max_results: 10,
@@ -297,6 +297,7 @@ router.post('/koboldcpp', jsonParser, async (request, response) => {
297297router.post('/visit', jsonParser, async (request, response) => {
298298 try {
299299 const url = request.body.url;
300+ const html = Boolean(request.body.html ?? true);
300301
301302 if (!url) {
302303 console.log('No url provided for /visit');
@@ -340,6 +341,8 @@ router.post('/visit', jsonParser, async (request, response) => {
340341 }
341342
342343 const contentType = String(result.headers.get('content-type'));
344+
345+ if (html) {
343346 if (!contentType.includes('text/html')) {
344347 console.log(`Visit failed, content-type is ${contentType}, expected text/html`);
345348 return response.sendStatus(500);
@@ -347,6 +350,11 @@ router.post('/visit', jsonParser, async (request, response) => {
347350
348351 const text = await result.text();
349352 return response.send(text);
353+ }
354+
355+ response.setHeader('Content-Type', contentType);
356+ const buffer = await result.arrayBuffer();
357+ return response.send(Buffer.from(buffer));
350358 } catch (error) {
351359 console.log(error);
352360 return response.sendStatus(500);