Class: Vellum::AsyncSandboxesClient

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:) ⇒ AsyncSandboxesClient

Parameters:



74
75
76
77
# File 'lib/vellum_ai/sandboxes/client.rb', line 74

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



70
71
72
# File 'lib/vellum_ai/sandboxes/client.rb', line 70

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)


121
122
123
124
125
126
127
128
129
130
# File 'lib/vellum_ai/sandboxes/client.rb', line 121

def delete_sandbox_scenario(id:, scenario_id:, request_options: nil)
  Async do
    @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
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:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vellum_ai/sandboxes/client.rb', line 97

def upsert_sandbox_scenario(id:, inputs:, label: nil, scenario_id: nil, request_options: nil)
  Async do
    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
end