Class: OpenAI::Files

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

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, organization_id: nil) ⇒ Files

Returns a new instance of Files.



3
4
5
6
# File 'lib/openai/files.rb', line 3

def initialize(access_token: nil, organization_id: nil)
  OpenAI.configuration.access_token = access_token if access_token
  OpenAI.configuration.organization_id = organization_id if organization_id
end

Instance Method Details

#content(id:) ⇒ Object



25
26
27
# File 'lib/openai/files.rb', line 25

def content(id:)
  OpenAI::Client.get(path: "/files/#{id}/content")
end

#delete(id:) ⇒ Object



29
30
31
# File 'lib/openai/files.rb', line 29

def delete(id:)
  OpenAI::Client.delete(path: "/files/#{id}")
end

#listObject



8
9
10
# File 'lib/openai/files.rb', line 8

def list
  OpenAI::Client.get(path: "/files")
end

#retrieve(id:) ⇒ Object



21
22
23
# File 'lib/openai/files.rb', line 21

def retrieve(id:)
  OpenAI::Client.get(path: "/files/#{id}")
end

#upload(parameters: {}) ⇒ Object



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

def upload(parameters: {})
  validate(file: parameters[:file])

  OpenAI::Client.multipart_post(
    path: "/files",
    parameters: parameters.merge(file: File.open(parameters[:file]))
  )
end