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:



232
233
234
# File 'lib/deeprails/resources/defend.rb', line 232

def initialize(client:)
  @client = client
end

Instance Method Details

#create_workflow(improvement_action:, name:, threshold_type:, automatic_hallucination_tolerance_levels: nil, context_awareness: 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

  • context_awareness (Boolean) —

    Context includes any structured information that directly relates to the model’s

  • 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:



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

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:



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

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:



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

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

#submit_and_stream_event_streaming(workflow_id, model_input:, model_output:, model_used:, run_mode:, stream: nil, nametag: nil, request_options: {}) ⇒ Deeprails::Internal::Stream<String>

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

Use this endpoint to submit a model input and output pair to a workflow for evaluation with streaming responses.

Parameters:

  • workflow_id (String) —

    Path param: The ID of the workflow to create the event for.

  • model_input (Hash{Symbol=>Object}) —

    Body param: The input provided to the model (e.g., prompt, messages).

  • model_output (String) —

    Body param: The output generated by the model to be evaluated.

  • model_used (String) —

    Body param: The model that generated the output (e.g., "gpt-4", "claude-3").

  • run_mode (Symbol, Deeprails::Models::DefendSubmitAndStreamEventParams::RunMode) —

    Body param: The evaluation run mode. Streaming is supported on all run modes exc

  • stream (Boolean) —

    Query param: Enable SSE streaming for real-time token feedback. Supported on all

  • nametag (String) —

    Body param: Optional tag to identify this event.

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

Returns:

See Also:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/deeprails/resources/defend.rb', line 132

def submit_and_stream_event_streaming(workflow_id, params)
  query_params = [:stream]
  parsed, options = Deeprails::DefendSubmitAndStreamEventParams.dump_request(params)
  query = Deeprails::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :post,
    path: ["defend/%1$s/events?stream=true", workflow_id],
    query: query,
    headers: {"accept" => "text/event-stream"},
    body: parsed.except(*query_params),
    stream: Deeprails::Internal::Stream,
    model: String,
    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:



173
174
175
176
177
178
179
180
181
182
# File 'lib/deeprails/resources/defend.rb', line 173

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, automatic_hallucination_tolerance_levels: nil, context_awareness: nil, custom_hallucination_threshold_values: nil, description: nil, file_search: nil, improvement_action: nil, max_improvement_attempts: nil, name: nil, threshold_type: nil, web_search: nil, request_options: {}) ⇒ Deeprails::Models::DefendUpdateResponse

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

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

Parameters:

  • workflow_id (String) —

    The ID of the workflow to edit.

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

    New mapping of guardrail metrics to hallucination tolerance levels

  • context_awareness (Boolean) —

    Whether to enable context awareness for this workflow's evaluations.

  • custom_hallucination_threshold_values (Hash{Symbol=>Float}) —

    New mapping of guardrail metrics to floating point threshold values to be used w

  • description (String) —

    New description for the workflow.

  • file_search (Array<String>) —

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

  • improvement_action (Symbol, Deeprails::Models::DefendUpdateWorkflowParams::ImprovementAction) —

    The new action used to improve outputs that fail one or more guardrail metrics f

  • max_improvement_attempts (Integer) —

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

  • name (String) —

    New name for the workflow.

  • threshold_type (Symbol, Deeprails::Models::DefendUpdateWorkflowParams::ThresholdType) —

    New type of thresholds to use for the workflow, either automatic or custom.

  • web_search (Boolean) —

    Whether to enable web search for this workflow's evaluations.

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

Returns:

See Also:



218
219
220
221
222
223
224
225
226
227
# File 'lib/deeprails/resources/defend.rb', line 218

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