Module: OpenAI::Helpers::ResourcePolling Private
- Defined in:
- lib/openai/helpers/resource_polling.rb,
sig/openai/helpers/resource_polling.rbs
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Product-specific status handling for file and vector-store polling.
Class Method Summary collapse
- .poll_vector_store_file(resource, file_id, vector_store_id:, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::VectorStores::VectorStoreFile private
- .poll_vector_store_file_batch(resource, batch_id, vector_store_id:, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch private
- .wait_for_file(resource, file_id, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::FileObject private
Class Method Details
.poll_vector_store_file(resource, file_id, vector_store_id:, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/openai/helpers/resource_polling.rb', line 52 def self.poll_vector_store_file( resource, file_id, vector_store_id:, poll_interval:, timeout:, request_options: ) poller = OpenAI::Internal::Poller.new( operation: "vector store file #{file_id}", poll_interval: poll_interval, timeout: timeout ) file = nil begin loop do file = poller .request( , extra_headers: {"OpenAI-Beta" => "assistants=v2"}, resource: file ) do || resource.retrieve(file_id, vector_store_id: vector_store_id, request_options: ) end case file.status when OpenAI::VectorStores::VectorStoreFile::Status::IN_PROGRESS poller.wait(file) when OpenAI::VectorStores::VectorStoreFile::Status::COMPLETED, OpenAI::VectorStores::VectorStoreFile::Status::FAILED, OpenAI::VectorStores::VectorStoreFile::Status::CANCELLED return file else raise( OpenAI::Errors::PollingError, "Unexpected status while waiting for vector store file " \ "#{file_id}: #{file.status.inspect}" ) end end rescue OpenAI::Errors::APITimeoutError poller.check_deadline!(file) raise end end |
.poll_vector_store_file_batch(resource, batch_id, vector_store_id:, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::VectorStores::VectorStoreFileBatch
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.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/openai/helpers/resource_polling.rb', line 104 def self.poll_vector_store_file_batch( resource, batch_id, vector_store_id:, poll_interval:, timeout:, request_options: ) poller = OpenAI::Internal::Poller.new( operation: "vector store file batch #{batch_id}", poll_interval: poll_interval, timeout: timeout ) batch = nil begin loop do batch = poller .request( , extra_headers: {"OpenAI-Beta" => "assistants=v2"}, resource: batch ) do || resource.retrieve(batch_id, vector_store_id: vector_store_id, request_options: ) end case batch.status when OpenAI::VectorStores::VectorStoreFileBatch::Status::IN_PROGRESS poller.wait(batch) when OpenAI::VectorStores::VectorStoreFileBatch::Status::COMPLETED, OpenAI::VectorStores::VectorStoreFileBatch::Status::FAILED, OpenAI::VectorStores::VectorStoreFileBatch::Status::CANCELLED return batch else raise( OpenAI::Errors::PollingError, "Unexpected status while waiting for vector store file batch " \ "#{batch_id}: #{batch.status.inspect}" ) end end rescue OpenAI::Errors::APITimeoutError poller.check_deadline!(batch) raise end end |
.wait_for_file(resource, file_id, poll_interval:, timeout:, request_options:) ⇒ OpenAI::Models::FileObject
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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openai/helpers/resource_polling.rb', line 12 def self.wait_for_file(resource, file_id, poll_interval:, timeout:, request_options:) poller = OpenAI::Internal::Poller.new( operation: "file #{file_id}", poll_interval: poll_interval, timeout: timeout ) file = nil begin loop do file = poller.request(, resource: file) do || resource.retrieve(file_id, request_options: ) end case file.status when OpenAI::FileObject::Status::UPLOADED poller.wait(file) when OpenAI::FileObject::Status::PROCESSED, OpenAI::FileObject::Status::ERROR, :deleted, "deleted" return file else raise( OpenAI::Errors::PollingError, "Unexpected status while waiting for file #{file_id}: #{file.status.inspect}" ) end end rescue OpenAI::Errors::APITimeoutError poller.check_deadline!(file) raise end end |