使用google api返回json格式的搜索结果笔记
现在ai大模型的发展很快,简直就是一个超级大脑,无所不知,但是由于ai训练的数据不是最新的,有时候无法回答你的问题,那么如果将ai接入搜索引擎,获取最新的搜索信息,然后加以总结给用户就很厉害了,这个时候就需要调用搜索引擎api接口了。
google自定义搜索提供了这样的一个api,每天可免费100次调用,超过是要交钱的,下面我记录一下申请调用流程:
1、创建自定义搜索引擎,地址:https://programmablesearchengine.google.com/controlpanel/create,
并记录下cx参数
2、申请api,地址:https://console.cloud.google.com/apis/credentials
3、最后就可以把上面申请的key和cx拼接到下面的url中访问谷歌自定义搜索api,google返回一个json格式化的数据。
https://www.googleapis.com/customsearch/v1?key=你申请的apikey&cx=创建的自定义搜索&q=关键字
返回json数据如下:
{ "kind": "customsearch#search", "url": { "type": "application/json", "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json" }, "queries": { "request": [ { "title": "Google Custom Search - openai新模型", "totalResults": "14100000", "searchTerms": "openai新模型", "count": 10, "startIndex": 1, "inputEncoding": "utf8", "outputEncoding": "utf8", "safe": "off", "cx": "自己的cx" } ], "nextPage": [ { "title": "Google Custom Search - openai新模型", "totalResults": "14100000", "searchTerms": "openai新模型", "count": 10, "startIndex": 11, "inputEncoding": "utf8", "outputEncoding": "utf8", "safe": "off", "cx": "自己的cx" } ] }, "context": { "title": "it" }, "searchInformation": { "searchTime": 0.444258, "formattedSearchTime": "0.44", "totalResults": "14100000", "formattedTotalResults": "14,100,000" }, "items": [ { "kind": "customsearch#result", "title": "终结扩散模型:OpenAI开源新模型代码,一步成图,1秒18张-36氪", "htmlTitle": "终结扩散\u003cb\u003e模型\u003c/b\u003e:\u003cb\u003eOpenAI\u003c/b\u003e开源\u003cb\u003e新模型\u003c/b\u003e代码,一步成图,1秒18张-36氪", "link": "https://m.36kr.com/p/2213338104164993", "displayLink": "m.36kr.com", "snippet": "Apr 13, 2023 ... 首先Consistency Models 建立在连续时间扩散模型中的概率流(PF) 常微分方程(ODE) 之上。如下图1 所示,给定一个将数据平滑地转换为噪声的PF ODE, ...", "htmlSnippet": "Apr 13, 2023 \u003cb\u003e...\u003c/b\u003e 首先Consistency Models 建立在连续时间扩散\u003cb\u003e模型\u003c/b\u003e中的概率流(PF) 常微分方程(ODE) 之上。如下图1 所示,给定一个将数据平滑地转换为噪声的PF ODE,?...", "formattedUrl": "https://m.36kr.com/p/2213338104164993", "htmlFormattedUrl": "https://m.36kr.com/p/2213338104164993", "pagemap": { "cse_thumbnail": [ { "src": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQxdHQ7qEoZaU7pB_38rlVd8sUr2ric5C1tb9hh3T-dDN98AbunpoMB-4_p&s", "width": "275", "height": "183" } ], "metatags": [ { "og:image": "https://img.36krcdn.com/hsossms/20230413/v2_0312915cf84149ac9adc5eba05638939@5335358_oswg427025oswg600oswg400_img_png", "og:type": "article", "renderer": "webkit", "article:published_time": "2023-04-12 23:09:46", "handheldfriendly": "True", "author": "机器之心", "apple-mobile-web-app-title": "Title", "og:title": "终结扩散模型:OpenAI开源新模型代码,一步成图,1秒18张-36氪", "applicable-device": "mobile", "shenma-site-verification": "8d43b014716644e38cc8fff2051c47a0_1622786801", "og:description": "扩散模型的时代结束了。", "360-site-verification": "b14201a8708468357bd6fab4ad556b78", "baidu-site-verification": "ET7tYDCqIv", "apple-mobile-web-app-status-bar-style": "black", "viewport": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover", "sogou_site_verification": "5ZZdpkOf3U", "popintimestamp": "1681366186194", "apple-mobile-web-app-capable": "yes", "mobileoptimized": "320", "og:url": "https://m.36kr.com/p/2213338104164993", "format-detection": "telephone=no" } ], "cse_image": [ { "src": "https://img.36krcdn.com/hsossms/20230413/v2_0312915cf84149ac9adc5eba05638939@5335358_oswg427025oswg600oswg400_img_png" } ] } }, { "kind": "customsearch#result", "title": "新一代AI强势出炉!OpenAI推出新模型GPT-4o,能进行实时口语对话 ...", "htmlTitle": "新一代AI强势出炉!\u003cb\u003eOpenAI\u003c/b\u003e推出\u003cb\u003e新模型\u003c/b\u003eGPT-4o,能进行实时口语对话 ...", "link": "https://www.guruin.com/news/75570", "displayLink": "www.guruin.com", "snippet": "咕噜美国通(Guruin.com): OpenAI 周一(5 月13 日)宣布推出最新一代人工智能大型语言模型GPT-4o,据称它将使ChatGPT 更智能、更易于使用。新模型将向未付费用户开放, ...", "htmlSnippet": "咕噜美国通(Guruin.com): \u003cb\u003eOpenAI\u003c/b\u003e 周一(5 月13 日)宣布推出最新一代人工智能大型语言\u003cb\u003e模型\u003c/b\u003eGPT-4o,据称它将使ChatGPT 更智能、更易于使用。\u003cb\u003e新模型\u003c/b\u003e将向未付费用户开放,?...", "formattedUrl": "https://www.guruin.com/news/75570", "htmlFormattedUrl": "https://www.guruin.com/news/75570", "pagemap": { "cse_thumbnail": [ { "src": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRr8TnMJBjm4u-eQseE-dbMx5UZDKU_T6fDa_xovylaAVxWWMzOjRxSooM&s", "width": "299", "height": "168" } ], "metatags": [ { "og:image": "https://media.cnn.com/api/v1/images/stellar/prod/screen-shot-2024-05-13-at-1-04-06-pm-copy.jpg?c=16x9&q=h_653,w_1160,c_fill/f_webp", "apple-itunes-app": "app-id=1080036296, affiliate-data=ct=MobileTopBanner&pt=117878949", "partnerboostverifycode": "32dc01246faccb7f5b3cad5016dd5033", "og:type": "website", "x-ua-compatible": "IE=edge,chrome=1", "og:title": "新一代AI强势出炉!OpenAI推出新模型GPT-4o,能进行实时口语对话,还是免费的! - 咕噜美国通 (Guruin.com)'", "og:description": "OpenAI 周一(5 月 13 日)宣布推出最新一代人工智能大型语言模型 GPT-4o,据称它将使 ChatGPT 更智能、更易于使用。新模型将向未付费用户开放,这意味着任何人都将可以通过 ChatGPT 使用 OpenAI 最先进的技术。", "fb:app_id": "1584038165196044", "apple-mobile-web-app-status-bar-style": "black", "viewport": "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no", "share_url": "https://www.guruin.comnews/75570", "apple-mobile-web-app-capable": "yes", "og:url": "https://www.guruin.com/news/75570" } ], "cse_image": [ { "src": "https://media.cnn.com/api/v1/images/stellar/prod/screen-shot-2024-05-13-at-1-04-06-pm-copy.jpg?c=16x9&q=h_653,w_1160,c_fill/f_webp" } ] } }, { "kind": "customsearch#result", "title": "OpenAI连发5款新模型,还修复了GPT-4变懒问题-虎嗅网", "htmlTitle": "\u003cb\u003eOpenAI\u003c/b\u003e连发5款\u003cb\u003e新模型\u003c/b\u003e,还修复了GPT-4变懒问题-虎嗅网", "link": "https://m.huxiu.com/article/2596319.html", "displayLink": "m.huxiu.com", "snippet": "Jan 26, 2024 ... OpenAI发布了五个新模型以及新的API使用管理工具,其中包括GPT-3.5 Turbo和GPT-4 Turbo的升级,以及新的文本嵌入模型和审查模型。同时,OpenAI还改进了API ...", "htmlSnippet": "Jan 26, 2024 \u003cb\u003e...\u003c/b\u003e \u003cb\u003eOpenAI\u003c/b\u003e发布了五个\u003cb\u003e新模型\u003c/b\u003e以及新的API使用管理工具,其中包括GPT-3.5 Turbo和GPT-4 Turbo的升级,以及新的文本嵌入\u003cb\u003e模型\u003c/b\u003e和审查\u003cb\u003e模型\u003c/b\u003e。同时,\u003cb\u003eOpenAI\u003c/b\u003e还改进了API?...", "formattedUrl": "https://m.huxiu.com/article/2596319.html", "htmlFormattedUrl": "https://m.huxiu.com/article/259631...
点击查看剩余70%
网友评论