Class: OpenAI::Resources::Files
- Inherits:
-
Object
- Object
- OpenAI::Resources::Files
- Defined in:
- lib/openai/resources/files.rb
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 the contents of the specified file.
-
#create(file:, purpose:, expires_after: nil, request_options: {}) ⇒ OpenAI::Models::FileObject
Some parameter documentations has been truncated, see Models::FileCreateParams for more details.
-
#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>
Some parameter documentations has been truncated, see Models::FileListParams for more details.
-
#retrieve(file_id, request_options: {}) ⇒ OpenAI::Models::FileObject
Returns information about a specific file.
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.
166 167 168 |
# File 'lib/openai/resources/files.rb', line 166 def initialize(client:) @client = client end |
Instance Method Details
#content(file_id, request_options: {}) ⇒ StringIO
Returns the contents of the specified file.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/openai/resources/files.rb', line 152 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
Some parameter documentations has been truncated, see Models::FileCreateParams for more details.
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](platform.openai.com/docs/assistants/tools) for details.
-
The Fine-tuning API only supports ‘.jsonl` files. The input also has certain required formats for fine-tuning [chat](platform.openai.com/docs/api-reference/fine-tuning/chat-input) or [completions](platform.openai.com/docs/api-reference/fine-tuning/completions-input) models.
-
The Batch API only supports ‘.jsonl` files up to 200 MB in size. The input also has a specific required [format](platform.openai.com/docs/api-reference/batch/request-input).
-
For Retrieval or ‘file_search` ingestion, upload files here first. If you need to attach multiple uploaded files to the same vector store, use [`/vector_stores/vector_store_id/file_batches`](platform.openai.com/docs/api-reference/vector-stores-file-batches/createBatch) instead 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](help.openai.com/) if you need to increase these storage limits.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/openai/resources/files.rb', line 52 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.
131 132 133 134 135 136 137 138 139 |
# File 'lib/openai/resources/files.rb', line 131 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>
Some parameter documentations has been truncated, see Models::FileListParams for more details.
Returns a list of files.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/openai/resources/files.rb', line 106 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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/openai/resources/files.rb', line 76 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 |