Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const googleSearchKey = "AIzaSyAY7rS9VJVEcS6196uOWXOx2mCq_cN2kXM";
const googleCxId = "70c6ff0b41f6943a4";
const baseurl = "https://www.googleapis.com/customsearch/v1";
export default async function(req: Request): Promise<Response> {
const { searchKey } = await req.json();
if (!searchKey) {
return Response.json({
prompt: "",
});
}
try {
const data = await fetch(
`https://www.googleapis.com/customsearch/v1?q=${searchKey}&cx=70c6ff0b41f6943a4&key=AIzaSyAY7rS9VJVEcS6196uOWXOx2mCq_cN2kXM&c2coff=1&start=1&num=5&dateRestrict=m%5B1%5D`,
)
.then(response => response.json())
.then(response => response)
.catch(err => err);
const result = data.items.map((item) => item.snippet).join("\n");
return Response.json({
prompt:
`下文是谷歌搜索的结果,你可以提供实时信息,根据搜索结果回答问题。搜索词: ${searchKey};google 搜索结果: ${result}`,
});
} catch (err) {
console.log(err, searchKey);
return Response.json({
prompt: "",
searchKey,
});
}
}
lolocoo-untitled_sapphireslug.web.val.run
December 15, 2023