Home > Back-end >  OpenAI, Python, Delete File
OpenAI, Python, Delete File

Time:11-06

In order to test some OpenAI file functionalities (Answer, Search etc.), I created several files using python through the OpenAI API.

As per OpenAI [files documentation][1] I am now trying to delete the file(s) I created as follows:

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()

CodePudding user response:

There is a bug in the OpenAI documentation.

You have to delete as follow :

openai.File.delete("file-CQ0tfZ4p3Hihlbwi1tQYmZV2")

instead of

openai.File("file-CQ0tfZ4p3Hihlbwi1tQYmZV2").delete()

  • Related