Class: Deeprails::Resources::Defend

Inherits:
Object
  • Object
show all
Defined in:
lib/deeprails/resources/defend.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Defend

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 Defend.

Parameters:



167
168
169
# File 'lib/deeprails/resources/defend.rb', line 167

def initialize(client:)
  @client = client
end

Instance Method Details

#create_workflow(improvement_action:, name:, threshold_type:, automatic_hallucination_tolerance_levels: nil, custom_hallucination_threshold_values: nil, description: nil, file_search: nil, max_improvement_attempts: nil, web_search: nil, request_options: {}) ⇒ Deeprails::Models::DefendCreateResponse

Some parameter documentations has been truncated, see Models::DefendCreateWorkflowParams for more details.

Use this endpoint to create a new guardrail workflow by specifying guardrail thresholds, an improvement action, and optional extended capabilities.

Parameters:

  • improvement_action (Symbol, Deeprails::Models::DefendCreateWorkflowParams::ImprovementAction)

    The action used to improve outputs that fail one or more guardrail metrics for t

  • name (String)

    Name of the workflow.

  • threshold_type (Symbol, Deeprails::Models::DefendCreateWorkflowParams::ThresholdType)

    Type of thresholds to use for the workflow, either ‘automatic` or `custom`. Aut

  • automatic_hallucination_tolerance_levels (Hash{Symbol=>Symbol, Deeprails::Models::DefendCreateWorkflowParams::AutomaticHallucinationToleranceLevel})

    Mapping of guardrail metrics to hallucination tolerance levels

  • custom_hallucination_threshold_values (Hash{Symbol=>Float})

    Mapping of guardrail metrics to floating point threshold values. Possible metric

  • description (String)

    Description for the workflow.

  • file_search (Array<String>)

    An array of file IDs to search in the workflow’s evaluations. Files must be uplo

  • max_improvement_attempts (Integer)

    Max. number of improvement action attempts until a given event passes the guardr

  • web_search (Boolean)

    Whether to enable web search for this workflow’s evaluations. Defaults to false.

  • request_options (Deeprails::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



37
38
39
40
41
42
43
44
45
46
# File 'lib/deeprails/resources/defend.rb', line 37

def create_workflow(params)
  parsed, options = Deeprails::DefendCreateWorkflowParams.dump_request(params)
  @client.request(
    method: :post,
    path: "defend",
    body: parsed,
    model: Deeprails::DefendCreateResponse,
    options: options
  )
end

#retrieve_event(event_id, workflow_id:, request_options: {}) ⇒ Deeprails::Models::WorkflowEventDetailResponse

Use this endpoint to retrieve a specific event of a guardrail workflow

Parameters:

  • event_id (String)

    The ID of the requested workflow event.

  • workflow_id (String)

    The ID of the workflow associated with the event.

  • request_options (Deeprails::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/deeprails/resources/defend.rb', line 61

def retrieve_event(event_id, params)
  parsed, options = Deeprails::DefendRetrieveEventParams.dump_request(params)
  workflow_id =
    parsed.delete(:workflow_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["defend/%1$s/events/%2$s", workflow_id, event_id],
    model: Deeprails::WorkflowEventDetailResponse,
    options: options
  )
end

#retrieve_workflow(workflow_id, limit: nil, request_options: {}) ⇒ Deeprails::Models::DefendResponse

Some parameter documentations has been truncated, see Models::DefendRetrieveWorkflowParams for more details.

Use this endpoint to retrieve the details for a specific defend workflow

Parameters:

  • workflow_id (String)

    The ID of the workflow to retrieve.

  • limit (Integer)

    Limit the number of returned events associated with this workflow. Defaults to

  • request_options (Deeprails::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



91
92
93
94
95
96
97
98
99
100
# File 'lib/deeprails/resources/defend.rb', line 91

def retrieve_workflow(workflow_id, params = {})
  parsed, options = Deeprails::DefendRetrieveWorkflowParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["defend/%1$s", workflow_id],
    query: parsed,
    model: Deeprails::DefendResponse,
    options: options
  )
end

#submit_event(workflow_id, model_input:, model_output:, model_used:, run_mode:, nametag: nil, request_options: {}) ⇒ Deeprails::Models::WorkflowEventResponse

Some parameter documentations has been truncated, see Models::DefendSubmitEventParams for more details.

Use this endpoint to submit a model input and output pair to a workflow for evaluation

Parameters:

  • workflow_id (String)

    Workflow ID associated with this event.

  • model_input (Deeprails::Models::DefendSubmitEventParams::ModelInput)

    A dictionary of inputs sent to the LLM to generate output. The dictionary must c

  • model_output (String)

    Output generated by the LLM to be evaluated.

  • model_used (String)

    Model ID used to generate the output, like ‘gpt-4o` or `o3`.

  • run_mode (Symbol, Deeprails::Models::DefendSubmitEventParams::RunMode)

    Run mode for the workflow event. The run mode allows the user to optimize for s

  • nametag (String)

    An optional, user-defined tag for the event.

  • request_options (Deeprails::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



127
128
129
130
131
132
133
134
135
136
# File 'lib/deeprails/resources/defend.rb', line 127

def submit_event(workflow_id, params)
  parsed, options = Deeprails::DefendSubmitEventParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["defend/%1$s/events", workflow_id],
    body: parsed,
    model: Deeprails::WorkflowEventResponse,
    options: options
  )
end

#update_workflow(workflow_id, description: nil, name: nil, request_options: {}) ⇒ Deeprails::Models::DefendUpdateResponse

Use this endpoint to update an existing defend workflow if its details change.

Parameters:

  • workflow_id (String)

    The ID of the workflow to edit.

  • description (String)

    Description for the workflow.

  • name (String)

    Name of the workflow.

  • request_options (Deeprails::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



153
154
155
156
157
158
159
160
161
162
# File 'lib/deeprails/resources/defend.rb', line 153

def update_workflow(workflow_id, params = {})
  parsed, options = Deeprails::DefendUpdateWorkflowParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["defend/%1$s", workflow_id],
    body: parsed,
    model: Deeprails::DefendUpdateResponse,
    options: options
  )
end