deeprails 0.17.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/README.md +3 -3
  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 +136 -12
  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/file_upload_params.rb +5 -5
  17. data/lib/deeprails/models/monitor_create_params.rb +14 -1
  18. data/lib/deeprails/models/monitor_detail_response.rb +56 -17
  19. data/lib/deeprails/models/monitor_event_detail_response.rb +6 -2
  20. data/lib/deeprails/models/monitor_submit_event_params.rb +52 -16
  21. data/lib/deeprails/models/monitor_update_params.rb +46 -5
  22. data/lib/deeprails/models/workflow_event_detail_response.rb +106 -34
  23. data/lib/deeprails/models/workflow_event_response.rb +9 -1
  24. data/lib/deeprails/models.rb +2 -0
  25. data/lib/deeprails/resources/defend.rb +70 -7
  26. data/lib/deeprails/resources/files.rb +2 -2
  27. data/lib/deeprails/resources/monitor.rb +14 -6
  28. data/lib/deeprails/version.rb +1 -1
  29. data/lib/deeprails.rb +5 -0
  30. data/manifest.yaml +1 -0
  31. data/rbi/deeprails/internal/stream.rbi +20 -0
  32. data/rbi/deeprails/internal/transport/base_client.rbi +18 -2
  33. data/rbi/deeprails/internal/type/base_stream.rbi +75 -0
  34. data/rbi/deeprails/models/defend_create_workflow_params.rbi +21 -0
  35. data/rbi/deeprails/models/defend_response.rbi +288 -16
  36. data/rbi/deeprails/models/defend_submit_and_stream_event_params.rbi +148 -0
  37. data/rbi/deeprails/models/defend_submit_and_stream_event_response.rbi +7 -0
  38. data/rbi/deeprails/models/defend_submit_event_params.rbi +108 -25
  39. data/rbi/deeprails/models/defend_update_response.rbi +14 -3
  40. data/rbi/deeprails/models/defend_update_workflow_params.rbi +298 -4
  41. data/rbi/deeprails/models/file_upload_params.rbi +9 -6
  42. data/rbi/deeprails/models/monitor_create_params.rbi +21 -0
  43. data/rbi/deeprails/models/monitor_detail_response.rbi +107 -26
  44. data/rbi/deeprails/models/monitor_event_detail_response.rbi +4 -2
  45. data/rbi/deeprails/models/monitor_submit_event_params.rbi +108 -25
  46. data/rbi/deeprails/models/monitor_update_params.rbi +107 -4
  47. data/rbi/deeprails/models/workflow_event_detail_response.rbi +209 -66
  48. data/rbi/deeprails/models/workflow_event_response.rbi +8 -0
  49. data/rbi/deeprails/models.rbi +3 -0
  50. data/rbi/deeprails/resources/defend.rbi +99 -9
  51. data/rbi/deeprails/resources/files.rbi +3 -3
  52. data/rbi/deeprails/resources/monitor.rbi +28 -8
  53. data/sig/deeprails/internal/stream.rbs +9 -0
  54. data/sig/deeprails/internal/type/base_stream.rbs +38 -0
  55. data/sig/deeprails/models/defend_create_workflow_params.rbs +7 -0
  56. data/sig/deeprails/models/defend_response.rbs +114 -8
  57. data/sig/deeprails/models/defend_submit_and_stream_event_params.rbs +74 -0
  58. data/sig/deeprails/models/defend_submit_and_stream_event_response.rbs +5 -0
  59. data/sig/deeprails/models/defend_submit_event_params.rbs +39 -10
  60. data/sig/deeprails/models/defend_update_response.rbs +10 -3
  61. data/sig/deeprails/models/defend_update_workflow_params.rbs +103 -1
  62. data/sig/deeprails/models/file_upload_params.rbs +4 -4
  63. data/sig/deeprails/models/monitor_create_params.rbs +7 -0
  64. data/sig/deeprails/models/monitor_detail_response.rbs +36 -9
  65. data/sig/deeprails/models/monitor_submit_event_params.rbs +39 -10
  66. data/sig/deeprails/models/monitor_update_params.rbs +45 -1
  67. data/sig/deeprails/models/workflow_event_detail_response.rbs +100 -27
  68. data/sig/deeprails/models/workflow_event_response.rbs +5 -0
  69. data/sig/deeprails/models.rbs +2 -0
  70. data/sig/deeprails/resources/defend.rbs +20 -0
  71. data/sig/deeprails/resources/files.rbs +1 -1
  72. data/sig/deeprails/resources/monitor.rbs +4 -0
  73. metadata +28 -2
@@ -15,8 +15,8 @@ module Deeprails
15
15
  end
16
16
 
17
17
  # A dictionary of inputs sent to the LLM to generate output. The dictionary must
18
- # contain at least a `user_prompt` field or a `system_prompt` field. For
19
- # ground_truth_adherence guardrail metric, `ground_truth` should be provided.
18
+ # contain a `user_prompt` field. For ground_truth_adherence guardrail metric,
19
+ # `ground_truth` should be provided.
20
20
  sig { returns(Deeprails::MonitorSubmitEventParams::ModelInput) }
21
21
  attr_reader :model_input
22
22
 
@@ -40,8 +40,8 @@ module Deeprails
40
40
 
41
41
  # Run mode for the monitor event. The run mode allows the user to optimize for
42
42
  # speed, accuracy, and cost by determining which models are used to evaluate the
43
- # event. Available run modes include `precision_plus`, `precision`, `smart`, and
44
- # `economy`. Defaults to `smart`.
43
+ # event. Available run modes include `precision_plus_codex`, `precision_plus`,
44
+ # `precision`, `smart`, and `economy`. Defaults to `smart`.
45
45
  sig do
46
46
  returns(
47
47
  T.nilable(Deeprails::MonitorSubmitEventParams::RunMode::OrSymbol)
@@ -67,8 +67,8 @@ module Deeprails
67
67
  end
68
68
  def self.new(
69
69
  # A dictionary of inputs sent to the LLM to generate output. The dictionary must
70
- # contain at least a `user_prompt` field or a `system_prompt` field. For
71
- # ground_truth_adherence guardrail metric, `ground_truth` should be provided.
70
+ # contain a `user_prompt` field. For ground_truth_adherence guardrail metric,
71
+ # `ground_truth` should be provided.
72
72
  model_input:,
73
73
  # Output generated by the LLM to be evaluated.
74
74
  model_output:,
@@ -76,8 +76,8 @@ module Deeprails
76
76
  nametag: nil,
77
77
  # Run mode for the monitor event. The run mode allows the user to optimize for
78
78
  # speed, accuracy, and cost by determining which models are used to evaluate the
79
- # event. Available run modes include `precision_plus`, `precision`, `smart`, and
80
- # `economy`. Defaults to `smart`.
79
+ # event. Available run modes include `precision_plus_codex`, `precision_plus`,
80
+ # `precision`, `smart`, and `economy`. Defaults to `smart`.
81
81
  run_mode: nil,
82
82
  request_options: {}
83
83
  )
@@ -106,6 +106,34 @@ module Deeprails
106
106
  )
107
107
  end
108
108
 
109
+ # The user prompt used to generate the output.
110
+ sig { returns(String) }
111
+ attr_accessor :user_prompt
112
+
113
+ # Any structured information that directly relates to the model’s input and
114
+ # expected output—e.g., the recent turn-by-turn history between an AI tutor and a
115
+ # student, facts or state passed through an agentic workflow, or other
116
+ # domain-specific signals your system already knows and wants the model to
117
+ # condition on.
118
+ sig do
119
+ returns(
120
+ T.nilable(
121
+ T::Array[Deeprails::MonitorSubmitEventParams::ModelInput::Context]
122
+ )
123
+ )
124
+ end
125
+ attr_reader :context
126
+
127
+ sig do
128
+ params(
129
+ context:
130
+ T::Array[
131
+ Deeprails::MonitorSubmitEventParams::ModelInput::Context::OrHash
132
+ ]
133
+ ).void
134
+ end
135
+ attr_writer :context
136
+
109
137
  # The ground truth for evaluating Ground Truth Adherence guardrail.
110
138
  sig { returns(T.nilable(String)) }
111
139
  attr_reader :ground_truth
@@ -120,46 +148,96 @@ module Deeprails
120
148
  sig { params(system_prompt: String).void }
121
149
  attr_writer :system_prompt
122
150
 
123
- # The user prompt used to generate the output.
124
- sig { returns(T.nilable(String)) }
125
- attr_reader :user_prompt
126
-
127
- sig { params(user_prompt: String).void }
128
- attr_writer :user_prompt
129
-
130
151
  # A dictionary of inputs sent to the LLM to generate output. The dictionary must
131
- # contain at least a `user_prompt` field or a `system_prompt` field. For
132
- # ground_truth_adherence guardrail metric, `ground_truth` should be provided.
152
+ # contain a `user_prompt` field. For ground_truth_adherence guardrail metric,
153
+ # `ground_truth` should be provided.
133
154
  sig do
134
155
  params(
156
+ user_prompt: String,
157
+ context:
158
+ T::Array[
159
+ Deeprails::MonitorSubmitEventParams::ModelInput::Context::OrHash
160
+ ],
135
161
  ground_truth: String,
136
- system_prompt: String,
137
- user_prompt: String
162
+ system_prompt: String
138
163
  ).returns(T.attached_class)
139
164
  end
140
165
  def self.new(
166
+ # The user prompt used to generate the output.
167
+ user_prompt:,
168
+ # Any structured information that directly relates to the model’s input and
169
+ # expected output—e.g., the recent turn-by-turn history between an AI tutor and a
170
+ # student, facts or state passed through an agentic workflow, or other
171
+ # domain-specific signals your system already knows and wants the model to
172
+ # condition on.
173
+ context: nil,
141
174
  # The ground truth for evaluating Ground Truth Adherence guardrail.
142
175
  ground_truth: nil,
143
176
  # The system prompt used to generate the output.
144
- system_prompt: nil,
145
- # The user prompt used to generate the output.
146
- user_prompt: nil
177
+ system_prompt: nil
147
178
  )
148
179
  end
149
180
 
150
181
  sig do
151
182
  override.returns(
152
- { ground_truth: String, system_prompt: String, user_prompt: String }
183
+ {
184
+ user_prompt: String,
185
+ context:
186
+ T::Array[
187
+ Deeprails::MonitorSubmitEventParams::ModelInput::Context
188
+ ],
189
+ ground_truth: String,
190
+ system_prompt: String
191
+ }
153
192
  )
154
193
  end
155
194
  def to_hash
156
195
  end
196
+
197
+ class Context < Deeprails::Internal::Type::BaseModel
198
+ OrHash =
199
+ T.type_alias do
200
+ T.any(
201
+ Deeprails::MonitorSubmitEventParams::ModelInput::Context,
202
+ Deeprails::Internal::AnyHash
203
+ )
204
+ end
205
+
206
+ # The content of the message.
207
+ sig { returns(T.nilable(String)) }
208
+ attr_reader :content
209
+
210
+ sig { params(content: String).void }
211
+ attr_writer :content
212
+
213
+ # The role of the speaker.
214
+ sig { returns(T.nilable(String)) }
215
+ attr_reader :role
216
+
217
+ sig { params(role: String).void }
218
+ attr_writer :role
219
+
220
+ sig do
221
+ params(content: String, role: String).returns(T.attached_class)
222
+ end
223
+ def self.new(
224
+ # The content of the message.
225
+ content: nil,
226
+ # The role of the speaker.
227
+ role: nil
228
+ )
229
+ end
230
+
231
+ sig { override.returns({ content: String, role: String }) }
232
+ def to_hash
233
+ end
234
+ end
157
235
  end
158
236
 
159
237
  # Run mode for the monitor event. The run mode allows the user to optimize for
160
238
  # speed, accuracy, and cost by determining which models are used to evaluate the
161
- # event. Available run modes include `precision_plus`, `precision`, `smart`, and
162
- # `economy`. Defaults to `smart`.
239
+ # event. Available run modes include `precision_plus_codex`, `precision_plus`,
240
+ # `precision`, `smart`, and `economy`. Defaults to `smart`.
163
241
  module RunMode
164
242
  extend Deeprails::Internal::Type::Enum
165
243
 
@@ -169,6 +247,11 @@ module Deeprails
169
247
  end
170
248
  OrSymbol = T.type_alias { T.any(Symbol, String) }
171
249
 
250
+ PRECISION_PLUS_CODEX =
251
+ T.let(
252
+ :precision_plus_codex,
253
+ Deeprails::MonitorSubmitEventParams::RunMode::TaggedSymbol
254
+ )
172
255
  PRECISION_PLUS =
173
256
  T.let(
174
257
  :precision_plus,
@@ -11,14 +11,41 @@ module Deeprails
11
11
  T.any(Deeprails::MonitorUpdateParams, Deeprails::Internal::AnyHash)
12
12
  end
13
13
 
14
- # Description of the monitor.
14
+ # New description of the monitor.
15
15
  sig { returns(T.nilable(String)) }
16
16
  attr_reader :description
17
17
 
18
18
  sig { params(description: String).void }
19
19
  attr_writer :description
20
20
 
21
- # Name of the monitor.
21
+ # An array of file IDs to search in the monitor's evaluations. Files must be
22
+ # uploaded via the DeepRails API first.
23
+ sig { returns(T.nilable(T::Array[String])) }
24
+ attr_reader :file_search
25
+
26
+ sig { params(file_search: T::Array[String]).void }
27
+ attr_writer :file_search
28
+
29
+ # An array of the new guardrail metrics that model input and output pairs will be
30
+ # evaluated on.
31
+ sig do
32
+ returns(
33
+ T.nilable(
34
+ T::Array[Deeprails::MonitorUpdateParams::GuardrailMetric::OrSymbol]
35
+ )
36
+ )
37
+ end
38
+ attr_reader :guardrail_metrics
39
+
40
+ sig do
41
+ params(
42
+ guardrail_metrics:
43
+ T::Array[Deeprails::MonitorUpdateParams::GuardrailMetric::OrSymbol]
44
+ ).void
45
+ end
46
+ attr_writer :guardrail_metrics
47
+
48
+ # New name of the monitor.
22
49
  sig { returns(T.nilable(String)) }
23
50
  attr_reader :name
24
51
 
@@ -37,22 +64,41 @@ module Deeprails
37
64
  end
38
65
  attr_writer :status
39
66
 
67
+ # Whether to enable web search for this monitor's evaluations.
68
+ sig { returns(T.nilable(T::Boolean)) }
69
+ attr_reader :web_search
70
+
71
+ sig { params(web_search: T::Boolean).void }
72
+ attr_writer :web_search
73
+
40
74
  sig do
41
75
  params(
42
76
  description: String,
77
+ file_search: T::Array[String],
78
+ guardrail_metrics:
79
+ T::Array[Deeprails::MonitorUpdateParams::GuardrailMetric::OrSymbol],
43
80
  name: String,
44
81
  status: Deeprails::MonitorUpdateParams::Status::OrSymbol,
82
+ web_search: T::Boolean,
45
83
  request_options: Deeprails::RequestOptions::OrHash
46
84
  ).returns(T.attached_class)
47
85
  end
48
86
  def self.new(
49
- # Description of the monitor.
87
+ # New description of the monitor.
50
88
  description: nil,
51
- # Name of the monitor.
89
+ # An array of file IDs to search in the monitor's evaluations. Files must be
90
+ # uploaded via the DeepRails API first.
91
+ file_search: nil,
92
+ # An array of the new guardrail metrics that model input and output pairs will be
93
+ # evaluated on.
94
+ guardrail_metrics: nil,
95
+ # New name of the monitor.
52
96
  name: nil,
53
97
  # Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
54
98
  # longer record and evaluate events.
55
99
  status: nil,
100
+ # Whether to enable web search for this monitor's evaluations.
101
+ web_search: nil,
56
102
  request_options: {}
57
103
  )
58
104
  end
@@ -61,8 +107,14 @@ module Deeprails
61
107
  override.returns(
62
108
  {
63
109
  description: String,
110
+ file_search: T::Array[String],
111
+ guardrail_metrics:
112
+ T::Array[
113
+ Deeprails::MonitorUpdateParams::GuardrailMetric::OrSymbol
114
+ ],
64
115
  name: String,
65
116
  status: Deeprails::MonitorUpdateParams::Status::OrSymbol,
117
+ web_search: T::Boolean,
66
118
  request_options: Deeprails::RequestOptions
67
119
  }
68
120
  )
@@ -70,6 +122,57 @@ module Deeprails
70
122
  def to_hash
71
123
  end
72
124
 
125
+ module GuardrailMetric
126
+ extend Deeprails::Internal::Type::Enum
127
+
128
+ TaggedSymbol =
129
+ T.type_alias do
130
+ T.all(Symbol, Deeprails::MonitorUpdateParams::GuardrailMetric)
131
+ end
132
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
133
+
134
+ CORRECTNESS =
135
+ T.let(
136
+ :correctness,
137
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
138
+ )
139
+ COMPLETENESS =
140
+ T.let(
141
+ :completeness,
142
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
143
+ )
144
+ INSTRUCTION_ADHERENCE =
145
+ T.let(
146
+ :instruction_adherence,
147
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
148
+ )
149
+ CONTEXT_ADHERENCE =
150
+ T.let(
151
+ :context_adherence,
152
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
153
+ )
154
+ GROUND_TRUTH_ADHERENCE =
155
+ T.let(
156
+ :ground_truth_adherence,
157
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
158
+ )
159
+ COMPREHENSIVE_SAFETY =
160
+ T.let(
161
+ :comprehensive_safety,
162
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
163
+ )
164
+
165
+ sig do
166
+ override.returns(
167
+ T::Array[
168
+ Deeprails::MonitorUpdateParams::GuardrailMetric::TaggedSymbol
169
+ ]
170
+ )
171
+ end
172
+ def self.values
173
+ end
174
+ end
175
+
73
176
  # Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
74
177
  # longer record and evaluate events.
75
178
  module Status