Tavily: allow requesting images
| @@ -220,7 +220,7 @@ router.post('/tavily', jsonParser, async (request, response) => { | ||
| 220 | 220 | return response.sendStatus(400); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | const { query, include_images } = request.body; |
| 224 | 224 | |
| 225 | 225 | const body = { |
| 226 | 226 | query: query, |
| @@ -229,7 +229,7 @@ router.post('/tavily', jsonParser, async (request, response) => { | ||
| 229 | 229 | topic: 'general', |
| 230 | 230 | include_answer: true, |
| 231 | 231 | include_raw_content: false, |
| 232 | 232 | include_images: false!!include_images, |
| 233 | 233 | include_image_descriptions: false, |
| 234 | 234 | include_domains: [], |
| 235 | 235 | max_results: 10, |
| @@ -297,6 +297,7 @@ router.post('/koboldcpp', jsonParser, async (request, response) => { | ||
| 297 | 297 | router.post('/visit', jsonParser, async (request, response) => { |
| 298 | 298 | try { |
| 299 | 299 | const url = request.body.url; |
| 300 | + const html = Boolean(request.body.html ?? true); | |
| 300 | 301 | |
| 301 | 302 | if (!url) { |
| 302 | 303 | console.log('No url provided for /visit'); |
| @@ -340,13 +341,20 @@ router.post('/visit', jsonParser, async (request, response) => { | ||
| 340 | 341 | } |
| 341 | 342 | |
| 342 | 343 | const contentType = String(result.headers.get('content-type')); |
| 343 | - if (!contentType.includes('text/html')) { | |
| 344 | + | |
| 344 | - console.log(`Visit failed, content-type is ${contentType}, expected text/html`); | |
| 345 | + if (html) { | |
| 345 | - return response.sendStatus(500); | |
| 346 | + if (!contentType.includes('text/html')) { | |
| 347 | + console.log(`Visit failed, content-type is ${contentType}, expected text/html`); | |
| 348 | + return response.sendStatus(500); | |
| 349 | + } | |
| 350 | + | |
| 351 | + const text = await result.text(); | |
| 352 | + return response.send(text); | |
| 346 | 353 | } |
| 347 | 354 | |
| 348 | - const text = await result.text(); | |
| 355 | + response.setHeader('Content-Type', contentType); | |
| 349 | - return response.send(text); | |
| 356 | + const buffer = await result.arrayBuffer(); | |
| 357 | + return response.send(Buffer.from(buffer)); | |
| 350 | 358 | } catch (error) { |
| 351 | 359 | console.log(error); |
| 352 | 360 | return response.sendStatus(500); |