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
Create a vector store file by attaching a File to a vector store.
-
#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>
Returns a list of vector store files.
-
#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
Update attributes on a vector store file.
-
#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.
429 430 431 |
# File 'lib/openai/resources/vector_stores/files.rb', line 429 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.
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/openai/resources/vector_stores/files.rb', line 410 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
Create a vector store file by attaching a File to a vector store.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/openai/resources/vector_stores/files.rb', line 41 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/openai/resources/vector_stores/files.rb', line 87 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.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/openai/resources/vector_stores/files.rb', line 246 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>
Returns a list of vector store files.
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/openai/resources/vector_stores/files.rb', line 214 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.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/openai/resources/vector_stores/files.rb', line 283 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.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/openai/resources/vector_stores/files.rb', line 126 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
Update attributes on a vector store file.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/openai/resources/vector_stores/files.rb', line 163 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.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/openai/resources/vector_stores/files.rb', line 319 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.
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/openai/resources/vector_stores/files.rb', line 368 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 |