题意:OpenAI, Python, 删除文件
问题背景:
In order to test some OpenAI file functionalities (Answer, Search etc.), I created several files using python through the OpenAI API.
为了测试一些OpenAI的文件功能(如回答、搜索等),我通过OpenAI API使用Python创建了几个文件。
As per OpenAI [files documentation][1] I am now trying to delete the file(s) I created as follows:
根据OpenAI的[文件文档][1],我现在正尝试删除我之前创建的文件,具体做法如下:
openai.File("file-CQ0tfZ4p3Hihlbwi1tQYmZV2").delete()
the error I get is as follows: 我得到了以下的错误:
TypeError: delete() missing 1 required positional argument: 'sid'
I know the file exists as I am able to print it's properties. My coding ability is fairly basic... how can I delete some...or all the files.
我知道文件存在,因为我能够打印出它的属性。我的编程能力相当基础...我该如何删除一些...或全部文件。
The entire code snippet is as follows: 完整的代码片段如下:
import openai#set environment variable and print
os.environ['OPENAI_API_KEY'] = '*************************'
os.environ.get('OPENAI_API_KEY')openai.File("file-CQ0tfZ4p3Hihlbwi1tQYmZV2").delete()
问题解决:
There is a bug in the OpenAI documentation.
OpenAI 文档中存在bug
You have to delete as follow : 需要删除以下内容
openai.File.delete("file-CQ0tfZ4p3Hihlbwi1tQYmZV2")
instead of 用以下内容替换
openai.File("file-CQ0tfZ4p3Hihlbwi1tQYmZV2").delete()