deeprails 0.3.2__py3-none-any.whl → 1.2.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.
Files changed (57) hide show
  1. deeprails/__init__.py +102 -1
  2. deeprails/_base_client.py +1995 -0
  3. deeprails/_client.py +419 -0
  4. deeprails/_compat.py +219 -0
  5. deeprails/_constants.py +14 -0
  6. deeprails/_exceptions.py +108 -0
  7. deeprails/_files.py +123 -0
  8. deeprails/_models.py +835 -0
  9. deeprails/_qs.py +150 -0
  10. deeprails/_resource.py +43 -0
  11. deeprails/_response.py +830 -0
  12. deeprails/_streaming.py +333 -0
  13. deeprails/_types.py +260 -0
  14. deeprails/_utils/__init__.py +64 -0
  15. deeprails/_utils/_compat.py +45 -0
  16. deeprails/_utils/_datetime_parse.py +136 -0
  17. deeprails/_utils/_logs.py +25 -0
  18. deeprails/_utils/_proxy.py +65 -0
  19. deeprails/_utils/_reflection.py +42 -0
  20. deeprails/_utils/_resources_proxy.py +24 -0
  21. deeprails/_utils/_streams.py +12 -0
  22. deeprails/_utils/_sync.py +86 -0
  23. deeprails/_utils/_transform.py +457 -0
  24. deeprails/_utils/_typing.py +156 -0
  25. deeprails/_utils/_utils.py +421 -0
  26. deeprails/_version.py +4 -0
  27. deeprails/lib/.keep +4 -0
  28. deeprails/py.typed +0 -0
  29. deeprails/resources/__init__.py +47 -0
  30. deeprails/resources/defend.py +671 -0
  31. deeprails/resources/evaluate.py +334 -0
  32. deeprails/resources/monitor.py +566 -0
  33. deeprails/types/__init__.py +18 -0
  34. deeprails/types/api_response.py +50 -0
  35. deeprails/types/defend_create_workflow_params.py +56 -0
  36. deeprails/types/defend_response.py +50 -0
  37. deeprails/types/defend_submit_event_params.py +44 -0
  38. deeprails/types/defend_update_workflow_params.py +18 -0
  39. deeprails/types/evaluate_create_params.py +60 -0
  40. deeprails/types/evaluation.py +113 -0
  41. deeprails/types/monitor_create_params.py +15 -0
  42. deeprails/types/monitor_retrieve_params.py +12 -0
  43. deeprails/types/monitor_retrieve_response.py +81 -0
  44. deeprails/types/monitor_submit_event_params.py +63 -0
  45. deeprails/types/monitor_submit_event_response.py +36 -0
  46. deeprails/types/monitor_update_params.py +22 -0
  47. deeprails/types/workflow_event_response.py +33 -0
  48. deeprails-1.2.0.dist-info/METADATA +377 -0
  49. deeprails-1.2.0.dist-info/RECORD +51 -0
  50. {deeprails-0.3.2.dist-info → deeprails-1.2.0.dist-info}/WHEEL +1 -1
  51. deeprails-1.2.0.dist-info/licenses/LICENSE +201 -0
  52. deeprails/client.py +0 -285
  53. deeprails/exceptions.py +0 -10
  54. deeprails/schemas.py +0 -92
  55. deeprails-0.3.2.dist-info/METADATA +0 -235
  56. deeprails-0.3.2.dist-info/RECORD +0 -8
  57. deeprails-0.3.2.dist-info/licenses/LICENSE +0 -11
@@ -0,0 +1,671 @@
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 Dict, Optional
6
+ from typing_extensions import Literal
7
+
8
+ import httpx
9
+
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
12
+ from .._utils import maybe_transform, async_maybe_transform
13
+ from .._compat import cached_property
14
+ from .._resource import SyncAPIResource, AsyncAPIResource
15
+ from .._response import (
16
+ to_raw_response_wrapper,
17
+ to_streamed_response_wrapper,
18
+ async_to_raw_response_wrapper,
19
+ async_to_streamed_response_wrapper,
20
+ )
21
+ from .._base_client import make_request_options
22
+ from ..types.defend_response import DefendResponse
23
+ from ..types.workflow_event_response import WorkflowEventResponse
24
+
25
+ __all__ = ["DefendResource", "AsyncDefendResource"]
26
+
27
+
28
+ class DefendResource(SyncAPIResource):
29
+ @cached_property
30
+ def with_raw_response(self) -> DefendResourceWithRawResponse:
31
+ """
32
+ This property can be used as a prefix for any HTTP method call to return
33
+ the raw response object instead of the parsed content.
34
+
35
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
36
+ """
37
+ return DefendResourceWithRawResponse(self)
38
+
39
+ @cached_property
40
+ def with_streaming_response(self) -> DefendResourceWithStreamingResponse:
41
+ """
42
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
43
+
44
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
45
+ """
46
+ return DefendResourceWithStreamingResponse(self)
47
+
48
+ def create_workflow(
49
+ self,
50
+ *,
51
+ improvement_action: Optional[Literal["regenerate", "fixit"]],
52
+ metrics: Dict[str, float],
53
+ name: str,
54
+ type: Literal["automatic", "custom"],
55
+ automatic_tolerance: Literal["low", "medium", "high"] | Omit = omit,
56
+ description: str | Omit = omit,
57
+ max_retries: int | Omit = omit,
58
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
59
+ # The extra values given here take precedence over values defined on the client or passed to this method.
60
+ extra_headers: Headers | None = None,
61
+ extra_query: Query | None = None,
62
+ extra_body: Body | None = None,
63
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
64
+ ) -> DefendResponse:
65
+ """
66
+ Create a new guardrail workflow with optional guardrail thresholds and
67
+ improvement actions.
68
+
69
+ Args:
70
+ improvement_action: The action used to improve outputs that fail one or guardrail metrics for the
71
+ workflow events. May be `regenerate`, `fixit`, or null which represents “do
72
+ nothing”. ReGen runs the user's exact input prompt with minor induced variance.
73
+ Fixit attempts to directly address the shortcomings of the output using the
74
+ guardrail failure rationale. Do nothing does not attempt any improvement.
75
+
76
+ metrics: Mapping of guardrail metrics to floating point threshold values. If the workflow
77
+ type is automatic, only the metric names are used (`automatic_tolerance`
78
+ determines thresholds). Possible metrics are `correctness`, `completeness`,
79
+ `instruction_adherence`, `context_adherence`, `ground_truth_adherence`, or
80
+ `comprehensive_safety`.
81
+
82
+ name: Name of the workflow.
83
+
84
+ type: Type of thresholds to use for the workflow, either `automatic` or `custom`.
85
+ Automatic thresholds are assigned internally after the user specifies a
86
+ qualitative tolerance for the metrics, whereas custom metrics allow the user to
87
+ set the threshold for each metric as a floating point number between 0.0 and
88
+ 1.0.
89
+
90
+ automatic_tolerance: Hallucination tolerance for automatic workflows; may be `low`, `medium`, or
91
+ `high`. Ignored if `type` is `custom`.
92
+
93
+ description: Description for the workflow.
94
+
95
+ max_retries: Max. number of improvement action retries until a given event passes the
96
+ guardrails. Defaults to 10.
97
+
98
+ extra_headers: Send extra headers
99
+
100
+ extra_query: Add additional query parameters to the request
101
+
102
+ extra_body: Add additional JSON properties to the request
103
+
104
+ timeout: Override the client-level default timeout for this request, in seconds
105
+ """
106
+ return self._post(
107
+ "/defend",
108
+ body=maybe_transform(
109
+ {
110
+ "improvement_action": improvement_action,
111
+ "metrics": metrics,
112
+ "name": name,
113
+ "type": type,
114
+ "automatic_tolerance": automatic_tolerance,
115
+ "description": description,
116
+ "max_retries": max_retries,
117
+ },
118
+ defend_create_workflow_params.DefendCreateWorkflowParams,
119
+ ),
120
+ options=make_request_options(
121
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
122
+ ),
123
+ cast_to=DefendResponse,
124
+ )
125
+
126
+ def retrieve_event(
127
+ self,
128
+ event_id: str,
129
+ *,
130
+ workflow_id: str,
131
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
132
+ # The extra values given here take precedence over values defined on the client or passed to this method.
133
+ extra_headers: Headers | None = None,
134
+ extra_query: Query | None = None,
135
+ extra_body: Body | None = None,
136
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
137
+ ) -> WorkflowEventResponse:
138
+ """
139
+ Retrieve a specific event of a guardrail workflow.
140
+
141
+ Args:
142
+ extra_headers: Send extra headers
143
+
144
+ extra_query: Add additional query parameters to the request
145
+
146
+ extra_body: Add additional JSON properties to the request
147
+
148
+ timeout: Override the client-level default timeout for this request, in seconds
149
+ """
150
+ if not workflow_id:
151
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
152
+ if not event_id:
153
+ raise ValueError(f"Expected a non-empty value for `event_id` but received {event_id!r}")
154
+ return self._get(
155
+ f"/defend/{workflow_id}/events/{event_id}",
156
+ options=make_request_options(
157
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
158
+ ),
159
+ cast_to=WorkflowEventResponse,
160
+ )
161
+
162
+ def retrieve_workflow(
163
+ self,
164
+ workflow_id: str,
165
+ *,
166
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
167
+ # The extra values given here take precedence over values defined on the client or passed to this method.
168
+ extra_headers: Headers | None = None,
169
+ extra_query: Query | None = None,
170
+ extra_body: Body | None = None,
171
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
172
+ ) -> DefendResponse:
173
+ """
174
+ Retrieve the details for a specific guardrail workflow.
175
+
176
+ Args:
177
+ extra_headers: Send extra headers
178
+
179
+ extra_query: Add additional query parameters to the request
180
+
181
+ extra_body: Add additional JSON properties to the request
182
+
183
+ timeout: Override the client-level default timeout for this request, in seconds
184
+ """
185
+ if not workflow_id:
186
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
187
+ return self._get(
188
+ f"/defend/{workflow_id}",
189
+ options=make_request_options(
190
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
191
+ ),
192
+ cast_to=DefendResponse,
193
+ )
194
+
195
+ def submit_event(
196
+ self,
197
+ workflow_id: str,
198
+ *,
199
+ model_input: defend_submit_event_params.ModelInput,
200
+ model_output: str,
201
+ model_used: str,
202
+ nametag: str,
203
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
204
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
205
+ # The extra values given here take precedence over values defined on the client or passed to this method.
206
+ extra_headers: Headers | None = None,
207
+ extra_query: Query | None = None,
208
+ extra_body: Body | None = None,
209
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
210
+ ) -> WorkflowEventResponse:
211
+ """
212
+ Submit a model input and output pair to a workflow for evaluation.
213
+
214
+ Args:
215
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
216
+ `user_prompt` field and an optional `context` field. Additional properties are
217
+ allowed.
218
+
219
+ model_output: Output generated by the LLM to be evaluated.
220
+
221
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
222
+
223
+ nametag: An optional, user-defined tag for the event.
224
+
225
+ run_mode: Run mode for the workflow event. The run mode allows the user to optimize for
226
+ speed, accuracy, and cost by determining which models are used to evaluate the
227
+ event. Available run modes include `precision_plus`, `precision`, `smart`, and
228
+ `economy`. Defaults to `smart`.
229
+
230
+ extra_headers: Send extra headers
231
+
232
+ extra_query: Add additional query parameters to the request
233
+
234
+ extra_body: Add additional JSON properties to the request
235
+
236
+ timeout: Override the client-level default timeout for this request, in seconds
237
+ """
238
+ if not workflow_id:
239
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
240
+ return self._post(
241
+ f"/defend/{workflow_id}/events",
242
+ body=maybe_transform(
243
+ {
244
+ "model_input": model_input,
245
+ "model_output": model_output,
246
+ "model_used": model_used,
247
+ "nametag": nametag,
248
+ "run_mode": run_mode,
249
+ },
250
+ defend_submit_event_params.DefendSubmitEventParams,
251
+ ),
252
+ options=make_request_options(
253
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
254
+ ),
255
+ cast_to=WorkflowEventResponse,
256
+ )
257
+
258
+ def update_workflow(
259
+ self,
260
+ workflow_id: str,
261
+ *,
262
+ description: str | Omit = omit,
263
+ name: str | Omit = omit,
264
+ type: Literal["automatic", "custom"] | Omit = omit,
265
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
266
+ # The extra values given here take precedence over values defined on the client or passed to this method.
267
+ extra_headers: Headers | None = None,
268
+ extra_query: Query | None = None,
269
+ extra_body: Body | None = None,
270
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
271
+ ) -> DefendResponse:
272
+ """
273
+ Update an existing guardrail workflow.
274
+
275
+ Args:
276
+ description: Description for the workflow.
277
+
278
+ name: Name of the workflow.
279
+
280
+ type: Type of thresholds to use for the workflow, either `automatic` or `custom`.
281
+
282
+ extra_headers: Send extra headers
283
+
284
+ extra_query: Add additional query parameters to the request
285
+
286
+ extra_body: Add additional JSON properties to the request
287
+
288
+ timeout: Override the client-level default timeout for this request, in seconds
289
+ """
290
+ if not workflow_id:
291
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
292
+ return self._put(
293
+ f"/defend/{workflow_id}",
294
+ body=maybe_transform(
295
+ {
296
+ "description": description,
297
+ "name": name,
298
+ "type": type,
299
+ },
300
+ defend_update_workflow_params.DefendUpdateWorkflowParams,
301
+ ),
302
+ options=make_request_options(
303
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
304
+ ),
305
+ cast_to=DefendResponse,
306
+ )
307
+
308
+
309
+ class AsyncDefendResource(AsyncAPIResource):
310
+ @cached_property
311
+ def with_raw_response(self) -> AsyncDefendResourceWithRawResponse:
312
+ """
313
+ This property can be used as a prefix for any HTTP method call to return
314
+ the raw response object instead of the parsed content.
315
+
316
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
317
+ """
318
+ return AsyncDefendResourceWithRawResponse(self)
319
+
320
+ @cached_property
321
+ def with_streaming_response(self) -> AsyncDefendResourceWithStreamingResponse:
322
+ """
323
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
324
+
325
+ For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
326
+ """
327
+ return AsyncDefendResourceWithStreamingResponse(self)
328
+
329
+ async def create_workflow(
330
+ self,
331
+ *,
332
+ improvement_action: Optional[Literal["regenerate", "fixit"]],
333
+ metrics: Dict[str, float],
334
+ name: str,
335
+ type: Literal["automatic", "custom"],
336
+ automatic_tolerance: Literal["low", "medium", "high"] | Omit = omit,
337
+ description: str | Omit = omit,
338
+ max_retries: int | Omit = omit,
339
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
340
+ # The extra values given here take precedence over values defined on the client or passed to this method.
341
+ extra_headers: Headers | None = None,
342
+ extra_query: Query | None = None,
343
+ extra_body: Body | None = None,
344
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
345
+ ) -> DefendResponse:
346
+ """
347
+ Create a new guardrail workflow with optional guardrail thresholds and
348
+ improvement actions.
349
+
350
+ Args:
351
+ improvement_action: The action used to improve outputs that fail one or guardrail metrics for the
352
+ workflow events. May be `regenerate`, `fixit`, or null which represents “do
353
+ nothing”. ReGen runs the user's exact input prompt with minor induced variance.
354
+ Fixit attempts to directly address the shortcomings of the output using the
355
+ guardrail failure rationale. Do nothing does not attempt any improvement.
356
+
357
+ metrics: Mapping of guardrail metrics to floating point threshold values. If the workflow
358
+ type is automatic, only the metric names are used (`automatic_tolerance`
359
+ determines thresholds). Possible metrics are `correctness`, `completeness`,
360
+ `instruction_adherence`, `context_adherence`, `ground_truth_adherence`, or
361
+ `comprehensive_safety`.
362
+
363
+ name: Name of the workflow.
364
+
365
+ type: Type of thresholds to use for the workflow, either `automatic` or `custom`.
366
+ Automatic thresholds are assigned internally after the user specifies a
367
+ qualitative tolerance for the metrics, whereas custom metrics allow the user to
368
+ set the threshold for each metric as a floating point number between 0.0 and
369
+ 1.0.
370
+
371
+ automatic_tolerance: Hallucination tolerance for automatic workflows; may be `low`, `medium`, or
372
+ `high`. Ignored if `type` is `custom`.
373
+
374
+ description: Description for the workflow.
375
+
376
+ max_retries: Max. number of improvement action retries until a given event passes the
377
+ guardrails. Defaults to 10.
378
+
379
+ extra_headers: Send extra headers
380
+
381
+ extra_query: Add additional query parameters to the request
382
+
383
+ extra_body: Add additional JSON properties to the request
384
+
385
+ timeout: Override the client-level default timeout for this request, in seconds
386
+ """
387
+ return await self._post(
388
+ "/defend",
389
+ body=await async_maybe_transform(
390
+ {
391
+ "improvement_action": improvement_action,
392
+ "metrics": metrics,
393
+ "name": name,
394
+ "type": type,
395
+ "automatic_tolerance": automatic_tolerance,
396
+ "description": description,
397
+ "max_retries": max_retries,
398
+ },
399
+ defend_create_workflow_params.DefendCreateWorkflowParams,
400
+ ),
401
+ options=make_request_options(
402
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
403
+ ),
404
+ cast_to=DefendResponse,
405
+ )
406
+
407
+ async def retrieve_event(
408
+ self,
409
+ event_id: str,
410
+ *,
411
+ workflow_id: str,
412
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
413
+ # The extra values given here take precedence over values defined on the client or passed to this method.
414
+ extra_headers: Headers | None = None,
415
+ extra_query: Query | None = None,
416
+ extra_body: Body | None = None,
417
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
418
+ ) -> WorkflowEventResponse:
419
+ """
420
+ Retrieve a specific event of a guardrail workflow.
421
+
422
+ Args:
423
+ extra_headers: Send extra headers
424
+
425
+ extra_query: Add additional query parameters to the request
426
+
427
+ extra_body: Add additional JSON properties to the request
428
+
429
+ timeout: Override the client-level default timeout for this request, in seconds
430
+ """
431
+ if not workflow_id:
432
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
433
+ if not event_id:
434
+ raise ValueError(f"Expected a non-empty value for `event_id` but received {event_id!r}")
435
+ return await self._get(
436
+ f"/defend/{workflow_id}/events/{event_id}",
437
+ options=make_request_options(
438
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
439
+ ),
440
+ cast_to=WorkflowEventResponse,
441
+ )
442
+
443
+ async def retrieve_workflow(
444
+ self,
445
+ workflow_id: str,
446
+ *,
447
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
448
+ # The extra values given here take precedence over values defined on the client or passed to this method.
449
+ extra_headers: Headers | None = None,
450
+ extra_query: Query | None = None,
451
+ extra_body: Body | None = None,
452
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
453
+ ) -> DefendResponse:
454
+ """
455
+ Retrieve the details for a specific guardrail workflow.
456
+
457
+ Args:
458
+ extra_headers: Send extra headers
459
+
460
+ extra_query: Add additional query parameters to the request
461
+
462
+ extra_body: Add additional JSON properties to the request
463
+
464
+ timeout: Override the client-level default timeout for this request, in seconds
465
+ """
466
+ if not workflow_id:
467
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
468
+ return await self._get(
469
+ f"/defend/{workflow_id}",
470
+ options=make_request_options(
471
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
472
+ ),
473
+ cast_to=DefendResponse,
474
+ )
475
+
476
+ async def submit_event(
477
+ self,
478
+ workflow_id: str,
479
+ *,
480
+ model_input: defend_submit_event_params.ModelInput,
481
+ model_output: str,
482
+ model_used: str,
483
+ nametag: str,
484
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
485
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
486
+ # The extra values given here take precedence over values defined on the client or passed to this method.
487
+ extra_headers: Headers | None = None,
488
+ extra_query: Query | None = None,
489
+ extra_body: Body | None = None,
490
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
491
+ ) -> WorkflowEventResponse:
492
+ """
493
+ Submit a model input and output pair to a workflow for evaluation.
494
+
495
+ Args:
496
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
497
+ `user_prompt` field and an optional `context` field. Additional properties are
498
+ allowed.
499
+
500
+ model_output: Output generated by the LLM to be evaluated.
501
+
502
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
503
+
504
+ nametag: An optional, user-defined tag for the event.
505
+
506
+ run_mode: Run mode for the workflow event. The run mode allows the user to optimize for
507
+ speed, accuracy, and cost by determining which models are used to evaluate the
508
+ event. Available run modes include `precision_plus`, `precision`, `smart`, and
509
+ `economy`. Defaults to `smart`.
510
+
511
+ extra_headers: Send extra headers
512
+
513
+ extra_query: Add additional query parameters to the request
514
+
515
+ extra_body: Add additional JSON properties to the request
516
+
517
+ timeout: Override the client-level default timeout for this request, in seconds
518
+ """
519
+ if not workflow_id:
520
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
521
+ return await self._post(
522
+ f"/defend/{workflow_id}/events",
523
+ body=await async_maybe_transform(
524
+ {
525
+ "model_input": model_input,
526
+ "model_output": model_output,
527
+ "model_used": model_used,
528
+ "nametag": nametag,
529
+ "run_mode": run_mode,
530
+ },
531
+ defend_submit_event_params.DefendSubmitEventParams,
532
+ ),
533
+ options=make_request_options(
534
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
535
+ ),
536
+ cast_to=WorkflowEventResponse,
537
+ )
538
+
539
+ async def update_workflow(
540
+ self,
541
+ workflow_id: str,
542
+ *,
543
+ description: str | Omit = omit,
544
+ name: str | Omit = omit,
545
+ type: Literal["automatic", "custom"] | Omit = omit,
546
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
547
+ # The extra values given here take precedence over values defined on the client or passed to this method.
548
+ extra_headers: Headers | None = None,
549
+ extra_query: Query | None = None,
550
+ extra_body: Body | None = None,
551
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
552
+ ) -> DefendResponse:
553
+ """
554
+ Update an existing guardrail workflow.
555
+
556
+ Args:
557
+ description: Description for the workflow.
558
+
559
+ name: Name of the workflow.
560
+
561
+ type: Type of thresholds to use for the workflow, either `automatic` or `custom`.
562
+
563
+ extra_headers: Send extra headers
564
+
565
+ extra_query: Add additional query parameters to the request
566
+
567
+ extra_body: Add additional JSON properties to the request
568
+
569
+ timeout: Override the client-level default timeout for this request, in seconds
570
+ """
571
+ if not workflow_id:
572
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
573
+ return await self._put(
574
+ f"/defend/{workflow_id}",
575
+ body=await async_maybe_transform(
576
+ {
577
+ "description": description,
578
+ "name": name,
579
+ "type": type,
580
+ },
581
+ defend_update_workflow_params.DefendUpdateWorkflowParams,
582
+ ),
583
+ options=make_request_options(
584
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
585
+ ),
586
+ cast_to=DefendResponse,
587
+ )
588
+
589
+
590
+ class DefendResourceWithRawResponse:
591
+ def __init__(self, defend: DefendResource) -> None:
592
+ self._defend = defend
593
+
594
+ self.create_workflow = to_raw_response_wrapper(
595
+ defend.create_workflow,
596
+ )
597
+ self.retrieve_event = to_raw_response_wrapper(
598
+ defend.retrieve_event,
599
+ )
600
+ self.retrieve_workflow = to_raw_response_wrapper(
601
+ defend.retrieve_workflow,
602
+ )
603
+ self.submit_event = to_raw_response_wrapper(
604
+ defend.submit_event,
605
+ )
606
+ self.update_workflow = to_raw_response_wrapper(
607
+ defend.update_workflow,
608
+ )
609
+
610
+
611
+ class AsyncDefendResourceWithRawResponse:
612
+ def __init__(self, defend: AsyncDefendResource) -> None:
613
+ self._defend = defend
614
+
615
+ self.create_workflow = async_to_raw_response_wrapper(
616
+ defend.create_workflow,
617
+ )
618
+ self.retrieve_event = async_to_raw_response_wrapper(
619
+ defend.retrieve_event,
620
+ )
621
+ self.retrieve_workflow = async_to_raw_response_wrapper(
622
+ defend.retrieve_workflow,
623
+ )
624
+ self.submit_event = async_to_raw_response_wrapper(
625
+ defend.submit_event,
626
+ )
627
+ self.update_workflow = async_to_raw_response_wrapper(
628
+ defend.update_workflow,
629
+ )
630
+
631
+
632
+ class DefendResourceWithStreamingResponse:
633
+ def __init__(self, defend: DefendResource) -> None:
634
+ self._defend = defend
635
+
636
+ self.create_workflow = to_streamed_response_wrapper(
637
+ defend.create_workflow,
638
+ )
639
+ self.retrieve_event = to_streamed_response_wrapper(
640
+ defend.retrieve_event,
641
+ )
642
+ self.retrieve_workflow = to_streamed_response_wrapper(
643
+ defend.retrieve_workflow,
644
+ )
645
+ self.submit_event = to_streamed_response_wrapper(
646
+ defend.submit_event,
647
+ )
648
+ self.update_workflow = to_streamed_response_wrapper(
649
+ defend.update_workflow,
650
+ )
651
+
652
+
653
+ class AsyncDefendResourceWithStreamingResponse:
654
+ def __init__(self, defend: AsyncDefendResource) -> None:
655
+ self._defend = defend
656
+
657
+ self.create_workflow = async_to_streamed_response_wrapper(
658
+ defend.create_workflow,
659
+ )
660
+ self.retrieve_event = async_to_streamed_response_wrapper(
661
+ defend.retrieve_event,
662
+ )
663
+ self.retrieve_workflow = async_to_streamed_response_wrapper(
664
+ defend.retrieve_workflow,
665
+ )
666
+ self.submit_event = async_to_streamed_response_wrapper(
667
+ defend.submit_event,
668
+ )
669
+ self.update_workflow = async_to_streamed_response_wrapper(
670
+ defend.update_workflow,
671
+ )