Python中的OpenAI库无法解析URL以使用关键字进行搜索

我编写了一个简短的聊 bot 原型,使用OpenAI库,它从键盘接收文本输入,通过一系列网站运行该搜索,处理通过ChatGPT返回的任何文本,并将其返回给用户。

我使用以下代码来创建响应

html = openai.File.create(url=source).text

其中source是通过遍历一系列URL创建的。

我使用的是标准的Raspberry Pi,Thonny是我的IDE,Python版本是3.9.2。

我遇到了以下错误。看起来openai.File.create方法不接受’url’参数,但我无法在库文档中找到可接受的关键字参数列表。

您知道如何使用一个关键字来从我的列表中获取URL吗?

非常感谢

搜索源时出错 https://en.wikipedia.org/wiki/Python_(programming_language): create() got an unexpected keyword argument ‘url’搜索源时出错 https://docs.python.org/3/tutorial/index.html: create() got an unexpected keyword argument ‘url’搜索源时出错 https://realpython.com/tutorials/: create() got an unexpected keyword argument ‘url’搜索源时出错 https://www.geeksforgeeks.org/python-programming-language/: create() got an unexpected keyword argument ‘url’搜索源时出错 https://www.python.org/: create() got an unexpected keyword argument ‘url’搜索源时出错 https://positivepython.co.uk: create() got an unexpected keyword argument ‘url’


回答:

我见过的所有File.create示例都是接收文件,而不是URL。关键字是file。例如:

openai.File.create(file=open("myfile.jsonl"), purpose="search")

根据文档File.create方法是用来创建文件的。

这是File类create方法的源代码

@classmethoddef create(    cls,    file,    purpose,    model=None,    api_key=None,    api_base=None,    api_type=None,    api_version=None,    organization=None,    user_provided_filename=None,):    requestor, url, files = cls.__prepare_file_create(        file,        purpose,        model,        api_key,        api_base,        api_type,        api_version,        organization,        user_provided_filename,    )    response, _, api_key = requestor.request("post", url, files=files)    return util.convert_to_openai_object(        response, api_key, api_version, organization    )

如您所见,没有url关键字。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注