Class: Ultrasafeai::VectorStores::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ultrasafeai/vector_stores/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, base_url: nil, environment: nil) ⇒ void

Parameters:



11
12
13
14
15
# File 'lib/ultrasafeai/vector_stores/client.rb', line 11

def initialize(client:, base_url: nil, environment: nil)
  @client = client
  @base_url = base_url
  @environment = environment
end

Instance Method Details

#cancel_vector_store_file_batch(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :batch_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/ultrasafeai/vector_stores/client.rb', line 515

def cancel_vector_store_file_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/file_batches/#{URI.encode_uri_component(params[:batch_id].to_s)}/cancel",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#create(request_options: {}, **params) ⇒ Ultrasafeai::Types::VectorStore

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



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
# File 'lib/ultrasafeai/vector_stores/client.rb', line 64

def create(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  if params[:name]
    body.add(
      name: "name",
      value: params[:name]
    )
  end
  body.add_part(params[:files].to_form_data_part(name: "files")) if params[:files]

  request = Ultrasafeai::Internal::Multipart::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::VectorStore.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_vector_store_file_batch(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/ultrasafeai/vector_stores/client.rb', line 448

def create_vector_store_file_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request_data = Ultrasafeai::VectorStores::Types::CreateVectorStoreFileBatchRequest.new(params).to_h
  non_body_param_names = %w[vector_store_id]
  body = request_data.except(*non_body_param_names)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/file_batches",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#delete(request_options: {}, **params) ⇒ Ultrasafeai::Types::DeletedResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/ultrasafeai/vector_stores/client.rb', line 175

def delete(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "DELETE",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::DeletedResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_vector_store_file(request_options: {}, **params) ⇒ Ultrasafeai::Types::DeletedResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :file_id (String)

Returns:



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/ultrasafeai/vector_stores/client.rb', line 385

def delete_vector_store_file(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "DELETE",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files/#{URI.encode_uri_component(params[:file_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::DeletedResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_vector_store_file_content(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :file_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/ultrasafeai/vector_stores/client.rb', line 418

def get_vector_store_file_content(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files/#{URI.encode_uri_component(params[:file_id].to_s)}/content",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#list(request_options: {}, **params) ⇒ Ultrasafeai::Types::ListResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :limit (Integer, nil)
  • :after (String, nil)

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ultrasafeai/vector_stores/client.rb', line 28

def list(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["after"] = params[:after] if params.key?(:after)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::ListResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_vector_store_batch_files(request_options: {}, **params) ⇒ Ultrasafeai::Types::ListResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :batch_id (String)
  • :limit (Integer, nil)
  • :after (String, nil)

Returns:



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/ultrasafeai/vector_stores/client.rb', line 548

def list_vector_store_batch_files(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["after"] = params[:after] if params.key?(:after)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/file_batches/#{URI.encode_uri_component(params[:batch_id].to_s)}/files",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::ListResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_vector_store_files(request_options: {}, **params) ⇒ Ultrasafeai::Types::ListResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :limit (Integer, nil)
  • :after (String, nil)

Returns:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/ultrasafeai/vector_stores/client.rb', line 246

def list_vector_store_files(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["after"] = params[:after] if params.key?(:after)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::ListResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve(request_options: {}, **params) ⇒ Ultrasafeai::Types::VectorStore

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ultrasafeai/vector_stores/client.rb', line 107

def retrieve(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::VectorStore.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve_vector_store_file(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :file_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/ultrasafeai/vector_stores/client.rb', line 319

def retrieve_vector_store_file(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files/#{URI.encode_uri_component(params[:file_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#retrieve_vector_store_file_batch(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :batch_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/ultrasafeai/vector_stores/client.rb', line 484

def retrieve_vector_store_file_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/file_batches/#{URI.encode_uri_component(params[:batch_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#search_vector_store(request_options: {}, **params) ⇒ Ultrasafeai::Types::ListResponse

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/ultrasafeai/vector_stores/client.rb', line 207

def search_vector_store(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request_data = Ultrasafeai::VectorStores::Types::SearchVectorStoreRequest.new(params).to_h
  non_body_param_names = %w[vector_store_id]
  body = request_data.except(*non_body_param_names)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/search",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::ListResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_vector_store(request_options: {}, **params) ⇒ Ultrasafeai::Types::VectorStore

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/ultrasafeai/vector_stores/client.rb', line 139

def update_vector_store(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[vector_store_id]
  body_params = params.except(*path_param_names)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}",
    body: body_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::VectorStore.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_vector_store_file(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)
  • :file_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/ultrasafeai/vector_stores/client.rb', line 350

def update_vector_store_file(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[vector_store_id file_id]
  body_params = params.except(*path_param_names)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files/#{URI.encode_uri_component(params[:file_id].to_s)}",
    body: body_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#upload_vector_store_file(request_options: {}, **params) ⇒ Hash[String, Object]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :vector_store_id (String)

Returns:

  • (Hash[String, Object])

Raises:

  • (error_class)


283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ultrasafeai/vector_stores/client.rb', line 283

def upload_vector_store_file(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  body.add_part(params[:file].to_form_data_part(name: "file")) if params[:file]

  request = Ultrasafeai::Internal::Multipart::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "vector_stores/#{URI.encode_uri_component(params[:vector_store_id].to_s)}/files",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end