1、首先申请一个api key,并安装openai
pip install openai
申请地址:https://beta.openai.com/
2、新建一个json文本文件sample-search.jsonl
{“text”: “The rebuilding of economies after the COVID-19 crisis offers a unique opportunity to transform the global food system and make it resilient to future shocks, ensuring environmentally sustainable and healthy nutrition for all. To make this happen, United Nations agencies like the Food and Agriculture Organization, the United Nations Environment Program, the Intergovernmental Panel on Climate Change, the International Fund for Agricultural Development, and the World Food Program, collectively, suggest four broad shifts in the food system.”, “metadata”: “Economic reset”}3、建立搜索库
{“text”: “In the past few weeks healthcare professionals have been fully focussed caring for enormous numbers of people infected with COVID-19. They did an amazing job. Not in the least because healthcare professionals and leaders have been using continues improvement as part of their accreditation program for many years. It has become part of their DNA. This has enabled them to change many processes as needed during COVID-19, using a cross-functional problem solving approach in (very) rapid improvement cycles.”, “metadata”: “Supporting adaptive healthcare”}
import openai
openai.api_key = "YOUR-API-KEY"
response = openai.File.create(file=open("/data/wwwroot/default/asset/sample-search.jsonl", 'r', encoding='utf-8'), purpose="search")
print(response)

从上面步骤中的响应中复制 id。
现在让我们来测试一下。要测试 GPT-3语义搜索的能力,请在查询文本参数中提供查询。
import openai
openai.api_key = "YOUR-API-KEY"
search_response = openai.Engine("davinci").search(
search_model="davinci",
query="healthcare",
max_rerank=5,
file="file-8ejPA5eM13J4J0dWy3bBbvTf",
return_metadata=True
)
print(search_response)

使用 GPT-3对给定查询执行语义搜索非常简单。在 JSON 响应中,我们得到与查询匹配的文档文本,得分显示结果的相关性。在我们的测试中,我们只提供了一个文档。如果我们提供多个文档,那么我们会得到多个不同分数的结果。
如果要使用中文gpt3,可以清源CPM (Chinese Pretrained Models),github地址:https://github.com/TsinghuaAI/CPM-1-Generate
网友回复
DLNA与UPnP的区别和不同?
苏超自建抢票app,通过先预约再抽签化解高并发抢票?
python如何让给电脑在局域网中伪装成电视接收手机的投屏图片视频播放?
如何结合python+js如何自己的视频编码与加密播放直播?
python如何在电脑上通过局域网将本地视频或m3u8视频投屏电视播放?
腾讯视频爱奇艺优酷vip电影电视剧视频如何通过python绕过vip收费直接观看?
有没有可免费观看全球电视台直播m3u8地址url的合集?
有没有实现观影自由的免vip影视苹果 CMS V10 API的可用url?
python如何实时检测电脑usb插入检测报警?
如何判断真人操作的鼠标移动直线轨迹与机器操作的轨迹?