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
35
36
37
38
39
40
41
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
const googleSearchKey = "AIzaSyAY7rS9VJVEcS6196uOWXOx2mCq_cN2kXM";
const googleCxId = "70c6ff0b41f6943a4";
const baseurl = "https://www.googleapis.com/customsearch/v1";
export const getGoogleSearch = async ({ searchKey }) => {
if (!searchKey) {
return {
prompt: "",
};
}
const postdata = {
q: searchKey,
cx: googleCxId,
key: googleSearchKey,
c2coff: 1,
start: 1,
end: 5,
dateRestrict: "m[1]",
};
const getSearch = async (data) => {
const response = await fetch("https://api.openai.com/v1/completions", {
method: "GET",
body: JSON.stringify(data),
});
const result = response.json();
const json = result.data.items.map((item) => item.snippet).join("\n");
return {
prompt:
`下文是谷歌搜索的结果,你可以提供实时信息,根据搜索结果回答问题。搜索词: ${searchKey};google 搜索结果: ${json}`,
};
};
const result = await getSearch(postdata) ?? { prompt: "" };
return Response.json({ foo: 123 });
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
lolocoo-googlesearch.express.val.run
December 15, 2023