Tavily: allow requesting images
| @@ -220,7 +220,7 @@ router.post('/tavily', jsonParser, async (request, response) => { | |||
| 220 | return response.sendStatus(400); | 220 | return response.sendStatus(400); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | const { query } = request.body; | 223 | const { query, include_images } = request.body; |
| 224 | 224 | ||
| 225 | const body = { | 225 | const body = { |
| 226 | query: query, | 226 | query: query, |
| @@ -229,7 +229,7 @@ router.post('/tavily', jsonParser, async (request, response) => { | |||
| 229 | topic: 'general', | 229 | topic: 'general', |
| 230 | include_answer: true, | 230 | include_answer: true, |
| 231 | include_raw_content: false, | 231 | include_raw_content: false, |
| 232 | include_images: false, | 232 | include_images: !!include_images, |
| 233 | include_image_descriptions: false, | 233 | include_image_descriptions: false, |
| 234 | include_domains: [], | 234 | include_domains: [], |
| 235 | max_results: 10, | 235 | max_results: 10, |
| @@ -297,6 +297,7 @@ router.post('/koboldcpp', jsonParser, async (request, response) => { | |||
| 297 | router.post('/visit', jsonParser, async (request, response) => { | 297 | router.post('/visit', jsonParser, async (request, response) => { |
| 298 | try { | 298 | try { |
| 299 | const url = request.body.url; | 299 | const url = request.body.url; |
| 300 | const html = Boolean(request.body.html ?? true); | ||
| 300 | 301 | ||
| 301 | if (!url) { | 302 | if (!url) { |
| 302 | console.log('No url provided for /visit'); | 303 | console.log('No url provided for /visit'); |
| @@ -340,13 +341,20 @@ router.post('/visit', jsonParser, async (request, response) => { | |||
| 340 | } | 341 | } |
| 341 | 342 | ||
| 342 | const contentType = String(result.headers.get('content-type')); | 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 | } catch (error) { | 358 | } catch (error) { |
| 351 | console.log(error); | 359 | console.log(error); |
| 352 | return response.sendStatus(500); | 360 | return response.sendStatus(500); |