Class: Asimov::ApiV1::Files
Overview
Class interface for API methods in the “/files” URI subspace.
Instance Method Summary collapse
-
#content(file_id:, writer:) ⇒ Object
Retrieves the contents of the file with the specified file_id from OpenAI and passes those contents to the writer in a chunked manner.
-
#delete(file_id:) ⇒ Object
Deletes the file with the specified file_id from OpenAI.
-
#list ⇒ Object
Lists files that have been uploaded to OpenAI.
-
#retrieve(file_id:) ⇒ Object
Retrieves the file with the specified file_id from OpenAI.
-
#upload(file:, purpose:, parameters: {}) ⇒ Object
Uploads a file to the /files endpoint with the specified parameters.
Methods inherited from Base
#initialize, #rest_create_w_json_params, #rest_create_w_multipart_params, #rest_delete, #rest_get, #rest_get_streamed_download, #rest_index
Constructor Details
This class inherits a constructor from Asimov::ApiV1::Base
Instance Method Details
#content(file_id:, writer:) ⇒ Object
Retrieves the contents of the file with the specified file_id from OpenAI and passes those contents to the writer in a chunked manner.
as it is received from the API
67 68 69 |
# File 'lib/asimov/api_v1/files.rb', line 67 def content(file_id:, writer:) rest_get_streamed_download(resource: [RESOURCE, file_id, "content"], writer: writer) end |
#delete(file_id:) ⇒ Object
Deletes the file with the specified file_id from OpenAI.
55 56 57 |
# File 'lib/asimov/api_v1/files.rb', line 55 def delete(file_id:) rest_delete(resource: RESOURCE, id: file_id) end |
#list ⇒ Object
Lists files that have been uploaded to OpenAI
19 20 21 |
# File 'lib/asimov/api_v1/files.rb', line 19 def list rest_index(resource: RESOURCE) end |
#retrieve(file_id:) ⇒ Object
Retrieves the file with the specified file_id from OpenAI.
46 47 48 |
# File 'lib/asimov/api_v1/files.rb', line 46 def retrieve(file_id:) rest_get(resource: RESOURCE, id: file_id) end |
#upload(file:, purpose:, parameters: {}) ⇒ Object
Uploads a file to the /files endpoint with the specified parameters.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asimov/api_v1/files.rb', line 29 def upload(file:, purpose:, parameters: {}) raise MissingRequiredParameterError.new(:file) unless file raise MissingRequiredParameterError.new(:purpose) unless purpose validate(file, purpose) rest_create_w_multipart_params( resource: RESOURCE, parameters: parameters.merge(file: Utils::FileManager.open(file), purpose: purpose) ) end |