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
网友回复
webpack打包的网页如何通过ai还原源码成单一html代码?
如何将一个任意url的在线网页的html代码及css、js代码输出成一个文本块中?
PyWebIO、Gradio、Streamlit、NiceGUI怎么选择?
如何从视频中直接解析人物动作捕获数据?
openai发布的agentkit与coze扣子、dify等流程搭建智能体有啥不同?
阿里云上的ecs镜像存储还要钱,如何免费下载到本地以后再创建?
如何通过调用大模型api实现输入一个商品图片生成模特展示解说的宣传短片?
qwen千问大模型api如何内置互联网搜索?
YOLO如何结合opencv实现视觉实时摔倒检测?
html中内嵌style与link引入css代码报错的处理机制不同?