deeprails 0.18.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -0
  3. data/README.md +1 -1
  4. data/lib/deeprails/internal/stream.rb +29 -0
  5. data/lib/deeprails/internal/transport/base_client.rb +3 -1
  6. data/lib/deeprails/internal/transport/pooled_net_requester.rb +12 -10
  7. data/lib/deeprails/internal/type/base_stream.rb +83 -0
  8. data/lib/deeprails/internal/util.rb +7 -2
  9. data/lib/deeprails/models/defend_create_workflow_params.rb +14 -1
  10. data/lib/deeprails/models/defend_response.rb +134 -10
  11. data/lib/deeprails/models/defend_submit_and_stream_event_params.rb +83 -0
  12. data/lib/deeprails/models/defend_submit_and_stream_event_response.rb +7 -0
  13. data/lib/deeprails/models/defend_submit_event_params.rb +52 -16
  14. data/lib/deeprails/models/defend_update_response.rb +9 -1
  15. data/lib/deeprails/models/defend_update_workflow_params.rb +131 -5
  16. data/lib/deeprails/models/monitor_create_params.rb +14 -1
  17. data/lib/deeprails/models/monitor_detail_response.rb +53 -14
  18. data/lib/deeprails/models/monitor_event_detail_response.rb +6 -2
  19. data/lib/deeprails/models/monitor_submit_event_params.rb +52 -16
  20. data/lib/deeprails/models/monitor_update_params.rb +46 -5
  21. data/lib/deeprails/models/workflow_event_detail_response.rb +88 -16
  22. data/lib/deeprails/models/workflow_event_response.rb +9 -1
  23. data/lib/deeprails/models.rb +2 -0
  24. data/lib/deeprails/resources/defend.rb +67 -4
  25. data/lib/deeprails/resources/monitor.rb +14 -6
  26. data/lib/deeprails/version.rb +1 -1
  27. data/lib/deeprails.rb +5 -0
  28. data/manifest.yaml +1 -0
  29. data/rbi/deeprails/internal/stream.rbi +20 -0
  30. data/rbi/deeprails/internal/transport/base_client.rbi +18 -2
  31. data/rbi/deeprails/internal/type/base_stream.rbi +75 -0
  32. data/rbi/deeprails/models/defend_create_workflow_params.rbi +21 -0
  33. data/rbi/deeprails/models/defend_response.rbi +286 -14
  34. data/rbi/deeprails/models/defend_submit_and_stream_event_params.rbi +148 -0
  35. data/rbi/deeprails/models/defend_submit_and_stream_event_response.rbi +7 -0
  36. data/rbi/deeprails/models/defend_submit_event_params.rbi +108 -25
  37. data/rbi/deeprails/models/defend_update_response.rbi +14 -3
  38. data/rbi/deeprails/models/defend_update_workflow_params.rbi +298 -4
  39. data/rbi/deeprails/models/monitor_create_params.rbi +21 -0
  40. data/rbi/deeprails/models/monitor_detail_response.rbi +103 -22
  41. data/rbi/deeprails/models/monitor_event_detail_response.rbi +4 -2
  42. data/rbi/deeprails/models/monitor_submit_event_params.rbi +108 -25
  43. data/rbi/deeprails/models/monitor_update_params.rbi +107 -4
  44. data/rbi/deeprails/models/workflow_event_detail_response.rbi +170 -24
  45. data/rbi/deeprails/models/workflow_event_response.rbi +8 -0
  46. data/rbi/deeprails/models.rbi +3 -0
  47. data/rbi/deeprails/resources/defend.rbi +96 -6
  48. data/rbi/deeprails/resources/monitor.rbi +28 -8
  49. data/sig/deeprails/internal/stream.rbs +9 -0
  50. data/sig/deeprails/internal/type/base_stream.rbs +38 -0
  51. data/sig/deeprails/models/defend_create_workflow_params.rbs +7 -0
  52. data/sig/deeprails/models/defend_response.rbs +114 -8
  53. data/sig/deeprails/models/defend_submit_and_stream_event_params.rbs +74 -0
  54. data/sig/deeprails/models/defend_submit_and_stream_event_response.rbs +5 -0
  55. data/sig/deeprails/models/defend_submit_event_params.rbs +39 -10
  56. data/sig/deeprails/models/defend_update_response.rbs +10 -3
  57. data/sig/deeprails/models/defend_update_workflow_params.rbs +103 -1
  58. data/sig/deeprails/models/monitor_create_params.rbs +7 -0
  59. data/sig/deeprails/models/monitor_detail_response.rbs +36 -9
  60. data/sig/deeprails/models/monitor_submit_event_params.rbs +39 -10
  61. data/sig/deeprails/models/monitor_update_params.rbs +45 -1
  62. data/sig/deeprails/models/workflow_event_detail_response.rbs +88 -15
  63. data/sig/deeprails/models/workflow_event_response.rbs +5 -0
  64. data/sig/deeprails/models.rbs +2 -0
  65. data/sig/deeprails/resources/defend.rbs +20 -0
  66. data/sig/deeprails/resources/monitor.rbs +4 -0
  67. metadata +28 -2
@@ -4,6 +4,11 @@ module Deeprails
4
4
  module Models
5
5
  # @see Deeprails::Resources::Defend#retrieve_event
6
6
  class WorkflowEventDetailResponse < Deeprails::Internal::Type::BaseModel
7
+ # @!attribute analysis_of_failures
8
+ #
9
+ # @return [Array<String>]
10
+ required :analysis_of_failures, Deeprails::Internal::Type::ArrayOf[String]
11
+
7
12
  # @!attribute evaluation_history
8
13
  # History of evaluations for the event.
9
14
  #
@@ -44,13 +49,23 @@ module Deeprails
44
49
  required :improvement_action, enum: -> { Deeprails::WorkflowEventDetailResponse::ImprovementAction }
45
50
 
46
51
  # @!attribute improvement_tool_status
47
- # Status of the improvement tool used to improve the event.
52
+ # Status of the improvement tool used to improve the event. `improvement_required`
53
+ # indicates that the evaluation is complete and the improvement action is needed
54
+ # but is not taking place. `improved` and `improvement_failed` indicate when the
55
+ # improvement action concludes, successfully and unsuccessfully, respectively.
56
+ # `no_improvement_required` means that the first evaluation passed all its
57
+ # metrics!
48
58
  #
49
59
  # @return [Symbol, Deeprails::Models::WorkflowEventDetailResponse::ImprovementToolStatus, nil]
50
60
  required :improvement_tool_status,
51
61
  enum: -> { Deeprails::WorkflowEventDetailResponse::ImprovementToolStatus },
52
62
  nil?: true
53
63
 
64
+ # @!attribute key_improvements
65
+ #
66
+ # @return [Array<Object>]
67
+ required :key_improvements, Deeprails::Internal::Type::ArrayOf[Deeprails::Internal::Type::Unknown]
68
+
54
69
  # @!attribute status
55
70
  # Status of the event.
56
71
  #
@@ -78,8 +93,8 @@ module Deeprails
78
93
  -> { Deeprails::Internal::Type::HashOf[enum: Deeprails::WorkflowEventDetailResponse::AutomaticHallucinationToleranceLevel] }
79
94
 
80
95
  # @!attribute capabilities
81
- # Extended AI capabilities available to the event, if any. Can be `web_search`
82
- # and/or `file_search`.
96
+ # Extended AI capabilities available to the event, if any. Can be `web_search`,
97
+ # `file_search`, and/or `context_awareness`.
83
98
  #
84
99
  # @return [Array<Deeprails::Models::WorkflowEventDetailResponse::Capability>, nil]
85
100
  optional :capabilities,
@@ -99,10 +114,19 @@ module Deeprails
99
114
  # @return [Array<Deeprails::Models::WorkflowEventDetailResponse::File>, nil]
100
115
  optional :files, -> { Deeprails::Internal::Type::ArrayOf[Deeprails::WorkflowEventDetailResponse::File] }
101
116
 
102
- # @!method initialize(evaluation_history:, evaluation_result:, event_id:, filtered:, improved_model_output:, improvement_action:, improvement_tool_status:, status:, threshold_type:, workflow_id:, automatic_hallucination_tolerance_levels: nil, capabilities: nil, custom_hallucination_threshold_values: nil, files: nil)
117
+ # @!attribute max_improvement_attempts
118
+ # The maximum number of improvement attempts to be applied to one event before it
119
+ # is considered failed.
120
+ #
121
+ # @return [Integer, nil]
122
+ optional :max_improvement_attempts, Integer
123
+
124
+ # @!method initialize(analysis_of_failures:, evaluation_history:, evaluation_result:, event_id:, filtered:, improved_model_output:, improvement_action:, improvement_tool_status:, key_improvements:, status:, threshold_type:, workflow_id:, automatic_hallucination_tolerance_levels: nil, capabilities: nil, custom_hallucination_threshold_values: nil, files: nil, max_improvement_attempts: nil)
103
125
  # Some parameter documentations has been truncated, see
104
126
  # {Deeprails::Models::WorkflowEventDetailResponse} for more details.
105
127
  #
128
+ # @param analysis_of_failures [Array<String>]
129
+ #
106
130
  # @param evaluation_history [Array<Deeprails::Models::WorkflowEventDetailResponse::EvaluationHistory>] History of evaluations for the event.
107
131
  #
108
132
  # @param evaluation_result [Hash{Symbol=>Object}] Evaluation result consisting of average scores and rationales for each of the ev
@@ -115,7 +139,9 @@ module Deeprails
115
139
  #
116
140
  # @param improvement_action [Symbol, Deeprails::Models::WorkflowEventDetailResponse::ImprovementAction] Type of improvement action used to improve the event.
117
141
  #
118
- # @param improvement_tool_status [Symbol, Deeprails::Models::WorkflowEventDetailResponse::ImprovementToolStatus, nil] Status of the improvement tool used to improve the event.
142
+ # @param improvement_tool_status [Symbol, Deeprails::Models::WorkflowEventDetailResponse::ImprovementToolStatus, nil] Status of the improvement tool used to improve the event. `improvement_required`
143
+ #
144
+ # @param key_improvements [Array<Object>]
119
145
  #
120
146
  # @param status [Symbol, Deeprails::Models::WorkflowEventDetailResponse::Status] Status of the event.
121
147
  #
@@ -125,13 +151,20 @@ module Deeprails
125
151
  #
126
152
  # @param automatic_hallucination_tolerance_levels [Hash{Symbol=>Symbol, Deeprails::Models::WorkflowEventDetailResponse::AutomaticHallucinationToleranceLevel}] Mapping of guardrail metric names to tolerance values. Values are strings (`low`
127
153
  #
128
- # @param capabilities [Array<Deeprails::Models::WorkflowEventDetailResponse::Capability>] Extended AI capabilities available to the event, if any. Can be `web_search` and
154
+ # @param capabilities [Array<Deeprails::Models::WorkflowEventDetailResponse::Capability>] Extended AI capabilities available to the event, if any. Can be `web_search`, `f
129
155
  #
130
156
  # @param custom_hallucination_threshold_values [Hash{Symbol=>Float}] Mapping of guardrail metric names to threshold values. Values are floating point
131
157
  #
132
158
  # @param files [Array<Deeprails::Models::WorkflowEventDetailResponse::File>] List of files available to the event, if any. Will only be present if `file_sear
159
+ #
160
+ # @param max_improvement_attempts [Integer] The maximum number of improvement attempts to be applied to one event before it
133
161
 
134
162
  class EvaluationHistory < Deeprails::Internal::Type::BaseModel
163
+ # @!attribute analysis_of_failures
164
+ #
165
+ # @return [String, nil]
166
+ optional :analysis_of_failures, String
167
+
135
168
  # @!attribute attempt
136
169
  #
137
170
  # @return [String, nil]
@@ -167,6 +200,17 @@ module Deeprails
167
200
  # @return [Array<String>, nil]
168
201
  optional :guardrail_metrics, Deeprails::Internal::Type::ArrayOf[String]
169
202
 
203
+ # @!attribute improvement_tool_status
204
+ #
205
+ # @return [Symbol, Deeprails::Models::WorkflowEventDetailResponse::EvaluationHistory::ImprovementToolStatus, nil]
206
+ optional :improvement_tool_status,
207
+ enum: -> { Deeprails::WorkflowEventDetailResponse::EvaluationHistory::ImprovementToolStatus }
208
+
209
+ # @!attribute key_improvements
210
+ #
211
+ # @return [Array<String>, nil]
212
+ optional :key_improvements, Deeprails::Internal::Type::ArrayOf[String]
213
+
170
214
  # @!attribute model_input
171
215
  #
172
216
  # @return [Hash{Symbol=>Object}, nil]
@@ -177,11 +221,6 @@ module Deeprails
177
221
  # @return [String, nil]
178
222
  optional :model_output, String
179
223
 
180
- # @!attribute modified_at
181
- #
182
- # @return [Time, nil]
183
- optional :modified_at, Time
184
-
185
224
  # @!attribute nametag
186
225
  #
187
226
  # @return [String, nil]
@@ -197,7 +236,8 @@ module Deeprails
197
236
  # @return [String, nil]
198
237
  optional :run_mode, String
199
238
 
200
- # @!method initialize(attempt: nil, created_at: nil, error_message: nil, evaluation_result: nil, evaluation_status: nil, evaluation_total_cost: nil, guardrail_metrics: nil, model_input: nil, model_output: nil, modified_at: nil, nametag: nil, progress: nil, run_mode: nil)
239
+ # @!method initialize(analysis_of_failures: nil, attempt: nil, created_at: nil, error_message: nil, evaluation_result: nil, evaluation_status: nil, evaluation_total_cost: nil, guardrail_metrics: nil, improvement_tool_status: nil, key_improvements: nil, model_input: nil, model_output: nil, nametag: nil, progress: nil, run_mode: nil)
240
+ # @param analysis_of_failures [String]
201
241
  # @param attempt [String]
202
242
  # @param created_at [Time]
203
243
  # @param error_message [String]
@@ -205,12 +245,26 @@ module Deeprails
205
245
  # @param evaluation_status [String]
206
246
  # @param evaluation_total_cost [Float]
207
247
  # @param guardrail_metrics [Array<String>]
248
+ # @param improvement_tool_status [Symbol, Deeprails::Models::WorkflowEventDetailResponse::EvaluationHistory::ImprovementToolStatus]
249
+ # @param key_improvements [Array<String>]
208
250
  # @param model_input [Hash{Symbol=>Object}]
209
251
  # @param model_output [String]
210
- # @param modified_at [Time]
211
252
  # @param nametag [String]
212
253
  # @param progress [Integer]
213
254
  # @param run_mode [String]
255
+
256
+ # @see Deeprails::Models::WorkflowEventDetailResponse::EvaluationHistory#improvement_tool_status
257
+ module ImprovementToolStatus
258
+ extend Deeprails::Internal::Type::Enum
259
+
260
+ IMPROVED = :improved
261
+ IMPROVEMENT_FAILED = :improvement_failed
262
+ NO_IMPROVEMENT_REQUIRED = :no_improvement_required
263
+ IMPROVEMENT_REQUIRED = :improvement_required
264
+
265
+ # @!method self.values
266
+ # @return [Array<Symbol>]
267
+ end
214
268
  end
215
269
 
216
270
  # Type of improvement action used to improve the event.
@@ -227,14 +281,20 @@ module Deeprails
227
281
  # @return [Array<Symbol>]
228
282
  end
229
283
 
230
- # Status of the improvement tool used to improve the event.
284
+ # Status of the improvement tool used to improve the event. `improvement_required`
285
+ # indicates that the evaluation is complete and the improvement action is needed
286
+ # but is not taking place. `improved` and `improvement_failed` indicate when the
287
+ # improvement action concludes, successfully and unsuccessfully, respectively.
288
+ # `no_improvement_required` means that the first evaluation passed all its
289
+ # metrics!
231
290
  #
232
291
  # @see Deeprails::Models::WorkflowEventDetailResponse#improvement_tool_status
233
292
  module ImprovementToolStatus
234
293
  extend Deeprails::Internal::Type::Enum
235
294
 
236
295
  IMPROVED = :improved
237
- FAILED_ON_MAX_RETRIES = :"failed on max retries"
296
+ IMPROVEMENT_FAILED = :improvement_failed
297
+ NO_IMPROVEMENT_REQUIRED = :no_improvement_required
238
298
  IMPROVEMENT_REQUIRED = :improvement_required
239
299
 
240
300
  # @!method self.values
@@ -304,10 +364,22 @@ module Deeprails
304
364
  # @return [Integer, nil]
305
365
  optional :file_size, Integer
306
366
 
307
- # @!method initialize(file_id: nil, file_name: nil, file_size: nil)
367
+ # @!attribute presigned_url
368
+ #
369
+ # @return [String, nil]
370
+ optional :presigned_url, String
371
+
372
+ # @!attribute presigned_url_expires_at
373
+ #
374
+ # @return [Time, nil]
375
+ optional :presigned_url_expires_at, Time
376
+
377
+ # @!method initialize(file_id: nil, file_name: nil, file_size: nil, presigned_url: nil, presigned_url_expires_at: nil)
308
378
  # @param file_id [String]
309
379
  # @param file_name [String]
310
380
  # @param file_size [Integer]
381
+ # @param presigned_url [String]
382
+ # @param presigned_url_expires_at [Time]
311
383
  end
312
384
  end
313
385
  end
@@ -4,6 +4,12 @@ module Deeprails
4
4
  module Models
5
5
  # @see Deeprails::Resources::Defend#submit_event
6
6
  class WorkflowEventResponse < Deeprails::Internal::Type::BaseModel
7
+ # @!attribute billing_request_id
8
+ # The ID of the billing request for the event.
9
+ #
10
+ # @return [String]
11
+ required :billing_request_id, String
12
+
7
13
  # @!attribute created_at
8
14
  # The time the event was created in UTC.
9
15
  #
@@ -28,7 +34,9 @@ module Deeprails
28
34
  # @return [String]
29
35
  required :workflow_id, String
30
36
 
31
- # @!method initialize(created_at:, event_id:, status:, workflow_id:)
37
+ # @!method initialize(billing_request_id:, created_at:, event_id:, status:, workflow_id:)
38
+ # @param billing_request_id [String] The ID of the billing request for the event.
39
+ #
32
40
  # @param created_at [Time] The time the event was created in UTC.
33
41
  #
34
42
  # @param event_id [String] A unique workflow event ID.
@@ -49,6 +49,8 @@ module Deeprails
49
49
 
50
50
  DefendRetrieveWorkflowParams = Deeprails::Models::DefendRetrieveWorkflowParams
51
51
 
52
+ DefendSubmitAndStreamEventParams = Deeprails::Models::DefendSubmitAndStreamEventParams
53
+
52
54
  DefendSubmitEventParams = Deeprails::Models::DefendSubmitEventParams
53
55
 
54
56
  DefendUpdateResponse = Deeprails::Models::DefendUpdateResponse
@@ -9,7 +9,7 @@ module Deeprails
9
9
  # Use this endpoint to create a new guardrail workflow by specifying guardrail
10
10
  # thresholds, an improvement action, and optional extended capabilities.
11
11
  #
12
- # @overload 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: {})
12
+ # @overload 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: {})
13
13
  #
14
14
  # @param improvement_action [Symbol, Deeprails::Models::DefendCreateWorkflowParams::ImprovementAction] The action used to improve outputs that fail one or more guardrail metrics for t
15
15
  #
@@ -19,6 +19,8 @@ module Deeprails
19
19
  #
20
20
  # @param automatic_hallucination_tolerance_levels [Hash{Symbol=>Symbol, Deeprails::Models::DefendCreateWorkflowParams::AutomaticHallucinationToleranceLevel}] Mapping of guardrail metrics to hallucination tolerance levels
21
21
  #
22
+ # @param context_awareness [Boolean] Context includes any structured information that directly relates to the model’s
23
+ #
22
24
  # @param custom_hallucination_threshold_values [Hash{Symbol=>Float}] Mapping of guardrail metrics to floating point threshold values. Possible metric
23
25
  #
24
26
  # @param description [String] Description for the workflow.
@@ -99,6 +101,48 @@ module Deeprails
99
101
  )
100
102
  end
101
103
 
104
+ # Some parameter documentations has been truncated, see
105
+ # {Deeprails::Models::DefendSubmitAndStreamEventParams} for more details.
106
+ #
107
+ # Use this endpoint to create a new event for a guardrail workflow with real-time
108
+ # streaming feedback via Server-Sent Events (SSE).
109
+ #
110
+ # @overload submit_and_stream_event_streaming(workflow_id, model_input:, model_output:, model_used:, run_mode:, stream: nil, nametag: nil, request_options: {})
111
+ #
112
+ # @param workflow_id [String] Path param: The ID of the workflow to create the event for.
113
+ #
114
+ # @param model_input [Hash{Symbol=>Object}] Body param: The input provided to the model (e.g., prompt, messages).
115
+ #
116
+ # @param model_output [String] Body param: The output generated by the model to be evaluated.
117
+ #
118
+ # @param model_used [String] Body param: The model that generated the output (e.g., "gpt-4", "claude-3").
119
+ #
120
+ # @param run_mode [Symbol, Deeprails::Models::DefendSubmitAndStreamEventParams::RunMode] Body param: The evaluation run mode. Streaming only supports fast, precision, an
121
+ #
122
+ # @param stream [Boolean] Query param: Enable SSE streaming for real-time token feedback. Only supported f
123
+ #
124
+ # @param nametag [String] Body param: Optional tag to identify this event.
125
+ #
126
+ # @param request_options [Deeprails::RequestOptions, Hash{Symbol=>Object}, nil]
127
+ #
128
+ # @return [Deeprails::Internal::Stream<String>]
129
+ #
130
+ # @see Deeprails::Models::DefendSubmitAndStreamEventParams
131
+ def submit_and_stream_event_streaming(workflow_id, params)
132
+ parsed, options = Deeprails::DefendSubmitAndStreamEventParams.dump_request(params)
133
+ query_params = [:stream]
134
+ @client.request(
135
+ method: :post,
136
+ path: ["defend/%1$s/events?stream=true", workflow_id],
137
+ query: parsed.slice(*query_params),
138
+ headers: {"accept" => "text/event-stream"},
139
+ body: parsed.except(*query_params),
140
+ stream: Deeprails::Internal::Stream,
141
+ model: String,
142
+ options: options
143
+ )
144
+ end
145
+
102
146
  # Some parameter documentations has been truncated, see
103
147
  # {Deeprails::Models::DefendSubmitEventParams} for more details.
104
148
  #
@@ -135,15 +179,34 @@ module Deeprails
135
179
  )
136
180
  end
137
181
 
182
+ # Some parameter documentations has been truncated, see
183
+ # {Deeprails::Models::DefendUpdateWorkflowParams} for more details.
184
+ #
138
185
  # Use this endpoint to update an existing defend workflow if its details change.
139
186
  #
140
- # @overload update_workflow(workflow_id, description: nil, name: nil, request_options: {})
187
+ # @overload 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: {})
141
188
  #
142
189
  # @param workflow_id [String] The ID of the workflow to edit.
143
190
  #
144
- # @param description [String] Description for the workflow.
191
+ # @param automatic_hallucination_tolerance_levels [Hash{Symbol=>Symbol, Deeprails::Models::DefendUpdateWorkflowParams::AutomaticHallucinationToleranceLevel}] New mapping of guardrail metrics to hallucination tolerance levels
145
192
  #
146
- # @param name [String] Name of the workflow.
193
+ # @param context_awareness [Boolean] Whether to enable context awareness for this workflow's evaluations.
194
+ #
195
+ # @param custom_hallucination_threshold_values [Hash{Symbol=>Float}] New mapping of guardrail metrics to floating point threshold values to be used w
196
+ #
197
+ # @param description [String] New description for the workflow.
198
+ #
199
+ # @param file_search [Array<String>] An array of file IDs to search in the workflow's evaluations. Files must be uplo
200
+ #
201
+ # @param improvement_action [Symbol, Deeprails::Models::DefendUpdateWorkflowParams::ImprovementAction] The new action used to improve outputs that fail one or more guardrail metrics f
202
+ #
203
+ # @param max_improvement_attempts [Integer] Max. number of improvement action attempts until a given event passes the guardr
204
+ #
205
+ # @param name [String] New name for the workflow.
206
+ #
207
+ # @param threshold_type [Symbol, Deeprails::Models::DefendUpdateWorkflowParams::ThresholdType] New type of thresholds to use for the workflow, either `automatic` or `custom`.
208
+ #
209
+ # @param web_search [Boolean] Whether to enable web search for this workflow's evaluations.
147
210
  #
148
211
  # @param request_options [Deeprails::RequestOptions, Hash{Symbol=>Object}, nil]
149
212
  #
@@ -9,12 +9,14 @@ module Deeprails
9
9
  # Use this endpoint to create a new monitor to evaluate model inputs and outputs
10
10
  # using guardrails
11
11
  #
12
- # @overload create(guardrail_metrics:, name:, description: nil, file_search: nil, web_search: nil, request_options: {})
12
+ # @overload create(guardrail_metrics:, name:, context_awareness: nil, description: nil, file_search: nil, web_search: nil, request_options: {})
13
13
  #
14
14
  # @param guardrail_metrics [Array<Symbol, Deeprails::Models::MonitorCreateParams::GuardrailMetric>] An array of guardrail metrics that the model input and output pair will be evalu
15
15
  #
16
16
  # @param name [String] Name of the new monitor.
17
17
  #
18
+ # @param context_awareness [Boolean] Context includes any structured information that directly relates to the model’s
19
+ #
18
20
  # @param description [String] Description of the new monitor.
19
21
  #
20
22
  # @param file_search [Array<String>] An array of file IDs to search in the monitor's evaluations. Files must be uploa
@@ -68,19 +70,25 @@ module Deeprails
68
70
  # Some parameter documentations has been truncated, see
69
71
  # {Deeprails::Models::MonitorUpdateParams} for more details.
70
72
  #
71
- # Use this endpoint to update the name, description, or status of an existing
72
- # monitor
73
+ # Use this endpoint to update the name, status, and/or other details of an
74
+ # existing monitor.
73
75
  #
74
- # @overload update(monitor_id, description: nil, name: nil, status: nil, request_options: {})
76
+ # @overload update(monitor_id, description: nil, file_search: nil, guardrail_metrics: nil, name: nil, status: nil, web_search: nil, request_options: {})
75
77
  #
76
78
  # @param monitor_id [String] The ID of the monitor to edit.
77
79
  #
78
- # @param description [String] Description of the monitor.
80
+ # @param description [String] New description of the monitor.
81
+ #
82
+ # @param file_search [Array<String>] An array of file IDs to search in the monitor's evaluations. Files must be uploa
79
83
  #
80
- # @param name [String] Name of the monitor.
84
+ # @param guardrail_metrics [Array<Symbol, Deeprails::Models::MonitorUpdateParams::GuardrailMetric>] An array of the new guardrail metrics that model input and output pairs will be
85
+ #
86
+ # @param name [String] New name of the monitor.
81
87
  #
82
88
  # @param status [Symbol, Deeprails::Models::MonitorUpdateParams::Status] Status of the monitor. Can be `active` or `inactive`. Inactive monitors no lon
83
89
  #
90
+ # @param web_search [Boolean] Whether to enable web search for this monitor's evaluations.
91
+ #
84
92
  # @param request_options [Deeprails::RequestOptions, Hash{Symbol=>Object}, nil]
85
93
  #
86
94
  # @return [Deeprails::Models::MonitorUpdateResponse]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deeprails
4
- VERSION = "0.18.0"
4
+ VERSION = "0.23.0"
5
5
  end
data/lib/deeprails.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # Standard libraries.
4
4
  # rubocop:disable Lint/RedundantRequireStatement
5
5
  require "English"
6
+ require "base64"
6
7
  require "cgi"
7
8
  require "date"
8
9
  require "erb"
@@ -43,6 +44,7 @@ require_relative "deeprails/internal/type/array_of"
43
44
  require_relative "deeprails/internal/type/hash_of"
44
45
  require_relative "deeprails/internal/type/base_model"
45
46
  require_relative "deeprails/internal/type/base_page"
47
+ require_relative "deeprails/internal/type/base_stream"
46
48
  require_relative "deeprails/internal/type/request_parameters"
47
49
  require_relative "deeprails/internal"
48
50
  require_relative "deeprails/request_options"
@@ -51,11 +53,14 @@ require_relative "deeprails/errors"
51
53
  require_relative "deeprails/internal/transport/base_client"
52
54
  require_relative "deeprails/internal/transport/pooled_net_requester"
53
55
  require_relative "deeprails/client"
56
+ require_relative "deeprails/internal/stream"
54
57
  require_relative "deeprails/models/defend_create_response"
55
58
  require_relative "deeprails/models/defend_create_workflow_params"
56
59
  require_relative "deeprails/models/defend_response"
57
60
  require_relative "deeprails/models/defend_retrieve_event_params"
58
61
  require_relative "deeprails/models/defend_retrieve_workflow_params"
62
+ require_relative "deeprails/models/defend_submit_and_stream_event_params"
63
+ require_relative "deeprails/models/defend_submit_and_stream_event_response"
59
64
  require_relative "deeprails/models/defend_submit_event_params"
60
65
  require_relative "deeprails/models/defend_update_response"
61
66
  require_relative "deeprails/models/defend_update_workflow_params"
data/manifest.yaml CHANGED
@@ -1,5 +1,6 @@
1
1
  dependencies:
2
2
  - English
3
+ - base64
3
4
  - cgi
4
5
  - date
5
6
  - erb
@@ -0,0 +1,20 @@
1
+ # typed: strong
2
+
3
+ module Deeprails
4
+ module Internal
5
+ class Stream
6
+ Message =
7
+ type_member(:in) do
8
+ { fixed: Deeprails::Internal::Util::ServerSentEvent }
9
+ end
10
+ Elem = type_member(:out)
11
+
12
+ include Deeprails::Internal::Type::BaseStream
13
+
14
+ # @api private
15
+ sig { override.returns(T::Enumerable[Elem]) }
16
+ private def iterator
17
+ end
18
+ end
19
+ end
20
+ end
@@ -49,7 +49,15 @@ module Deeprails
49
49
  ]
50
50
  ]
51
51
  ),
52
- stream: T.nilable(T::Class[T.anything]),
52
+ stream:
53
+ T.nilable(
54
+ T::Class[
55
+ Deeprails::Internal::Type::BaseStream[
56
+ T.anything,
57
+ Deeprails::Internal::Type::BaseModel
58
+ ]
59
+ ]
60
+ ),
53
61
  model: T.nilable(Deeprails::Internal::Type::Converter::Input),
54
62
  options: T.nilable(Deeprails::RequestOptions::OrHash)
55
63
  }
@@ -269,7 +277,15 @@ module Deeprails
269
277
  ]
270
278
  ]
271
279
  ),
272
- stream: T.nilable(T::Class[T.anything]),
280
+ stream:
281
+ T.nilable(
282
+ T::Class[
283
+ Deeprails::Internal::Type::BaseStream[
284
+ T.anything,
285
+ Deeprails::Internal::Type::BaseModel
286
+ ]
287
+ ]
288
+ ),
273
289
  model: T.nilable(Deeprails::Internal::Type::Converter::Input),
274
290
  options: T.nilable(Deeprails::RequestOptions::OrHash)
275
291
  ).returns(T.anything)
@@ -0,0 +1,75 @@
1
+ # typed: strong
2
+
3
+ module Deeprails
4
+ module Internal
5
+ module Type
6
+ # @api private
7
+ #
8
+ # This module provides a base implementation for streaming responses in the SDK.
9
+ module BaseStream
10
+ include Enumerable
11
+
12
+ Message = type_member(:in)
13
+ Elem = type_member(:out)
14
+
15
+ sig { returns(Integer) }
16
+ attr_reader :status
17
+
18
+ sig { returns(T::Hash[String, String]) }
19
+ attr_reader :headers
20
+
21
+ sig { void }
22
+ def close
23
+ end
24
+
25
+ # @api private
26
+ sig { overridable.returns(T::Enumerable[Elem]) }
27
+ private def iterator
28
+ end
29
+
30
+ sig { params(blk: T.proc.params(arg0: Elem).void).void }
31
+ def each(&blk)
32
+ end
33
+
34
+ sig { returns(T::Enumerator[Elem]) }
35
+ def to_enum
36
+ end
37
+
38
+ # @api private
39
+ sig do
40
+ params(
41
+ model:
42
+ T.any(T::Class[T.anything], Deeprails::Internal::Type::Converter),
43
+ url: URI::Generic,
44
+ status: Integer,
45
+ headers: T::Hash[String, String],
46
+ response: Net::HTTPResponse,
47
+ unwrap:
48
+ T.any(
49
+ Symbol,
50
+ Integer,
51
+ T::Array[T.any(Symbol, Integer)],
52
+ T.proc.params(arg0: T.anything).returns(T.anything)
53
+ ),
54
+ stream: T::Enumerable[Message]
55
+ ).void
56
+ end
57
+ def initialize(
58
+ model:,
59
+ url:,
60
+ status:,
61
+ headers:,
62
+ response:,
63
+ unwrap:,
64
+ stream:
65
+ )
66
+ end
67
+
68
+ # @api private
69
+ sig { returns(String) }
70
+ def inspect
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -67,6 +67,18 @@ module Deeprails
67
67
  end
68
68
  attr_writer :automatic_hallucination_tolerance_levels
69
69
 
70
+ # Context includes any structured information that directly relates to the model’s
71
+ # input and expected output—e.g., the recent turn-by-turn history between an AI
72
+ # tutor and a student, facts or state passed through an agentic workflow, or other
73
+ # domain-specific signals your system already knows and wants the model to
74
+ # condition on. This field determines whether to enable context awareness for this
75
+ # workflow's evaluations. Defaults to false.
76
+ sig { returns(T.nilable(T::Boolean)) }
77
+ attr_reader :context_awareness
78
+
79
+ sig { params(context_awareness: T::Boolean).void }
80
+ attr_writer :context_awareness
81
+
70
82
  # Mapping of guardrail metrics to floating point threshold values. Possible
71
83
  # metrics are `correctness`, `completeness`, `instruction_adherence`,
72
84
  # `context_adherence`, `ground_truth_adherence`, or `comprehensive_safety`.
@@ -122,6 +134,7 @@ module Deeprails
122
134
  Symbol,
123
135
  Deeprails::DefendCreateWorkflowParams::AutomaticHallucinationToleranceLevel::OrSymbol
124
136
  ],
137
+ context_awareness: T::Boolean,
125
138
  custom_hallucination_threshold_values: T::Hash[Symbol, Float],
126
139
  description: String,
127
140
  file_search: T::Array[String],
@@ -150,6 +163,13 @@ module Deeprails
150
163
  # `instruction_adherence`, `context_adherence`, `ground_truth_adherence`, or
151
164
  # `comprehensive_safety`.
152
165
  automatic_hallucination_tolerance_levels: nil,
166
+ # Context includes any structured information that directly relates to the model’s
167
+ # input and expected output—e.g., the recent turn-by-turn history between an AI
168
+ # tutor and a student, facts or state passed through an agentic workflow, or other
169
+ # domain-specific signals your system already knows and wants the model to
170
+ # condition on. This field determines whether to enable context awareness for this
171
+ # workflow's evaluations. Defaults to false.
172
+ context_awareness: nil,
153
173
  # Mapping of guardrail metrics to floating point threshold values. Possible
154
174
  # metrics are `correctness`, `completeness`, `instruction_adherence`,
155
175
  # `context_adherence`, `ground_truth_adherence`, or `comprehensive_safety`.
@@ -181,6 +201,7 @@ module Deeprails
181
201
  Symbol,
182
202
  Deeprails::DefendCreateWorkflowParams::AutomaticHallucinationToleranceLevel::OrSymbol
183
203
  ],
204
+ context_awareness: T::Boolean,
184
205
  custom_hallucination_threshold_values: T::Hash[Symbol, Float],
185
206
  description: String,
186
207
  file_search: T::Array[String],