Class: OpenAI::Resources::VectorStores::FileBatches
- Inherits:
-
Object
- Object
- OpenAI::Resources::VectorStores::FileBatches
- Defined in:
- lib/openai/resources/vector_stores/file_batches.rb,
sig/openai/resources/vector_stores/file_batches.rbs
Instance Method Summary collapse
-
#cancel(batch_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Cancel a vector store file batch.
-
#create(vector_store_id, attributes: nil, chunking_strategy: nil, file_ids: nil, files: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Some parameter documentations has been truncated, see Models::VectorStores::FileBatchCreateParams for more details.
-
#create_and_poll(vector_store_id, attributes: nil, chunking_strategy: nil, file_ids: nil, files: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Create a vector store file batch and wait for processing to finish.
-
#initialize(client:) ⇒ FileBatches
constructor
private
A new instance of FileBatches.
-
#list_files(batch_id, vector_store_id:, after: nil, before: nil, filter: nil, limit: nil, order: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::VectorStores::VectorStoreFile>
Some parameter documentations has been truncated, see Models::VectorStores::FileBatchListFilesParams for more details.
-
#poll(batch_id, vector_store_id:, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Wait for a vector store file batch to finish processing.
-
#retrieve(batch_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Retrieves a vector store file batch.
-
#upload_and_poll(vector_store_id, files:, file_ids: [], max_concurrency: 5, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Upload files concurrently, create a vector store file batch, and wait for processing to finish.
Constructor Details
#initialize(client:) ⇒ FileBatches
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 FileBatches.
329 330 331 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 329 def initialize(client:) @client = client end |
Instance Method Details
#cancel(batch_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 148 def cancel(batch_id, params) parsed, = OpenAI::VectorStores::FileBatchCancelParams.dump_request(params) vector_store_id = parsed.delete(:vector_store_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :post, path: ["vector_stores/%1$s/file_batches/%2$s/cancel", vector_store_id, batch_id], model: OpenAI::VectorStores::VectorStoreFileBatch, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#create(vector_store_id, attributes: nil, chunking_strategy: nil, file_ids: nil, files: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Some parameter documentations has been truncated, see Models::VectorStores::FileBatchCreateParams for more details.
Create a vector store file batch.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 31 def create(vector_store_id, params = {}) parsed, = OpenAI::VectorStores::FileBatchCreateParams.dump_request(params) @client.request( method: :post, path: ["vector_stores/%1$s/file_batches", vector_store_id], body: parsed, model: OpenAI::VectorStores::VectorStoreFileBatch, security: {bearer_auth: true}, options: { **, extra_headers: OpenAI::Internal::Util.normalized_headers( {"OpenAI-Beta" => "assistants=v2"}, [:extra_headers].to_h ) } ) end |
#create_and_poll(vector_store_id, attributes: nil, chunking_strategy: nil, file_ids: nil, files: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Create a vector store file batch and wait for processing to finish.
The returned batch may have a failed or cancelled status; callers should
inspect its status and file counts. 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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 79 def create_and_poll( vector_store_id, attributes: nil, chunking_strategy: nil, file_ids: nil, files: nil, poll_interval: nil, timeout: OpenAI::Internal::Poller::DEFAULT_TIMEOUT, request_options: {} ) OpenAI::Internal::Poller.validate!(poll_interval: poll_interval, timeout: timeout) params = {request_options: } params[:attributes] = attributes unless attributes.nil? params[:chunking_strategy] = chunking_strategy unless chunking_strategy.nil? params[:file_ids] = file_ids unless file_ids.nil? params[:files] = files unless files.nil? batch = create(vector_store_id, params) poll( batch.id, vector_store_id: vector_store_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |
#list_files(batch_id, vector_store_id:, after: nil, before: nil, filter: nil, limit: nil, order: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::VectorStores::VectorStoreFile>
Some parameter documentations has been truncated, see Models::VectorStores::FileBatchListFilesParams for more details.
Returns a list of vector store files in a batch.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 189 def list_files(batch_id, params) parsed, = OpenAI::VectorStores::FileBatchListFilesParams.dump_request(params) vector_store_id = parsed.delete(:vector_store_id) do raise ArgumentError.new("missing required path argument #{_1}") end query = OpenAI::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["vector_stores/%1$s/file_batches/%2$s/files", vector_store_id, batch_id], query: query, page: OpenAI::Internal::CursorPage, model: OpenAI::VectorStores::VectorStoreFile, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#poll(batch_id, vector_store_id:, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Wait for a vector store file batch to finish processing.
The returned batch may have a failed or cancelled status; callers should
inspect its status and file counts. Polling intervals and the overall timeout
are in seconds. Set timeout to nil to wait indefinitely.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 229 def poll( batch_id, vector_store_id:, poll_interval: nil, timeout: OpenAI::Internal::Poller::DEFAULT_TIMEOUT, request_options: {} ) OpenAI::Helpers::ResourcePolling.poll_vector_store_file_batch( self, batch_id, vector_store_id: vector_store_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |
#retrieve(batch_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Retrieves a vector store file batch.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 119 def retrieve(batch_id, params) parsed, = OpenAI::VectorStores::FileBatchRetrieveParams.dump_request(params) vector_store_id = parsed.delete(:vector_store_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :get, path: ["vector_stores/%1$s/file_batches/%2$s", vector_store_id, batch_id], model: OpenAI::VectorStores::VectorStoreFileBatch, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#upload_and_poll(vector_store_id, files:, file_ids: [], max_concurrency: 5, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
Upload files concurrently, create a vector store file batch, and wait for processing to finish.
Existing file IDs can be included alongside new uploads. Upload concurrency is
bounded and defaults to 5. Set max_concurrency to 1 for sequential uploads.
Inputs are enumerated before requests begin so the 2,000-file API limit can be
checked without orphaning uploads. Stream-backed inputs are safely spooled during
enumeration, including IO objects yielded from block-scoped enumerators.
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 281 def upload_and_poll( vector_store_id, files:, file_ids: [], max_concurrency: 5, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: OpenAI::Internal::Poller::DEFAULT_TIMEOUT, request_options: {} ) OpenAI::Internal::Poller.validate!(poll_interval: poll_interval, timeout: timeout) = OpenAI::Internal::RequestOptionsScope.new() max_files = OpenAI::Internal::VectorStoreFileUploader::MAX_FILES_PER_BATCH if file_ids.length > max_files raise ArgumentError, "`file_ids` cannot contain more than #{max_files} entries" end uploaded = OpenAI::Internal::VectorStoreFileUploader .new( client: @client, max_concurrency: max_concurrency, request_options: ) .upload(files, max_files: max_files - file_ids.length) if uploaded.empty? raise( ArgumentError, "No `files` provided. Use `create_and_poll` when all files are already uploaded." ) end create_and_poll( vector_store_id, file_ids: [*file_ids, *uploaded.map(&:id)], attributes: attributes, chunking_strategy: chunking_strategy, poll_interval: poll_interval, timeout: timeout, request_options: .child("file-batch") ) end |