Class: Vellum::SandboxesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/sandboxes/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ SandboxesClient

Parameters:



14
15
16
17
# File 'lib/vellum_ai/sandboxes/client.rb', line 14

def initialize(request_client:)
  # @type [RequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



10
11
12
# File 'lib/vellum_ai/sandboxes/client.rb', line 10

def request_client
  @request_client
end

Instance Method Details

#delete_sandbox_scenario(id:, scenario_id:, request_options: nil) ⇒ Void

Deletes an existing scenario from a sandbox, keying off of the provided scenario id.

Parameters:

  • id (String)

    A UUID string identifying this sandbox.

  • scenario_id (String)

    An id identifying the scenario that you’d like to delete

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


59
60
61
62
63
64
65
66
# File 'lib/vellum_ai/sandboxes/client.rb', line 59

def delete_sandbox_scenario(id:, scenario_id:, request_options: nil)
  @request_client.conn.delete do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.url "#{@request_client.default_environment[:Default]}/v1/sandboxes/#{id}/scenarios/#{scenario_id}"
  end
end

#upsert_sandbox_scenario(id:, inputs:, label: nil, scenario_id: nil, request_options: nil) ⇒ SandboxScenario

Upserts a new scenario for a sandbox, keying off of the optionally provided scenario id.

If an id is provided and has a match, the scenario will be updated. If no id is provided or no match is found, a new scenario will be appended to the end.

Note that a full replacement of the scenario is performed, so any fields not provided will be removed or overwritten with default values.

Parameters:

  • id (String)

    A UUID string identifying this sandbox.

  • label (String) (defaults to: nil)
  • inputs (Array<Hash>)

    The inputs for the scenarioRequest of type Array<ScenarioInputRequest>, as a Hash

    • :key (String)

    • :type (SCENARIO_INPUT_TYPE_ENUM)

    • :value (String)

    • :chat_history (Array<ChatMessageRequest>)

  • scenario_id (String) (defaults to: nil)

    The id of the scenario to update. If none is provided, an id will be generated and a new scenario will be appended.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vellum_ai/sandboxes/client.rb', line 37

def upsert_sandbox_scenario(id:, inputs:, label: nil, scenario_id: nil, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      label: label,
      inputs: inputs,
      scenario_id: scenario_id
    }.compact
    req.url "#{@request_client.default_environment[:Default]}/v1/sandboxes/#{id}/scenarios"
  end
  SandboxScenario.from_json(json_object: response.body)
end