Class: OpenAI::Resources::Files
- Inherits:
-
Object
- Object
- OpenAI::Resources::Files
- Defined in:
- lib/openai/resources/files.rb,
lib/openai/helpers/files.rb,
sig/openai/helpers/files.rbs,
sig/openai/resources/files.rbs
Overview
Files are used to upload documents that can be used with features like Assistants and Fine-tuning.
Instance Method Summary collapse
-
#content(file_id, request_options: {}) ⇒ StringIO
Returns a response containing the contents of the specified file.
-
#create(file:, purpose:, expires_after: nil, request_options: {}) ⇒ OpenAI::Models::FileObject
Upload a file that can be used across various endpoints.
-
#delete(file_id, request_options: {}) ⇒ OpenAI::Models::FileDeleted
Delete a file and remove it from all vector stores.
-
#initialize(client:) ⇒ Files
constructor
private
A new instance of Files.
-
#list(after: nil, limit: nil, order: nil, purpose: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::FileObject>
Returns a list of files.
-
#retrieve(file_id, request_options: {}) ⇒ OpenAI::Models::FileObject
Returns information about a specific file.
-
#wait_for_processing(file_id, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::FileObject
Wait for an uploaded file to finish processing.
Constructor Details
#initialize(client:) ⇒ Files
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Files.
191 192 193 |
# File 'lib/openai/resources/files.rb', line 191 def initialize(client:) @client = client end |
Instance Method Details
#content(file_id, request_options: {}) ⇒ StringIO
Returns a response containing the contents of the specified file.
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/openai/resources/files.rb', line 177 def content(file_id, params = {}) @client.request( method: :get, path: ["files/%1$s/content", file_id], headers: {"accept" => "application/binary"}, model: StringIO, security: {bearer_auth: true}, options: params[:request_options] ) end |
#create(file:, purpose:, expires_after: nil, request_options: {}) ⇒ OpenAI::Models::FileObject
Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and each project can store up to 2.5 TB of files in total. There is no organization-wide storage limit. Uploads to this endpoint are rate-limited to 1,000 requests per minute per authenticated user.
- The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details.
- The Fine-tuning API only supports
.jsonlfiles. The input also has certain required formats for fine-tuning chat or completions models. - The Batch API only supports
.jsonlfiles up to 200 MB in size. The input also has a specific required format. - For Retrieval or
file_searchingestion, upload files here first. If you need to attach multiple uploaded files to the same vector store, use/vector_stores/{vector_store_id}/file_batchesinstead of attaching them one by one. Vector store attachment has separate limits from file upload, including 2,000 attached files per minute per organization.
Please contact us if you need to increase these storage limits.
String, StringIO, and pathless IO inputs are sent with generic upload
metadata. Use OpenAI::FilePart when you need to override the filename or
content type.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openai/resources/files.rb', line 68 def create(params) parsed, = OpenAI::FileCreateParams.dump_request(params) @client.request( method: :post, path: "files", headers: {"content-type" => "multipart/form-data"}, body: parsed, model: OpenAI::FileObject, security: {bearer_auth: true}, options: ) end |
#delete(file_id, request_options: {}) ⇒ OpenAI::Models::FileDeleted
Delete a file and remove it from all vector stores.
155 156 157 158 159 160 161 162 163 |
# File 'lib/openai/resources/files.rb', line 155 def delete(file_id, params = {}) @client.request( method: :delete, path: ["files/%1$s", file_id], model: OpenAI::FileDeleted, security: {bearer_auth: true}, options: params[:request_options] ) end |
#list(after: nil, limit: nil, order: nil, purpose: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::FileObject>
Returns a list of files.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/openai/resources/files.rb', line 129 def list(params = {}) parsed, = OpenAI::FileListParams.dump_request(params) query = OpenAI::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "files", query: query, page: OpenAI::Internal::CursorPage, model: OpenAI::FileObject, security: {bearer_auth: true}, options: ) end |
#retrieve(file_id, request_options: {}) ⇒ OpenAI::Models::FileObject
Returns information about a specific file.
93 94 95 96 97 98 99 100 101 |
# File 'lib/openai/resources/files.rb', line 93 def retrieve(file_id, params = {}) @client.request( method: :get, path: ["files/%1$s", file_id], model: OpenAI::FileObject, security: {bearer_auth: true}, options: params[:request_options] ) end |
#wait_for_processing(file_id, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::FileObject
Wait for an uploaded file to finish processing.
The returned file may have an error status; callers should inspect the
status before using it. Polling intervals and the overall timeout are in
seconds. Finite timeouts include authentication and request replay time and
disable transport retries so the deadline remains strict. Set timeout to
nil to wait indefinitely and retain configured transport retries.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/openai/helpers/files.rb', line 31 def wait_for_processing( file_id, poll_interval: nil, timeout: OpenAI::Internal::Poller::DEFAULT_TIMEOUT, request_options: {} ) OpenAI::Helpers::ResourcePolling.wait_for_file( self, file_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |