Class: OpenAI::Resources::VectorStores::Files
- Inherits:
-
Object
- Object
- OpenAI::Resources::VectorStores::Files
- Defined in:
- lib/openai/resources/vector_stores/files.rb,
sig/openai/resources/vector_stores/files.rbs
Instance Method Summary collapse
-
#content(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Internal::Page<OpenAI::Models::VectorStores::FileContentResponse>
Retrieve the parsed contents of a vector store file.
-
#create(vector_store_id, file_id:, attributes: nil, chunking_strategy: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Some parameter documentations has been truncated, see Models::VectorStores::FileCreateParams for more details.
-
#create_and_poll(vector_store_id, file_id:, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Attach a file to a vector store and wait for processing to finish.
-
#delete(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileDeleted
Delete a vector store file.
-
#initialize(client:) ⇒ Files
constructor
private
A new instance of Files.
-
#list(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::FileListParams for more details.
-
#poll(file_id, vector_store_id:, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Wait for a vector store file to finish processing.
-
#retrieve(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Retrieves a vector store file.
-
#update(file_id, vector_store_id:, attributes:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Some parameter documentations has been truncated, see Models::VectorStores::FileUpdateParams for more details.
-
#upload(vector_store_id, file:, attributes: nil, chunking_strategy: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Upload a file and attach it to a vector store.
-
#upload_and_poll(vector_store_id, file:, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Upload a file, attach it to a vector store, and wait for processing to finish.
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.
398 399 400 |
# File 'lib/openai/resources/vector_stores/files.rb', line 398 def initialize(client:) @client = client end |
Instance Method Details
#content(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Internal::Page<OpenAI::Models::VectorStores::FileContentResponse>
Retrieve the parsed contents of a vector store file.
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/openai/resources/vector_stores/files.rb', line 379 def content(file_id, params) parsed, = OpenAI::VectorStores::FileContentParams.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/files/%2$s/content", vector_store_id, file_id], page: OpenAI::Internal::Page, model: OpenAI::Models::VectorStores::FileContentResponse, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#create(vector_store_id, file_id:, attributes: nil, chunking_strategy: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Some parameter documentations has been truncated, see Models::VectorStores::FileCreateParams for more details.
Create a vector store file by attaching a File to a vector store.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openai/resources/vector_stores/files.rb', line 31 def create(vector_store_id, params) parsed, = OpenAI::VectorStores::FileCreateParams.dump_request(params) @client.request( method: :post, path: ["vector_stores/%1$s/files", vector_store_id], body: parsed, model: OpenAI::VectorStores::VectorStoreFile, 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, file_id:, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Attach a file to a vector store and wait for processing to finish.
The returned file may have a failed or cancelled status; callers should
inspect the status and last_error. 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.
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/resources/vector_stores/files.rb', line 77 def create_and_poll( vector_store_id, file_id:, 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) params = {file_id: file_id, request_options: } params[:attributes] = attributes unless attributes.nil? params[:chunking_strategy] = chunking_strategy unless chunking_strategy.nil? file = create(vector_store_id, params) poll( file.id, vector_store_id: vector_store_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |
#delete(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFileDeleted
Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the delete file endpoint.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/openai/resources/vector_stores/files.rb', line 217 def delete(file_id, params) parsed, = OpenAI::VectorStores::FileDeleteParams.dump_request(params) vector_store_id = parsed.delete(:vector_store_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :delete, path: ["vector_stores/%1$s/files/%2$s", vector_store_id, file_id], model: OpenAI::VectorStores::VectorStoreFileDeleted, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#list(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::FileListParams for more details.
Returns a list of vector store files.
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/openai/resources/vector_stores/files.rb', line 187 def list(vector_store_id, params = {}) parsed, = OpenAI::VectorStores::FileListParams.dump_request(params) query = OpenAI::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["vector_stores/%1$s/files", vector_store_id], query: query, page: OpenAI::Internal::CursorPage, model: OpenAI::VectorStores::VectorStoreFile, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#poll(file_id, vector_store_id:, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Wait for a vector store file to finish processing.
The returned file may have a failed or cancelled status; callers should
inspect the status and last_error. Polling intervals and the overall timeout
are in seconds. Set timeout to nil to wait indefinitely.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/openai/resources/vector_stores/files.rb', line 254 def poll( file_id, vector_store_id:, poll_interval: nil, timeout: OpenAI::Internal::Poller::DEFAULT_TIMEOUT, request_options: {} ) OpenAI::Helpers::ResourcePolling.poll_vector_store_file( self, file_id, vector_store_id: vector_store_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |
#retrieve(file_id, vector_store_id:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Retrieves a vector store file.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/openai/resources/vector_stores/files.rb', line 114 def retrieve(file_id, params) parsed, = OpenAI::VectorStores::FileRetrieveParams.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/files/%2$s", vector_store_id, file_id], model: OpenAI::VectorStores::VectorStoreFile, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#update(file_id, vector_store_id:, attributes:, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Some parameter documentations has been truncated, see Models::VectorStores::FileUpdateParams for more details.
Update attributes on a vector store file.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/openai/resources/vector_stores/files.rb', line 147 def update(file_id, params) parsed, = OpenAI::VectorStores::FileUpdateParams.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/files/%2$s", vector_store_id, file_id], body: parsed, model: OpenAI::VectorStores::VectorStoreFile, security: {bearer_auth: true}, options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **} ) end |
#upload(vector_store_id, file:, attributes: nil, chunking_strategy: nil, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Upload a file and attach it to a vector store.
Processing continues asynchronously; use #upload_and_poll to wait until the file is ready.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/openai/resources/vector_stores/files.rb', line 290 def upload( vector_store_id, file:, attributes: nil, chunking_strategy: nil, request_options: {} ) = OpenAI::Internal::RequestOptionsScope.new() uploaded = @client.files.create( file: file, purpose: :assistants, request_options: .child("file-upload") ) params = { file_id: uploaded.id, request_options: .child("vector-store-file") } params[:attributes] = attributes unless attributes.nil? params[:chunking_strategy] = chunking_strategy unless chunking_strategy.nil? create(vector_store_id, params) end |
#upload_and_poll(vector_store_id, file:, attributes: nil, chunking_strategy: nil, poll_interval: nil, timeout: 1800.0, request_options: {}) ⇒ OpenAI::Models::VectorStores::VectorStoreFile
Upload a file, attach it to a vector store, and wait for processing to finish.
The returned file may have a failed or cancelled status; callers should
inspect the status and last_error.
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/openai/resources/vector_stores/files.rb', line 339 def upload_and_poll( vector_store_id, file:, 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) attached = upload( vector_store_id, file: file, attributes: attributes, chunking_strategy: chunking_strategy, request_options: ) poll( attached.id, vector_store_id: vector_store_id, poll_interval: poll_interval, timeout: timeout, request_options: ) end |