Class: OpenAI::Files

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

Constant Summary collapse

PURPOSES =
%w[
  assistants
  batch
  fine-tune
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Files

Returns a new instance of Files.



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

def initialize(client:)
  @client = client
end

Instance Method Details

#content(id:) ⇒ Object



35
36
37
# File 'lib/openai/files.rb', line 35

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

#delete(id:) ⇒ Object



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

def delete(id:)
  @client.delete(path: "/files/#{id}")
end

#listObject



13
14
15
# File 'lib/openai/files.rb', line 13

def list
  @client.get(path: "/files")
end

#retrieve(id:) ⇒ Object



31
32
33
# File 'lib/openai/files.rb', line 31

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

#upload(parameters: {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openai/files.rb', line 17

def upload(parameters: {})
  file_input = parameters[:file]
  file = prepare_file_input(file_input: file_input)

  validate(file: file, purpose: parameters[:purpose], file_input: file_input)

  @client.multipart_post(
    path: "/files",
    parameters: parameters.merge(file: file)
  )
ensure
  file.close if file.is_a?(File)
end