deeprails 1.10.0__py3-none-any.whl → 1.12.0__py3-none-any.whl

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.

Potentially problematic release.


This version of deeprails might be problematic. Click here for more details.

deeprails/_client.py CHANGED
@@ -21,7 +21,7 @@ from ._types import (
21
21
  )
22
22
  from ._utils import is_given, get_async_library
23
23
  from ._version import __version__
24
- from .resources import defend, monitor
24
+ from .resources import files, defend, monitor
25
25
  from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
26
  from ._exceptions import APIStatusError, DeeprailsError
27
27
  from ._base_client import (
@@ -45,6 +45,7 @@ __all__ = [
45
45
  class Deeprails(SyncAPIClient):
46
46
  defend: defend.DefendResource
47
47
  monitor: monitor.MonitorResource
48
+ files: files.FilesResource
48
49
  with_raw_response: DeeprailsWithRawResponse
49
50
  with_streaming_response: DeeprailsWithStreamedResponse
50
51
 
@@ -104,6 +105,7 @@ class Deeprails(SyncAPIClient):
104
105
 
105
106
  self.defend = defend.DefendResource(self)
106
107
  self.monitor = monitor.MonitorResource(self)
108
+ self.files = files.FilesResource(self)
107
109
  self.with_raw_response = DeeprailsWithRawResponse(self)
108
110
  self.with_streaming_response = DeeprailsWithStreamedResponse(self)
109
111
 
@@ -215,6 +217,7 @@ class Deeprails(SyncAPIClient):
215
217
  class AsyncDeeprails(AsyncAPIClient):
216
218
  defend: defend.AsyncDefendResource
217
219
  monitor: monitor.AsyncMonitorResource
220
+ files: files.AsyncFilesResource
218
221
  with_raw_response: AsyncDeeprailsWithRawResponse
219
222
  with_streaming_response: AsyncDeeprailsWithStreamedResponse
220
223
 
@@ -274,6 +277,7 @@ class AsyncDeeprails(AsyncAPIClient):
274
277
 
275
278
  self.defend = defend.AsyncDefendResource(self)
276
279
  self.monitor = monitor.AsyncMonitorResource(self)
280
+ self.files = files.AsyncFilesResource(self)
277
281
  self.with_raw_response = AsyncDeeprailsWithRawResponse(self)
278
282
  self.with_streaming_response = AsyncDeeprailsWithStreamedResponse(self)
279
283
 
@@ -386,24 +390,28 @@ class DeeprailsWithRawResponse:
386
390
  def __init__(self, client: Deeprails) -> None:
387
391
  self.defend = defend.DefendResourceWithRawResponse(client.defend)
388
392
  self.monitor = monitor.MonitorResourceWithRawResponse(client.monitor)
393
+ self.files = files.FilesResourceWithRawResponse(client.files)
389
394
 
390
395
 
391
396
  class AsyncDeeprailsWithRawResponse:
392
397
  def __init__(self, client: AsyncDeeprails) -> None:
393
398
  self.defend = defend.AsyncDefendResourceWithRawResponse(client.defend)
394
399
  self.monitor = monitor.AsyncMonitorResourceWithRawResponse(client.monitor)
400
+ self.files = files.AsyncFilesResourceWithRawResponse(client.files)
395
401
 
396
402
 
397
403
  class DeeprailsWithStreamedResponse:
398
404
  def __init__(self, client: Deeprails) -> None:
399
405
  self.defend = defend.DefendResourceWithStreamingResponse(client.defend)
400
406
  self.monitor = monitor.MonitorResourceWithStreamingResponse(client.monitor)
407
+ self.files = files.FilesResourceWithStreamingResponse(client.files)
401
408
 
402
409
 
403
410
  class AsyncDeeprailsWithStreamedResponse:
404
411
  def __init__(self, client: AsyncDeeprails) -> None:
405
412
  self.defend = defend.AsyncDefendResourceWithStreamingResponse(client.defend)
406
413
  self.monitor = monitor.AsyncMonitorResourceWithStreamingResponse(client.monitor)
414
+ self.files = files.AsyncFilesResourceWithStreamingResponse(client.files)
407
415
 
408
416
 
409
417
  Client = Deeprails
deeprails/_files.py CHANGED
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
34
34
  if not is_file_content(obj):
35
35
  prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
36
36
  raise RuntimeError(
37
- f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37
+ f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/deeprails/deeprails-sdk-python/tree/main#file-uploads"
38
38
  ) from None
39
39
 
40
40
 
deeprails/_streaming.py CHANGED
@@ -57,9 +57,8 @@ class Stream(Generic[_T]):
57
57
  for sse in iterator:
58
58
  yield process_data(data=sse.json(), cast_to=cast_to, response=response)
59
59
 
60
- # Ensure the entire stream is consumed
61
- for _sse in iterator:
62
- ...
60
+ # As we might not fully consume the response stream, we need to close it explicitly
61
+ response.close()
63
62
 
64
63
  def __enter__(self) -> Self:
65
64
  return self
@@ -121,9 +120,8 @@ class AsyncStream(Generic[_T]):
121
120
  async for sse in iterator:
122
121
  yield process_data(data=sse.json(), cast_to=cast_to, response=response)
123
122
 
124
- # Ensure the entire stream is consumed
125
- async for _sse in iterator:
126
- ...
123
+ # As we might not fully consume the response stream, we need to close it explicitly
124
+ await response.aclose()
127
125
 
128
126
  async def __aenter__(self) -> Self:
129
127
  return self
deeprails/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "deeprails"
4
- __version__ = "1.10.0" # x-release-please-version
4
+ __version__ = "1.12.0" # x-release-please-version
@@ -1,5 +1,13 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
+ from .files import (
4
+ FilesResource,
5
+ AsyncFilesResource,
6
+ FilesResourceWithRawResponse,
7
+ AsyncFilesResourceWithRawResponse,
8
+ FilesResourceWithStreamingResponse,
9
+ AsyncFilesResourceWithStreamingResponse,
10
+ )
3
11
  from .defend import (
4
12
  DefendResource,
5
13
  AsyncDefendResource,
@@ -30,4 +38,10 @@ __all__ = [
30
38
  "AsyncMonitorResourceWithRawResponse",
31
39
  "MonitorResourceWithStreamingResponse",
32
40
  "AsyncMonitorResourceWithStreamingResponse",
41
+ "FilesResource",
42
+ "AsyncFilesResource",
43
+ "FilesResourceWithRawResponse",
44
+ "AsyncFilesResourceWithRawResponse",
45
+ "FilesResourceWithStreamingResponse",
46
+ "AsyncFilesResourceWithStreamingResponse",
33
47
  ]
@@ -8,7 +8,7 @@ from typing_extensions import Literal
8
8
  import httpx
9
9
 
10
10
  from ..types import defend_submit_event_params, defend_create_workflow_params, defend_update_workflow_params
11
- from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
11
+ from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
12
12
  from .._utils import maybe_transform, async_maybe_transform
13
13
  from .._compat import cached_property
14
14
  from .._resource import SyncAPIResource, AsyncAPIResource
@@ -54,7 +54,9 @@ class DefendResource(SyncAPIResource):
54
54
  automatic_hallucination_tolerance_levels: Dict[str, Literal["low", "medium", "high"]] | Omit = omit,
55
55
  custom_hallucination_threshold_values: Dict[str, float] | Omit = omit,
56
56
  description: str | Omit = omit,
57
+ file_search: SequenceNotStr[str] | Omit = omit,
57
58
  max_improvement_attempts: int | Omit = omit,
59
+ web_search: bool | Omit = omit,
58
60
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
59
61
  # The extra values given here take precedence over values defined on the client or passed to this method.
60
62
  extra_headers: Headers | None = None,
@@ -92,9 +94,14 @@ class DefendResource(SyncAPIResource):
92
94
 
93
95
  description: Description for the workflow.
94
96
 
97
+ file_search: An array of file IDs to search in the workflow's evaluations. Files must be
98
+ uploaded via the DeepRails API first.
99
+
95
100
  max_improvement_attempts: Max. number of improvement action retries until a given event passes the
96
101
  guardrails. Defaults to 10.
97
102
 
103
+ web_search: Whether to enable web search for this workflow's evaluations. Defaults to false.
104
+
98
105
  extra_headers: Send extra headers
99
106
 
100
107
  extra_query: Add additional query parameters to the request
@@ -113,7 +120,9 @@ class DefendResource(SyncAPIResource):
113
120
  "automatic_hallucination_tolerance_levels": automatic_hallucination_tolerance_levels,
114
121
  "custom_hallucination_threshold_values": custom_hallucination_threshold_values,
115
122
  "description": description,
123
+ "file_search": file_search,
116
124
  "max_improvement_attempts": max_improvement_attempts,
125
+ "web_search": web_search,
117
126
  },
118
127
  defend_create_workflow_params.DefendCreateWorkflowParams,
119
128
  ),
@@ -332,7 +341,9 @@ class AsyncDefendResource(AsyncAPIResource):
332
341
  automatic_hallucination_tolerance_levels: Dict[str, Literal["low", "medium", "high"]] | Omit = omit,
333
342
  custom_hallucination_threshold_values: Dict[str, float] | Omit = omit,
334
343
  description: str | Omit = omit,
344
+ file_search: SequenceNotStr[str] | Omit = omit,
335
345
  max_improvement_attempts: int | Omit = omit,
346
+ web_search: bool | Omit = omit,
336
347
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
337
348
  # The extra values given here take precedence over values defined on the client or passed to this method.
338
349
  extra_headers: Headers | None = None,
@@ -370,9 +381,14 @@ class AsyncDefendResource(AsyncAPIResource):
370
381
 
371
382
  description: Description for the workflow.
372
383
 
384
+ file_search: An array of file IDs to search in the workflow's evaluations. Files must be
385
+ uploaded via the DeepRails API first.
386
+
373
387
  max_improvement_attempts: Max. number of improvement action retries until a given event passes the
374
388
  guardrails. Defaults to 10.
375
389
 
390
+ web_search: Whether to enable web search for this workflow's evaluations. Defaults to false.
391
+
376
392
  extra_headers: Send extra headers
377
393
 
378
394
  extra_query: Add additional query parameters to the request
@@ -391,7 +407,9 @@ class AsyncDefendResource(AsyncAPIResource):
391
407
  "automatic_hallucination_tolerance_levels": automatic_hallucination_tolerance_levels,
392
408
  "custom_hallucination_threshold_values": custom_hallucination_threshold_values,
393
409
  "description": description,
410
+ "file_search": file_search,
394
411
  "max_improvement_attempts": max_improvement_attempts,
412
+ "web_search": web_search,
395
413
  },
396
414
  defend_create_workflow_params.DefendCreateWorkflowParams,
397
415
  ),
@@ -0,0 +1,183 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Mapping, cast
6
+
7
+ import httpx
8
+
9
+ from ..types import file_upload_params
10
+ from .._types import Body, Query, Headers, NotGiven, FileTypes, not_given
11
+ from .._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
12
+ from .._compat import cached_property
13
+ from .._resource import SyncAPIResource, AsyncAPIResource
14
+ from .._response import (
15
+ to_raw_response_wrapper,
16
+ to_streamed_response_wrapper,
17
+ async_to_raw_response_wrapper,
18
+ async_to_streamed_response_wrapper,
19
+ )
20
+ from .._base_client import make_request_options
21
+ from ..types.file_response import FileResponse
22
+
23
+ __all__ = ["FilesResource", "AsyncFilesResource"]
24
+
25
+
26
+ class FilesResource(SyncAPIResource):
27
+ @cached_property
28
+ def with_raw_response(self) -> FilesResourceWithRawResponse:
29
+ """
30
+ This property can be used as a prefix for any HTTP method call to return
31
+ the raw response object instead of the parsed content.
32
+
33
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
34
+ """
35
+ return FilesResourceWithRawResponse(self)
36
+
37
+ @cached_property
38
+ def with_streaming_response(self) -> FilesResourceWithStreamingResponse:
39
+ """
40
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
41
+
42
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
43
+ """
44
+ return FilesResourceWithStreamingResponse(self)
45
+
46
+ def upload(
47
+ self,
48
+ *,
49
+ file: FileTypes,
50
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
51
+ # The extra values given here take precedence over values defined on the client or passed to this method.
52
+ extra_headers: Headers | None = None,
53
+ extra_query: Query | None = None,
54
+ extra_body: Body | None = None,
55
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
56
+ ) -> FileResponse:
57
+ """
58
+ Use this endpoint to upload a file to the DeepRails API
59
+
60
+ Args:
61
+ file: The contents of the file to upload.
62
+
63
+ extra_headers: Send extra headers
64
+
65
+ extra_query: Add additional query parameters to the request
66
+
67
+ extra_body: Add additional JSON properties to the request
68
+
69
+ timeout: Override the client-level default timeout for this request, in seconds
70
+ """
71
+ body = deepcopy_minimal({"file": file})
72
+ files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
73
+ # It should be noted that the actual Content-Type header that will be
74
+ # sent to the server will contain a `boundary` parameter, e.g.
75
+ # multipart/form-data; boundary=---abc--
76
+ extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
77
+ return self._post(
78
+ "/files/upload",
79
+ body=maybe_transform(body, file_upload_params.FileUploadParams),
80
+ files=files,
81
+ options=make_request_options(
82
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
83
+ ),
84
+ cast_to=FileResponse,
85
+ )
86
+
87
+
88
+ class AsyncFilesResource(AsyncAPIResource):
89
+ @cached_property
90
+ def with_raw_response(self) -> AsyncFilesResourceWithRawResponse:
91
+ """
92
+ This property can be used as a prefix for any HTTP method call to return
93
+ the raw response object instead of the parsed content.
94
+
95
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
96
+ """
97
+ return AsyncFilesResourceWithRawResponse(self)
98
+
99
+ @cached_property
100
+ def with_streaming_response(self) -> AsyncFilesResourceWithStreamingResponse:
101
+ """
102
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
103
+
104
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
105
+ """
106
+ return AsyncFilesResourceWithStreamingResponse(self)
107
+
108
+ async def upload(
109
+ self,
110
+ *,
111
+ file: FileTypes,
112
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
113
+ # The extra values given here take precedence over values defined on the client or passed to this method.
114
+ extra_headers: Headers | None = None,
115
+ extra_query: Query | None = None,
116
+ extra_body: Body | None = None,
117
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
118
+ ) -> FileResponse:
119
+ """
120
+ Use this endpoint to upload a file to the DeepRails API
121
+
122
+ Args:
123
+ file: The contents of the file to upload.
124
+
125
+ extra_headers: Send extra headers
126
+
127
+ extra_query: Add additional query parameters to the request
128
+
129
+ extra_body: Add additional JSON properties to the request
130
+
131
+ timeout: Override the client-level default timeout for this request, in seconds
132
+ """
133
+ body = deepcopy_minimal({"file": file})
134
+ files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
135
+ # It should be noted that the actual Content-Type header that will be
136
+ # sent to the server will contain a `boundary` parameter, e.g.
137
+ # multipart/form-data; boundary=---abc--
138
+ extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
139
+ return await self._post(
140
+ "/files/upload",
141
+ body=await async_maybe_transform(body, file_upload_params.FileUploadParams),
142
+ files=files,
143
+ options=make_request_options(
144
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
145
+ ),
146
+ cast_to=FileResponse,
147
+ )
148
+
149
+
150
+ class FilesResourceWithRawResponse:
151
+ def __init__(self, files: FilesResource) -> None:
152
+ self._files = files
153
+
154
+ self.upload = to_raw_response_wrapper(
155
+ files.upload,
156
+ )
157
+
158
+
159
+ class AsyncFilesResourceWithRawResponse:
160
+ def __init__(self, files: AsyncFilesResource) -> None:
161
+ self._files = files
162
+
163
+ self.upload = async_to_raw_response_wrapper(
164
+ files.upload,
165
+ )
166
+
167
+
168
+ class FilesResourceWithStreamingResponse:
169
+ def __init__(self, files: FilesResource) -> None:
170
+ self._files = files
171
+
172
+ self.upload = to_streamed_response_wrapper(
173
+ files.upload,
174
+ )
175
+
176
+
177
+ class AsyncFilesResourceWithStreamingResponse:
178
+ def __init__(self, files: AsyncFilesResource) -> None:
179
+ self._files = files
180
+
181
+ self.upload = async_to_streamed_response_wrapper(
182
+ files.upload,
183
+ )
@@ -8,7 +8,7 @@ from typing_extensions import Literal
8
8
  import httpx
9
9
 
10
10
  from ..types import monitor_create_params, monitor_update_params, monitor_retrieve_params, monitor_submit_event_params
11
- from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
11
+ from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
12
12
  from .._utils import maybe_transform, async_maybe_transform
13
13
  from .._compat import cached_property
14
14
  from .._resource import SyncAPIResource, AsyncAPIResource
@@ -49,8 +49,20 @@ class MonitorResource(SyncAPIResource):
49
49
  def create(
50
50
  self,
51
51
  *,
52
+ guardrail_metrics: List[
53
+ Literal[
54
+ "correctness",
55
+ "completeness",
56
+ "instruction_adherence",
57
+ "context_adherence",
58
+ "ground_truth_adherence",
59
+ "comprehensive_safety",
60
+ ]
61
+ ],
52
62
  name: str,
53
63
  description: str | Omit = omit,
64
+ file_search: SequenceNotStr[str] | Omit = omit,
65
+ web_search: bool | Omit = omit,
54
66
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
55
67
  # The extra values given here take precedence over values defined on the client or passed to this method.
56
68
  extra_headers: Headers | None = None,
@@ -63,10 +75,20 @@ class MonitorResource(SyncAPIResource):
63
75
  using guardrails
64
76
 
65
77
  Args:
78
+ guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
79
+ evaluated on. For non-enterprise users, these will be limited to `correctness`,
80
+ `completeness`, `instruction_adherence`, `context_adherence`,
81
+ `ground_truth_adherence`, and/or `comprehensive_safety`.
82
+
66
83
  name: Name of the new monitor.
67
84
 
68
85
  description: Description of the new monitor.
69
86
 
87
+ file_search: An array of file IDs to search in the monitor's evaluations. Files must be
88
+ uploaded via the DeepRails API first.
89
+
90
+ web_search: Whether to enable web search for this monitor's evaluations. Defaults to false.
91
+
70
92
  extra_headers: Send extra headers
71
93
 
72
94
  extra_query: Add additional query parameters to the request
@@ -79,8 +101,11 @@ class MonitorResource(SyncAPIResource):
79
101
  "/monitor",
80
102
  body=maybe_transform(
81
103
  {
104
+ "guardrail_metrics": guardrail_metrics,
82
105
  "name": name,
83
106
  "description": description,
107
+ "file_search": file_search,
108
+ "web_search": web_search,
84
109
  },
85
110
  monitor_create_params.MonitorCreateParams,
86
111
  ),
@@ -187,19 +212,8 @@ class MonitorResource(SyncAPIResource):
187
212
  self,
188
213
  monitor_id: str,
189
214
  *,
190
- guardrail_metrics: List[
191
- Literal[
192
- "correctness",
193
- "completeness",
194
- "instruction_adherence",
195
- "context_adherence",
196
- "ground_truth_adherence",
197
- "comprehensive_safety",
198
- ]
199
- ],
200
215
  model_input: monitor_submit_event_params.ModelInput,
201
216
  model_output: str,
202
- model_used: str | Omit = omit,
203
217
  nametag: str | Omit = omit,
204
218
  run_mode: Literal["precision_plus", "precision", "smart", "economy"] | Omit = omit,
205
219
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -214,19 +228,12 @@ class MonitorResource(SyncAPIResource):
214
228
  evaluation
215
229
 
216
230
  Args:
217
- guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
218
- evaluated on. For non-enterprise users, these will be limited to `correctness`,
219
- `completeness`, `instruction_adherence`, `context_adherence`,
220
- `ground_truth_adherence`, and/or `comprehensive_safety`.
221
-
222
231
  model_input: A dictionary of inputs sent to the LLM to generate output. The dictionary must
223
232
  contain at least a `user_prompt` field or a `system_prompt` field. For
224
233
  ground_truth_adherence guardrail metric, `ground_truth` should be provided.
225
234
 
226
235
  model_output: Output generated by the LLM to be evaluated.
227
236
 
228
- model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
229
-
230
237
  nametag: An optional, user-defined tag for the event.
231
238
 
232
239
  run_mode: Run mode for the monitor event. The run mode allows the user to optimize for
@@ -248,10 +255,8 @@ class MonitorResource(SyncAPIResource):
248
255
  f"/monitor/{monitor_id}/events",
249
256
  body=maybe_transform(
250
257
  {
251
- "guardrail_metrics": guardrail_metrics,
252
258
  "model_input": model_input,
253
259
  "model_output": model_output,
254
- "model_used": model_used,
255
260
  "nametag": nametag,
256
261
  "run_mode": run_mode,
257
262
  },
@@ -287,8 +292,20 @@ class AsyncMonitorResource(AsyncAPIResource):
287
292
  async def create(
288
293
  self,
289
294
  *,
295
+ guardrail_metrics: List[
296
+ Literal[
297
+ "correctness",
298
+ "completeness",
299
+ "instruction_adherence",
300
+ "context_adherence",
301
+ "ground_truth_adherence",
302
+ "comprehensive_safety",
303
+ ]
304
+ ],
290
305
  name: str,
291
306
  description: str | Omit = omit,
307
+ file_search: SequenceNotStr[str] | Omit = omit,
308
+ web_search: bool | Omit = omit,
292
309
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
293
310
  # The extra values given here take precedence over values defined on the client or passed to this method.
294
311
  extra_headers: Headers | None = None,
@@ -301,10 +318,20 @@ class AsyncMonitorResource(AsyncAPIResource):
301
318
  using guardrails
302
319
 
303
320
  Args:
321
+ guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
322
+ evaluated on. For non-enterprise users, these will be limited to `correctness`,
323
+ `completeness`, `instruction_adherence`, `context_adherence`,
324
+ `ground_truth_adherence`, and/or `comprehensive_safety`.
325
+
304
326
  name: Name of the new monitor.
305
327
 
306
328
  description: Description of the new monitor.
307
329
 
330
+ file_search: An array of file IDs to search in the monitor's evaluations. Files must be
331
+ uploaded via the DeepRails API first.
332
+
333
+ web_search: Whether to enable web search for this monitor's evaluations. Defaults to false.
334
+
308
335
  extra_headers: Send extra headers
309
336
 
310
337
  extra_query: Add additional query parameters to the request
@@ -317,8 +344,11 @@ class AsyncMonitorResource(AsyncAPIResource):
317
344
  "/monitor",
318
345
  body=await async_maybe_transform(
319
346
  {
347
+ "guardrail_metrics": guardrail_metrics,
320
348
  "name": name,
321
349
  "description": description,
350
+ "file_search": file_search,
351
+ "web_search": web_search,
322
352
  },
323
353
  monitor_create_params.MonitorCreateParams,
324
354
  ),
@@ -425,19 +455,8 @@ class AsyncMonitorResource(AsyncAPIResource):
425
455
  self,
426
456
  monitor_id: str,
427
457
  *,
428
- guardrail_metrics: List[
429
- Literal[
430
- "correctness",
431
- "completeness",
432
- "instruction_adherence",
433
- "context_adherence",
434
- "ground_truth_adherence",
435
- "comprehensive_safety",
436
- ]
437
- ],
438
458
  model_input: monitor_submit_event_params.ModelInput,
439
459
  model_output: str,
440
- model_used: str | Omit = omit,
441
460
  nametag: str | Omit = omit,
442
461
  run_mode: Literal["precision_plus", "precision", "smart", "economy"] | Omit = omit,
443
462
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -452,19 +471,12 @@ class AsyncMonitorResource(AsyncAPIResource):
452
471
  evaluation
453
472
 
454
473
  Args:
455
- guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
456
- evaluated on. For non-enterprise users, these will be limited to `correctness`,
457
- `completeness`, `instruction_adherence`, `context_adherence`,
458
- `ground_truth_adherence`, and/or `comprehensive_safety`.
459
-
460
474
  model_input: A dictionary of inputs sent to the LLM to generate output. The dictionary must
461
475
  contain at least a `user_prompt` field or a `system_prompt` field. For
462
476
  ground_truth_adherence guardrail metric, `ground_truth` should be provided.
463
477
 
464
478
  model_output: Output generated by the LLM to be evaluated.
465
479
 
466
- model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
467
-
468
480
  nametag: An optional, user-defined tag for the event.
469
481
 
470
482
  run_mode: Run mode for the monitor event. The run mode allows the user to optimize for
@@ -486,10 +498,8 @@ class AsyncMonitorResource(AsyncAPIResource):
486
498
  f"/monitor/{monitor_id}/events",
487
499
  body=await async_maybe_transform(
488
500
  {
489
- "guardrail_metrics": guardrail_metrics,
490
501
  "model_input": model_input,
491
502
  "model_output": model_output,
492
- "model_used": model_used,
493
503
  "nametag": nametag,
494
504
  "run_mode": run_mode,
495
505
  },
@@ -2,8 +2,10 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from .file_response import FileResponse as FileResponse
5
6
  from .defend_response import DefendResponse as DefendResponse
6
7
  from .monitor_response import MonitorResponse as MonitorResponse
8
+ from .file_upload_params import FileUploadParams as FileUploadParams
7
9
  from .monitor_create_params import MonitorCreateParams as MonitorCreateParams
8
10
  from .monitor_update_params import MonitorUpdateParams as MonitorUpdateParams
9
11
  from .monitor_event_response import MonitorEventResponse as MonitorEventResponse
@@ -5,6 +5,8 @@ from __future__ import annotations
5
5
  from typing import Dict
6
6
  from typing_extensions import Literal, Required, TypedDict
7
7
 
8
+ from .._types import SequenceNotStr
9
+
8
10
  __all__ = ["DefendCreateWorkflowParams"]
9
11
 
10
12
 
@@ -48,9 +50,21 @@ class DefendCreateWorkflowParams(TypedDict, total=False):
48
50
  description: str
49
51
  """Description for the workflow."""
50
52
 
53
+ file_search: SequenceNotStr[str]
54
+ """An array of file IDs to search in the workflow's evaluations.
55
+
56
+ Files must be uploaded via the DeepRails API first.
57
+ """
58
+
51
59
  max_improvement_attempts: int
52
60
  """Max.
53
61
 
54
62
  number of improvement action retries until a given event passes the guardrails.
55
63
  Defaults to 10.
56
64
  """
65
+
66
+ web_search: bool
67
+ """Whether to enable web search for this workflow's evaluations.
68
+
69
+ Defaults to false.
70
+ """
@@ -0,0 +1,25 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+ from datetime import datetime
5
+
6
+ from .._models import BaseModel
7
+
8
+ __all__ = ["FileResponse"]
9
+
10
+
11
+ class FileResponse(BaseModel):
12
+ created_at: Optional[datetime] = None
13
+ """The time the file was created in UTC."""
14
+
15
+ file_id: Optional[str] = None
16
+ """A unique file ID."""
17
+
18
+ file_name: Optional[str] = None
19
+ """Name of the file."""
20
+
21
+ file_path: Optional[str] = None
22
+ """Path to the s3 bucket where the file is stored."""
23
+
24
+ updated_at: Optional[datetime] = None
25
+ """The most recent time the file was modified in UTC."""
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Required, TypedDict
6
+
7
+ from .._types import FileTypes
8
+
9
+ __all__ = ["FileUploadParams"]
10
+
11
+
12
+ class FileUploadParams(TypedDict, total=False):
13
+ file: Required[FileTypes]
14
+ """The contents of the file to upload."""
@@ -2,14 +2,45 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing_extensions import Required, TypedDict
5
+ from typing import List
6
+ from typing_extensions import Literal, Required, TypedDict
7
+
8
+ from .._types import SequenceNotStr
6
9
 
7
10
  __all__ = ["MonitorCreateParams"]
8
11
 
9
12
 
10
13
  class MonitorCreateParams(TypedDict, total=False):
14
+ guardrail_metrics: Required[
15
+ List[
16
+ Literal[
17
+ "correctness",
18
+ "completeness",
19
+ "instruction_adherence",
20
+ "context_adherence",
21
+ "ground_truth_adherence",
22
+ "comprehensive_safety",
23
+ ]
24
+ ]
25
+ ]
26
+ """
27
+ An array of guardrail metrics that the model input and output pair will be
28
+ evaluated on. For non-enterprise users, these will be limited to `correctness`,
29
+ `completeness`, `instruction_adherence`, `context_adherence`,
30
+ `ground_truth_adherence`, and/or `comprehensive_safety`.
31
+ """
32
+
11
33
  name: Required[str]
12
34
  """Name of the new monitor."""
13
35
 
14
36
  description: str
15
37
  """Description of the new monitor."""
38
+
39
+ file_search: SequenceNotStr[str]
40
+ """An array of file IDs to search in the monitor's evaluations.
41
+
42
+ Files must be uploaded via the DeepRails API first.
43
+ """
44
+
45
+ web_search: bool
46
+ """Whether to enable web search for this monitor's evaluations. Defaults to false."""
@@ -2,32 +2,12 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import List
6
5
  from typing_extensions import Literal, Required, TypedDict
7
6
 
8
7
  __all__ = ["MonitorSubmitEventParams", "ModelInput"]
9
8
 
10
9
 
11
10
  class MonitorSubmitEventParams(TypedDict, total=False):
12
- guardrail_metrics: Required[
13
- List[
14
- Literal[
15
- "correctness",
16
- "completeness",
17
- "instruction_adherence",
18
- "context_adherence",
19
- "ground_truth_adherence",
20
- "comprehensive_safety",
21
- ]
22
- ]
23
- ]
24
- """
25
- An array of guardrail metrics that the model input and output pair will be
26
- evaluated on. For non-enterprise users, these will be limited to `correctness`,
27
- `completeness`, `instruction_adherence`, `context_adherence`,
28
- `ground_truth_adherence`, and/or `comprehensive_safety`.
29
- """
30
-
31
11
  model_input: Required[ModelInput]
32
12
  """A dictionary of inputs sent to the LLM to generate output.
33
13
 
@@ -39,9 +19,6 @@ class MonitorSubmitEventParams(TypedDict, total=False):
39
19
  model_output: Required[str]
40
20
  """Output generated by the LLM to be evaluated."""
41
21
 
42
- model_used: str
43
- """Model ID used to generate the output, like `gpt-4o` or `o3`."""
44
-
45
22
  nametag: str
46
23
  """An optional, user-defined tag for the event."""
47
24
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: deeprails
3
- Version: 1.10.0
3
+ Version: 1.12.0
4
4
  Summary: The official Python library for the deeprails API
5
5
  Project-URL: Homepage, https://docs.deeprails.com/
6
6
  Project-URL: Repository, https://github.com/deeprails/deeprails-sdk-python
@@ -181,6 +181,23 @@ workflow_event_response = client.defend.submit_event(
181
181
  print(workflow_event_response.model_input)
182
182
  ```
183
183
 
184
+ ## File uploads
185
+
186
+ Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
187
+
188
+ ```python
189
+ from pathlib import Path
190
+ from deeprails import Deeprails
191
+
192
+ client = Deeprails()
193
+
194
+ client.files.upload(
195
+ file=Path("/path/to/file"),
196
+ )
197
+ ```
198
+
199
+ The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
200
+
184
201
  ## Handling errors
185
202
 
186
203
  When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `deeprails.APIConnectionError` is raised.
@@ -1,17 +1,17 @@
1
1
  deeprails/__init__.py,sha256=Rz38DnPkRJzvTJjgsLPjYyEId-pJndorgdE4Yhcq0J4,2692
2
2
  deeprails/_base_client.py,sha256=3bTH_cn_59gEjfZdcRS6g6Er4ZobAgTCRsnQmD_viNQ,67050
3
- deeprails/_client.py,sha256=BzJOTEiC2RszdX3GCBEk_R5k6e48rzP-XlbCN1Cplr4,15563
3
+ deeprails/_client.py,sha256=YIvCXcVFQjZcY7I_xynUci6w9UqJn76exF293tU3uaI,16038
4
4
  deeprails/_compat.py,sha256=DQBVORjFb33zch24jzkhM14msvnzY7mmSmgDLaVFUM8,6562
5
5
  deeprails/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
6
6
  deeprails/_exceptions.py,sha256=N99bKrZNjDzgEDrvdw99WO-zpuPeZySaUUKNLEUz8mU,3226
7
- deeprails/_files.py,sha256=KnEzGi_O756MvKyJ4fOCW_u3JhOeWPQ4RsmDvqihDQU,3545
7
+ deeprails/_files.py,sha256=yYKwrIipJBVzGNimPEwe__wofI3Xz9tQkDXHhVIGR7U,3622
8
8
  deeprails/_models.py,sha256=lKnskYPONAWDvWo8tmbbVk7HmG7UOsI0Nve0vSMmkRc,30452
9
9
  deeprails/_qs.py,sha256=craIKyvPktJ94cvf9zn8j8ekG9dWJzhWv0ob34lIOv4,4828
10
10
  deeprails/_resource.py,sha256=7RXX5KZr4j0TIE66vnduHp7p9Yf9X0FyDDECuvRHARg,1118
11
11
  deeprails/_response.py,sha256=yj0HJDU91WPpiczwi6CBOLAl_bqf4I_I96vWMAwx6Fg,28806
12
- deeprails/_streaming.py,sha256=hCp5bK9dyw2TyrVL69m-6qGC-QtGYwhXmFzITCWPgAs,10112
12
+ deeprails/_streaming.py,sha256=Q6e6KLMPe7Pe4AWnbiC5pDrbRRIaNUh0svOWpWXLheY,10161
13
13
  deeprails/_types.py,sha256=XR3mad9NsGqZsjrd1VVJ657-4O4kwyw9Qzg4M3i6Vh0,7239
14
- deeprails/_version.py,sha256=dE6ROKmhSXt4B73GxgSswrtaxSRJBdQihEVLUUaQ-M0,162
14
+ deeprails/_version.py,sha256=Lu9BU95-FlOx4Vp5TnTzo6mRfvfmbANoTKPP3Y24uck,162
15
15
  deeprails/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  deeprails/_utils/__init__.py,sha256=7fch0GT9zpNnErbciSpUNa-SjTxxjY6kxHxKMOM4AGs,2305
17
17
  deeprails/_utils/_compat.py,sha256=D8gtAvjJQrDWt9upS0XaG9Rr5l1QhiAx_I_1utT_tt0,1195
@@ -26,23 +26,26 @@ deeprails/_utils/_transform.py,sha256=NjCzmnfqYrsAikUHQig6N9QfuTVbKipuP3ur9mcNF-
26
26
  deeprails/_utils/_typing.py,sha256=N_5PPuFNsaygbtA_npZd98SVN1LQQvFTKL6bkWPBZGU,4786
27
27
  deeprails/_utils/_utils.py,sha256=0dDqauUbVZEXV0NVl7Bwu904Wwo5eyFCZpQThhFNhyA,12253
28
28
  deeprails/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
29
- deeprails/resources/__init__.py,sha256=JBzEBVMLg2n1w2QJGYCsyjPHY6zHZ0G3xaWuuFoa5Pg,1015
30
- deeprails/resources/defend.py,sha256=e6NzUJziYx__FkGSVNeaqzA8sZU0L5dY5Nob1IPCxc4,28186
31
- deeprails/resources/monitor.py,sha256=bW7HCn8lDpWqaPd11J_tVnGSduWTX3sfXlDYYycvk8k,22524
32
- deeprails/types/__init__.py,sha256=PlF7idbYiAj3xyJYstHDaBer-rLUHe6eUEfRfJKisvk,1124
33
- deeprails/types/defend_create_workflow_params.py,sha256=AmyoU1z3a0U39pqVtVnFsM86ysK1nYIx15Tolwb4PKA,2102
29
+ deeprails/resources/__init__.py,sha256=VyIb1MX_ovlwJo6XAW_ZN9Ib0Ea-Oapbs5Hfwx0o_IY,1452
30
+ deeprails/resources/defend.py,sha256=Ztcn4OEw8GIhlXx1QHIzIdnNP2obeIhmeEmvNyVza2g,29094
31
+ deeprails/resources/files.py,sha256=zHtuxEm-t9MMdbH7gQcDQat3qXPh1ABWDmqxrUY2a8k,6903
32
+ deeprails/resources/monitor.py,sha256=4X6c4yPJ4ZZZXd2ViTdHpa5cCXrbd6Mg34Riz2SYerM,23090
33
+ deeprails/types/__init__.py,sha256=h4_LUTZM98zsmfk3ziFmihgjQO_DI41gbgx2xVOGy78,1249
34
+ deeprails/types/defend_create_workflow_params.py,sha256=gVK6ORTsvo3ur4Inyq6dU0rN7F9RyNnm4SFfQyyO5ZU,2434
34
35
  deeprails/types/defend_response.py,sha256=VoePIT9RKN795y-3ZvoFmzSTCetqkZZh6iQLYjJEFoY,1603
35
36
  deeprails/types/defend_submit_event_params.py,sha256=yL_rLUGKlZjXHGbdi8h9ZItb4sICQ2POO_o0VbUtans,1539
36
37
  deeprails/types/defend_update_workflow_params.py,sha256=QH2k7EDMLub3mW1lPV5SUoKDHW_T2arSo-RGHLterwo,373
37
- deeprails/types/monitor_create_params.py,sha256=kTSj-PhuzpT-HPDTQJemRWfd8w32foUMH9FQZj8symk,384
38
+ deeprails/types/file_response.py,sha256=8RAkrlfgt9d27ryd4qMf6gHi_gTsD3LhDen2MtxYZ-I,656
39
+ deeprails/types/file_upload_params.py,sha256=64xHtKiy39dFANWYBWeqK5eeOJV-zxJejwNjXY7kW8E,363
40
+ deeprails/types/monitor_create_params.py,sha256=uU_wqGLAo9B4r-nFZw_UG5YbUF0hxIJf0_P5HqpOIw8,1365
38
41
  deeprails/types/monitor_detail_response.py,sha256=s8dzFFaU9uI-GHCfUxCN9yLhpmq4LTu7CSww9z0SLvk,5028
39
42
  deeprails/types/monitor_event_response.py,sha256=-cnugHD_3QeeZRMbo6aQBirqSPgKIKpaD2qNkgxCeCA,565
40
43
  deeprails/types/monitor_response.py,sha256=LjnJVYniee1hgvZu8RT-9jX4xd0Ob_yvq4NBOxVn59c,950
41
44
  deeprails/types/monitor_retrieve_params.py,sha256=PEsRmbd-81z4pJvhfi4JbrQWNzmeiLkoNsTUoPZ6kFY,352
42
- deeprails/types/monitor_submit_event_params.py,sha256=YetTV8HzmDGNnSYoKZp8tv3u9L6oYn4tnvWOppTRfOQ,2164
45
+ deeprails/types/monitor_submit_event_params.py,sha256=D6ecLaN7y4Y3q7PI2qplXpItXN5dmrasjrdTumjLnHc,1420
43
46
  deeprails/types/monitor_update_params.py,sha256=gJyFFxT_u_iWABknuKnLpPl9r-VPfCcGtOAmh6sPwUw,550
44
47
  deeprails/types/workflow_event_response.py,sha256=mIzOCnYJg4TDSq_tG_0WfA0_Gmc9-0q-befyookfUFM,867
45
- deeprails-1.10.0.dist-info/METADATA,sha256=oMlAwTn3V1FCFTw1ErsGTS_clu3q1dtpn3vQAssiJv0,12081
46
- deeprails-1.10.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
47
- deeprails-1.10.0.dist-info/licenses/LICENSE,sha256=rFTxPcYE516UQLju2SCY1r2pSDDfodL0-ZvxF_fgueg,11339
48
- deeprails-1.10.0.dist-info/RECORD,,
48
+ deeprails-1.12.0.dist-info/METADATA,sha256=iR51Ti99Htf03ehr-ygjOzattoN9tc2dKw78QSbiV1A,12660
49
+ deeprails-1.12.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
50
+ deeprails-1.12.0.dist-info/licenses/LICENSE,sha256=rFTxPcYE516UQLju2SCY1r2pSDDfodL0-ZvxF_fgueg,11339
51
+ deeprails-1.12.0.dist-info/RECORD,,