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
#http_delete, #http_get, #http_streamed_download, #initialize, #json_post, #multipart_post
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:) http_streamed_download(path: "#{URI_PREFIX}/#{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:) http_delete(path: "#{URI_PREFIX}/#{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 http_get(path: URI_PREFIX) 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:) http_get(path: "#{URI_PREFIX}/#{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) multipart_post( path: URI_PREFIX, parameters: parameters.merge(file: Utils::FileManager.open(file), purpose: purpose) ) end |