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
网友回复
python如何调用openai的api实现知识讲解类动画讲解视频的合成?
html如何直接调用openai的api实现海报可视化设计及文本描述生成可编辑海报?
f12前端调试如何找出按钮点击事件触发的那段代码进行调试?
abcjs如何将曲谱播放后导出mid和wav格式音频下载?
python如何将曲子文本生成音乐mp3或wav、mid文件
python中mp3、wav音乐如何转成mid格式?
js在HTML中如何将曲谱生成音乐在线播放并下载本地?
python如何实现在windows上通过键盘来模拟鼠标操作?
python如何给win10电脑增加文件或文件夹右键自定义菜单?
python如何将音乐mp3文件解析获取曲调数据?