fix google plugin bug due to URI encoding issue. (#469)
* fix: uri encoding * fix: error handling
This commit is contained in:
		
							parent
							
								
									25958a9548
								
							
						
					
					
						commit
						ac69b7a887
					
				|  | @ -16,13 +16,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse<any>) => { | ||||||
|       req.body as GoogleBody; |       req.body as GoogleBody; | ||||||
| 
 | 
 | ||||||
|     const userMessage = messages[messages.length - 1]; |     const userMessage = messages[messages.length - 1]; | ||||||
|  |     const query = encodeURIComponent(userMessage.content.trim()); | ||||||
| 
 | 
 | ||||||
|     const googleRes = await fetch( |     const googleRes = await fetch( | ||||||
|       `https://customsearch.googleapis.com/customsearch/v1?key=${ |       `https://customsearch.googleapis.com/customsearch/v1?key=${ | ||||||
|         googleAPIKey ? googleAPIKey : process.env.GOOGLE_API_KEY |         googleAPIKey ? googleAPIKey : process.env.GOOGLE_API_KEY | ||||||
|       }&cx=${ |       }&cx=${ | ||||||
|         googleCSEId ? googleCSEId : process.env.GOOGLE_CSE_ID |         googleCSEId ? googleCSEId : process.env.GOOGLE_CSE_ID | ||||||
|       }&q=${userMessage.content.trim()}&num=5`,
 |       }&q=${query}&num=5`,
 | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     const googleData = await googleRes.json(); |     const googleData = await googleRes.json(); | ||||||
|  | @ -140,7 +141,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse<any>) => { | ||||||
| 
 | 
 | ||||||
|     res.status(200).json({ answer }); |     res.status(200).json({ answer }); | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|     return new Response('Error', { status: 500 }); |     console.error(error); | ||||||
|  |     res.status(500).json({ error: 'Error'}) | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue