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;
|
||||
|
||||
const userMessage = messages[messages.length - 1];
|
||||
const query = encodeURIComponent(userMessage.content.trim());
|
||||
|
||||
const googleRes = await fetch(
|
||||
`https://customsearch.googleapis.com/customsearch/v1?key=${
|
||||
googleAPIKey ? googleAPIKey : process.env.GOOGLE_API_KEY
|
||||
}&cx=${
|
||||
googleCSEId ? googleCSEId : process.env.GOOGLE_CSE_ID
|
||||
}&q=${userMessage.content.trim()}&num=5`,
|
||||
}&q=${query}&num=5`,
|
||||
);
|
||||
|
||||
const googleData = await googleRes.json();
|
||||
|
@ -140,7 +141,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse<any>) => {
|
|||
|
||||
res.status(200).json({ answer });
|
||||
} catch (error) {
|
||||
return new Response('Error', { status: 500 });
|
||||
console.error(error);
|
||||
res.status(500).json({ error: 'Error'})
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue