Class: Asimov::ApiV1::Files

Inherits:
Base
  • Object
show all
Defined in:
lib/asimov/api_v1/files.rb

Overview

Class interface for API methods in the “/files” URI subspace.

Constant Summary collapse

URI_PREFIX =
"/files".freeze

Instance Method Summary collapse

Methods inherited from Base

#check_for_api_error, #http_delete, #http_get, #http_streamed_download, #initialize, #json_post, #multipart_post, #wrap_response_with_error_handling

Constructor Details

This class inherits a constructor from Asimov::ApiV1::Base

Instance Method Details

#content(file_id:, writer:) ⇒ Object



42
43
44
# File 'lib/asimov/api_v1/files.rb', line 42

def content(file_id:, writer:)
  http_streamed_download(path: "#{URI_PREFIX}/#{file_id}/content", writer: writer)
end

#delete(file_id:) ⇒ Object



38
39
40
# File 'lib/asimov/api_v1/files.rb', line 38

def delete(file_id:)
  http_delete(path: "#{URI_PREFIX}/#{file_id}")
end

#listObject

Lists files that have been uploaded to OpenAI



18
19
20
# File 'lib/asimov/api_v1/files.rb', line 18

def list
  http_get(path: URI_PREFIX)
end

#retrieve(file_id:) ⇒ Object



34
35
36
# File 'lib/asimov/api_v1/files.rb', line 34

def retrieve(file_id:)
  http_get(path: "#{URI_PREFIX}/#{file_id}")
end

#upload(parameters:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/asimov/api_v1/files.rb', line 22

def upload(parameters:)
  raise MissingRequiredParameterError.new(:file) unless parameters[:file]
  raise MissingRequiredParameterError.new(:purpose) unless parameters[:purpose]

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

  multipart_post(
    path: URI_PREFIX,
    parameters: parameters.merge(file: Utils::FileManager.open(parameters[:file]))
  )
end