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
Create a vector store file batch.
-
#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>
Returns a list of vector store files in a batch.
-
#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.
363 364 365 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 363 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.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 169 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
Create a vector store file batch.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 48 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 96 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>
Returns a list of vector store files in a batch.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 223 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.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 263 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.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 138 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.
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/openai/resources/vector_stores/file_batches.rb', line 315 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 |