必应bing搜索+gpt4o打造具有联网搜索问题总结能力的ai助手

大模型一旦拥有了搜索引擎的能力,那要飞起来,如果自己有服务器,可以用Scrapy、Apache Lucene、Elasticsearch 和 Solr这些开源的搜索引擎自己搭建一个自己的搜索引擎进行全网爬取网页进行索引,不过今天我们所有搜索引擎的api,我们以bing搜索为例:
一、申请bing搜索api和azure openai的api
搜索api申请地址:https://www.microsoft.com/en-us/bing/apis/bing-web-search-api

免费的每秒可请求3次,每个月1000次,收费版本1000次高达25美元,有点贵啊,不过我们使用免费的。


这里提供了秘钥和示例代码


还有api文档:https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/reference/query-parameters
还有各种编程语言的请求bing搜索api的示例代码

我们以python为例根据关键字获取搜索结果
import requests
# 替换为你的 API 密钥
API_KEY = 'YOUR_API_KEY'
# Bing 搜索 API 的 URL
SEARCH_URL = 'https://api.bing.microsoft.com/v7.0/search'
def bing_search(query, count=10):
headers = {
'Ocp-Apim-Subscription-Key': API_KEY
}
params = {
'q': query,
'count': count,
'mkt': 'en-US' # 指定市场,例如美国
}
response = requests.get(SEARCH_URL, headers=headers, params=params)
response.raise_for_status()
return response.json()
if __name__ == '__main__':
query = 'Python programming'
results = bing_search(query)
for result in results['webPages']['value']:
print(f"Title: {result['name']}")
print(f"URL: {result['url']}")
print(f"Snippet: {result['snippet']}")
print('-' * 50)

二、编写代...
点击查看剩余70%
网友评论0