Class: Openai::Client::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/client/files.rb

Constant Summary collapse

PATH =
'files'

Instance Method Summary collapse

Instance Method Details

#delete(id) ⇒ Hash

Public: Makes an API call to delete the file.

Parameters:

  • id (String)

    file ID

Returns:

  • (Hash)

    the file



38
39
40
41
42
# File 'lib/openai/client/files.rb', line 38

def delete(id)
  Http.new.delete("#{PATH}/#{id}").body
rescue Faraday::Error
  nil
end

#find(id) ⇒ Hash

Public: Makes an API call to find the file by the ID.

Parameters:

  • id (String)

    file ID

Returns:

  • (Hash)

    found file



50
51
52
53
54
# File 'lib/openai/client/files.rb', line 50

def find(id)
  Http.new.get("#{PATH}/#{id}").body
rescue Faraday::Error
  nil
end

#find_content(id) ⇒ Hash

Public: Makes an API call to find the contents of the specified file.

Parameters:

  • id (String)

    file ID

Returns:

  • (Hash)

    the contents of the specified file



62
63
64
65
66
# File 'lib/openai/client/files.rb', line 62

def find_content(id)
  Http.new.get("#{PATH}/#{id}/content").body
rescue Faraday::Error
  nil
end

#listHash

Public: Makes an API call to return all files that belong to the user’s organization.

Returns:

  • (Hash)

    a list of files



14
15
16
17
18
# File 'lib/openai/client/files.rb', line 14

def list
  Http.new.get(PATH).body
rescue Faraday::Error
  nil
end

#upload(body) ⇒ Hash

Public: Makes an API call to upload a file.

Parameters:

  • body (Hash)

    request body

Returns:

  • (Hash)

    the file



26
27
28
29
30
# File 'lib/openai/client/files.rb', line 26

def upload(body)
  Http.new.multipart_post(PATH, Utils.upload_io(body, %i[file], 'jsonl')).body
rescue Faraday::Error
  nil
end