deeprails 0.3.1__py3-none-any.whl → 1.0.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.

Files changed (60) hide show
  1. deeprails/__init__.py +104 -1
  2. deeprails/_base_client.py +1995 -0
  3. deeprails/_client.py +478 -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/__init__.py +33 -0
  31. deeprails/resources/defend/defend.py +480 -0
  32. deeprails/resources/defend/events.py +311 -0
  33. deeprails/resources/evaluate.py +334 -0
  34. deeprails/resources/monitor.py +566 -0
  35. deeprails/types/__init__.py +16 -0
  36. deeprails/types/api_response.py +50 -0
  37. deeprails/types/defend/__init__.py +6 -0
  38. deeprails/types/defend/event_submit_event_params.py +44 -0
  39. deeprails/types/defend/workflow_event_response.py +33 -0
  40. deeprails/types/defend_create_workflow_params.py +56 -0
  41. deeprails/types/defend_response.py +50 -0
  42. deeprails/types/defend_update_workflow_params.py +18 -0
  43. deeprails/types/evaluate_create_params.py +60 -0
  44. deeprails/types/evaluation.py +113 -0
  45. deeprails/types/monitor_create_params.py +15 -0
  46. deeprails/types/monitor_retrieve_params.py +12 -0
  47. deeprails/types/monitor_retrieve_response.py +81 -0
  48. deeprails/types/monitor_submit_event_params.py +63 -0
  49. deeprails/types/monitor_submit_event_response.py +36 -0
  50. deeprails/types/monitor_update_params.py +22 -0
  51. deeprails-1.0.0.dist-info/METADATA +550 -0
  52. deeprails-1.0.0.dist-info/RECORD +54 -0
  53. {deeprails-0.3.1.dist-info → deeprails-1.0.0.dist-info}/WHEEL +1 -1
  54. deeprails-1.0.0.dist-info/licenses/LICENSE +201 -0
  55. deeprails/client.py +0 -285
  56. deeprails/exceptions.py +0 -10
  57. deeprails/schemas.py +0 -92
  58. deeprails-0.3.1.dist-info/METADATA +0 -235
  59. deeprails-0.3.1.dist-info/RECORD +0 -8
  60. deeprails-0.3.1.dist-info/licenses/LICENSE +0 -11
@@ -0,0 +1,311 @@
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 Literal
6
+
7
+ import httpx
8
+
9
+ from ..._types import Body, Query, Headers, NotGiven, not_given
10
+ from ..._utils import maybe_transform, async_maybe_transform
11
+ from ..._compat import cached_property
12
+ from ..._resource import SyncAPIResource, AsyncAPIResource
13
+ from ..._response import (
14
+ to_raw_response_wrapper,
15
+ to_streamed_response_wrapper,
16
+ async_to_raw_response_wrapper,
17
+ async_to_streamed_response_wrapper,
18
+ )
19
+ from ..._base_client import make_request_options
20
+ from ...types.defend import event_submit_event_params
21
+ from ...types.defend.workflow_event_response import WorkflowEventResponse
22
+
23
+ __all__ = ["EventsResource", "AsyncEventsResource"]
24
+
25
+
26
+ class EventsResource(SyncAPIResource):
27
+ @cached_property
28
+ def with_raw_response(self) -> EventsResourceWithRawResponse:
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-python-sdk#accessing-raw-response-data-eg-headers
34
+ """
35
+ return EventsResourceWithRawResponse(self)
36
+
37
+ @cached_property
38
+ def with_streaming_response(self) -> EventsResourceWithStreamingResponse:
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-python-sdk#with_streaming_response
43
+ """
44
+ return EventsResourceWithStreamingResponse(self)
45
+
46
+ def retrieve_event(
47
+ self,
48
+ event_id: str,
49
+ *,
50
+ workflow_id: str,
51
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
52
+ # The extra values given here take precedence over values defined on the client or passed to this method.
53
+ extra_headers: Headers | None = None,
54
+ extra_query: Query | None = None,
55
+ extra_body: Body | None = None,
56
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
57
+ ) -> WorkflowEventResponse:
58
+ """
59
+ Retrieve a specific event of a guardrail workflow.
60
+
61
+ Args:
62
+ extra_headers: Send extra headers
63
+
64
+ extra_query: Add additional query parameters to the request
65
+
66
+ extra_body: Add additional JSON properties to the request
67
+
68
+ timeout: Override the client-level default timeout for this request, in seconds
69
+ """
70
+ if not workflow_id:
71
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
72
+ if not event_id:
73
+ raise ValueError(f"Expected a non-empty value for `event_id` but received {event_id!r}")
74
+ return self._get(
75
+ f"/defend/{workflow_id}/events/{event_id}",
76
+ options=make_request_options(
77
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
78
+ ),
79
+ cast_to=WorkflowEventResponse,
80
+ )
81
+
82
+ def submit_event(
83
+ self,
84
+ workflow_id: str,
85
+ *,
86
+ model_input: event_submit_event_params.ModelInput,
87
+ model_output: str,
88
+ model_used: str,
89
+ nametag: str,
90
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
91
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
92
+ # The extra values given here take precedence over values defined on the client or passed to this method.
93
+ extra_headers: Headers | None = None,
94
+ extra_query: Query | None = None,
95
+ extra_body: Body | None = None,
96
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
97
+ ) -> WorkflowEventResponse:
98
+ """
99
+ Submit a model input and output pair to a workflow for evaluation.
100
+
101
+ Args:
102
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
103
+ `user_prompt` field and an optional `context` field. Additional properties are
104
+ allowed.
105
+
106
+ model_output: Output generated by the LLM to be evaluated.
107
+
108
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
109
+
110
+ nametag: An optional, user-defined tag for the event.
111
+
112
+ run_mode: Run mode for the workflow event. The run mode allows the user to optimize for
113
+ speed, accuracy, and cost by determining which models are used to evaluate the
114
+ event. Available run modes include `precision_plus`, `precision`, `smart`, and
115
+ `economy`. Defaults to `smart`.
116
+
117
+ extra_headers: Send extra headers
118
+
119
+ extra_query: Add additional query parameters to the request
120
+
121
+ extra_body: Add additional JSON properties to the request
122
+
123
+ timeout: Override the client-level default timeout for this request, in seconds
124
+ """
125
+ if not workflow_id:
126
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
127
+ return self._post(
128
+ f"/defend/{workflow_id}/events",
129
+ body=maybe_transform(
130
+ {
131
+ "model_input": model_input,
132
+ "model_output": model_output,
133
+ "model_used": model_used,
134
+ "nametag": nametag,
135
+ "run_mode": run_mode,
136
+ },
137
+ event_submit_event_params.EventSubmitEventParams,
138
+ ),
139
+ options=make_request_options(
140
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
141
+ ),
142
+ cast_to=WorkflowEventResponse,
143
+ )
144
+
145
+
146
+ class AsyncEventsResource(AsyncAPIResource):
147
+ @cached_property
148
+ def with_raw_response(self) -> AsyncEventsResourceWithRawResponse:
149
+ """
150
+ This property can be used as a prefix for any HTTP method call to return
151
+ the raw response object instead of the parsed content.
152
+
153
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#accessing-raw-response-data-eg-headers
154
+ """
155
+ return AsyncEventsResourceWithRawResponse(self)
156
+
157
+ @cached_property
158
+ def with_streaming_response(self) -> AsyncEventsResourceWithStreamingResponse:
159
+ """
160
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
161
+
162
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#with_streaming_response
163
+ """
164
+ return AsyncEventsResourceWithStreamingResponse(self)
165
+
166
+ async def retrieve_event(
167
+ self,
168
+ event_id: str,
169
+ *,
170
+ workflow_id: str,
171
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
172
+ # The extra values given here take precedence over values defined on the client or passed to this method.
173
+ extra_headers: Headers | None = None,
174
+ extra_query: Query | None = None,
175
+ extra_body: Body | None = None,
176
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
177
+ ) -> WorkflowEventResponse:
178
+ """
179
+ Retrieve a specific event of a guardrail workflow.
180
+
181
+ Args:
182
+ extra_headers: Send extra headers
183
+
184
+ extra_query: Add additional query parameters to the request
185
+
186
+ extra_body: Add additional JSON properties to the request
187
+
188
+ timeout: Override the client-level default timeout for this request, in seconds
189
+ """
190
+ if not workflow_id:
191
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
192
+ if not event_id:
193
+ raise ValueError(f"Expected a non-empty value for `event_id` but received {event_id!r}")
194
+ return await self._get(
195
+ f"/defend/{workflow_id}/events/{event_id}",
196
+ options=make_request_options(
197
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
198
+ ),
199
+ cast_to=WorkflowEventResponse,
200
+ )
201
+
202
+ async def submit_event(
203
+ self,
204
+ workflow_id: str,
205
+ *,
206
+ model_input: event_submit_event_params.ModelInput,
207
+ model_output: str,
208
+ model_used: str,
209
+ nametag: str,
210
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
211
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
212
+ # The extra values given here take precedence over values defined on the client or passed to this method.
213
+ extra_headers: Headers | None = None,
214
+ extra_query: Query | None = None,
215
+ extra_body: Body | None = None,
216
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
217
+ ) -> WorkflowEventResponse:
218
+ """
219
+ Submit a model input and output pair to a workflow for evaluation.
220
+
221
+ Args:
222
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
223
+ `user_prompt` field and an optional `context` field. Additional properties are
224
+ allowed.
225
+
226
+ model_output: Output generated by the LLM to be evaluated.
227
+
228
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
229
+
230
+ nametag: An optional, user-defined tag for the event.
231
+
232
+ run_mode: Run mode for the workflow event. The run mode allows the user to optimize for
233
+ speed, accuracy, and cost by determining which models are used to evaluate the
234
+ event. Available run modes include `precision_plus`, `precision`, `smart`, and
235
+ `economy`. Defaults to `smart`.
236
+
237
+ extra_headers: Send extra headers
238
+
239
+ extra_query: Add additional query parameters to the request
240
+
241
+ extra_body: Add additional JSON properties to the request
242
+
243
+ timeout: Override the client-level default timeout for this request, in seconds
244
+ """
245
+ if not workflow_id:
246
+ raise ValueError(f"Expected a non-empty value for `workflow_id` but received {workflow_id!r}")
247
+ return await self._post(
248
+ f"/defend/{workflow_id}/events",
249
+ body=await async_maybe_transform(
250
+ {
251
+ "model_input": model_input,
252
+ "model_output": model_output,
253
+ "model_used": model_used,
254
+ "nametag": nametag,
255
+ "run_mode": run_mode,
256
+ },
257
+ event_submit_event_params.EventSubmitEventParams,
258
+ ),
259
+ options=make_request_options(
260
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
261
+ ),
262
+ cast_to=WorkflowEventResponse,
263
+ )
264
+
265
+
266
+ class EventsResourceWithRawResponse:
267
+ def __init__(self, events: EventsResource) -> None:
268
+ self._events = events
269
+
270
+ self.retrieve_event = to_raw_response_wrapper(
271
+ events.retrieve_event,
272
+ )
273
+ self.submit_event = to_raw_response_wrapper(
274
+ events.submit_event,
275
+ )
276
+
277
+
278
+ class AsyncEventsResourceWithRawResponse:
279
+ def __init__(self, events: AsyncEventsResource) -> None:
280
+ self._events = events
281
+
282
+ self.retrieve_event = async_to_raw_response_wrapper(
283
+ events.retrieve_event,
284
+ )
285
+ self.submit_event = async_to_raw_response_wrapper(
286
+ events.submit_event,
287
+ )
288
+
289
+
290
+ class EventsResourceWithStreamingResponse:
291
+ def __init__(self, events: EventsResource) -> None:
292
+ self._events = events
293
+
294
+ self.retrieve_event = to_streamed_response_wrapper(
295
+ events.retrieve_event,
296
+ )
297
+ self.submit_event = to_streamed_response_wrapper(
298
+ events.submit_event,
299
+ )
300
+
301
+
302
+ class AsyncEventsResourceWithStreamingResponse:
303
+ def __init__(self, events: AsyncEventsResource) -> None:
304
+ self._events = events
305
+
306
+ self.retrieve_event = async_to_streamed_response_wrapper(
307
+ events.retrieve_event,
308
+ )
309
+ self.submit_event = async_to_streamed_response_wrapper(
310
+ events.submit_event,
311
+ )
@@ -0,0 +1,334 @@
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 List
6
+ from typing_extensions import Literal
7
+
8
+ import httpx
9
+
10
+ from ..types import evaluate_create_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.evaluation import Evaluation
23
+
24
+ __all__ = ["EvaluateResource", "AsyncEvaluateResource"]
25
+
26
+
27
+ class EvaluateResource(SyncAPIResource):
28
+ @cached_property
29
+ def with_raw_response(self) -> EvaluateResourceWithRawResponse:
30
+ """
31
+ This property can be used as a prefix for any HTTP method call to return
32
+ the raw response object instead of the parsed content.
33
+
34
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#accessing-raw-response-data-eg-headers
35
+ """
36
+ return EvaluateResourceWithRawResponse(self)
37
+
38
+ @cached_property
39
+ def with_streaming_response(self) -> EvaluateResourceWithStreamingResponse:
40
+ """
41
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
42
+
43
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#with_streaming_response
44
+ """
45
+ return EvaluateResourceWithStreamingResponse(self)
46
+
47
+ def create(
48
+ self,
49
+ *,
50
+ model_input: evaluate_create_params.ModelInput,
51
+ model_output: str,
52
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
53
+ guardrail_metrics: List[
54
+ Literal[
55
+ "correctness",
56
+ "completeness",
57
+ "instruction_adherence",
58
+ "context_adherence",
59
+ "ground_truth_adherence",
60
+ "comprehensive_safety",
61
+ ]
62
+ ]
63
+ | Omit = omit,
64
+ model_used: str | Omit = omit,
65
+ nametag: str | Omit = omit,
66
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
67
+ # The extra values given here take precedence over values defined on the client or passed to this method.
68
+ extra_headers: Headers | None = None,
69
+ extra_query: Query | None = None,
70
+ extra_body: Body | None = None,
71
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
72
+ ) -> Evaluation:
73
+ """
74
+ Use this endpoint to evaluate a model's input and output pair against selected
75
+ guardrail metrics
76
+
77
+ Args:
78
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
79
+ `user_prompt` field and an optional `context` field. Additional properties are
80
+ allowed.
81
+
82
+ model_output: Output generated by the LLM to be evaluated.
83
+
84
+ run_mode: Run mode for the evaluation. The run mode allows the user to optimize for speed,
85
+ accuracy, and cost by determining which models are used to evaluate the event.
86
+ Available run modes include `precision_plus`, `precision`, `smart`, and
87
+ `economy`. Defaults to `smart`.
88
+
89
+ guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
90
+ evaluated on. For non-enterprise users, these will be limited to the allowed
91
+ guardrail metrics.
92
+
93
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
94
+
95
+ nametag: An optional, user-defined tag for the evaluation.
96
+
97
+ extra_headers: Send extra headers
98
+
99
+ extra_query: Add additional query parameters to the request
100
+
101
+ extra_body: Add additional JSON properties to the request
102
+
103
+ timeout: Override the client-level default timeout for this request, in seconds
104
+ """
105
+ return self._post(
106
+ "/evaluate",
107
+ body=maybe_transform(
108
+ {
109
+ "model_input": model_input,
110
+ "model_output": model_output,
111
+ "run_mode": run_mode,
112
+ "guardrail_metrics": guardrail_metrics,
113
+ "model_used": model_used,
114
+ "nametag": nametag,
115
+ },
116
+ evaluate_create_params.EvaluateCreateParams,
117
+ ),
118
+ options=make_request_options(
119
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
120
+ ),
121
+ cast_to=Evaluation,
122
+ )
123
+
124
+ def retrieve(
125
+ self,
126
+ eval_id: str,
127
+ *,
128
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
129
+ # The extra values given here take precedence over values defined on the client or passed to this method.
130
+ extra_headers: Headers | None = None,
131
+ extra_query: Query | None = None,
132
+ extra_body: Body | None = None,
133
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
134
+ ) -> Evaluation:
135
+ """
136
+ Retrieve the evaluation record for a given evaluation ID.
137
+
138
+ Args:
139
+ extra_headers: Send extra headers
140
+
141
+ extra_query: Add additional query parameters to the request
142
+
143
+ extra_body: Add additional JSON properties to the request
144
+
145
+ timeout: Override the client-level default timeout for this request, in seconds
146
+ """
147
+ if not eval_id:
148
+ raise ValueError(f"Expected a non-empty value for `eval_id` but received {eval_id!r}")
149
+ return self._get(
150
+ f"/evaluate/{eval_id}",
151
+ options=make_request_options(
152
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
153
+ ),
154
+ cast_to=Evaluation,
155
+ )
156
+
157
+
158
+ class AsyncEvaluateResource(AsyncAPIResource):
159
+ @cached_property
160
+ def with_raw_response(self) -> AsyncEvaluateResourceWithRawResponse:
161
+ """
162
+ This property can be used as a prefix for any HTTP method call to return
163
+ the raw response object instead of the parsed content.
164
+
165
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#accessing-raw-response-data-eg-headers
166
+ """
167
+ return AsyncEvaluateResourceWithRawResponse(self)
168
+
169
+ @cached_property
170
+ def with_streaming_response(self) -> AsyncEvaluateResourceWithStreamingResponse:
171
+ """
172
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
173
+
174
+ For more information, see https://www.github.com/deeprails/deeprails-python-sdk#with_streaming_response
175
+ """
176
+ return AsyncEvaluateResourceWithStreamingResponse(self)
177
+
178
+ async def create(
179
+ self,
180
+ *,
181
+ model_input: evaluate_create_params.ModelInput,
182
+ model_output: str,
183
+ run_mode: Literal["precision_plus", "precision", "smart", "economy"],
184
+ guardrail_metrics: List[
185
+ Literal[
186
+ "correctness",
187
+ "completeness",
188
+ "instruction_adherence",
189
+ "context_adherence",
190
+ "ground_truth_adherence",
191
+ "comprehensive_safety",
192
+ ]
193
+ ]
194
+ | Omit = omit,
195
+ model_used: str | Omit = omit,
196
+ nametag: str | Omit = omit,
197
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
198
+ # The extra values given here take precedence over values defined on the client or passed to this method.
199
+ extra_headers: Headers | None = None,
200
+ extra_query: Query | None = None,
201
+ extra_body: Body | None = None,
202
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
203
+ ) -> Evaluation:
204
+ """
205
+ Use this endpoint to evaluate a model's input and output pair against selected
206
+ guardrail metrics
207
+
208
+ Args:
209
+ model_input: A dictionary of inputs sent to the LLM to generate output. This must contain a
210
+ `user_prompt` field and an optional `context` field. Additional properties are
211
+ allowed.
212
+
213
+ model_output: Output generated by the LLM to be evaluated.
214
+
215
+ run_mode: Run mode for the evaluation. The run mode allows the user to optimize for speed,
216
+ accuracy, and cost by determining which models are used to evaluate the event.
217
+ Available run modes include `precision_plus`, `precision`, `smart`, and
218
+ `economy`. Defaults to `smart`.
219
+
220
+ guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
221
+ evaluated on. For non-enterprise users, these will be limited to the allowed
222
+ guardrail metrics.
223
+
224
+ model_used: Model ID used to generate the output, like `gpt-4o` or `o3`.
225
+
226
+ nametag: An optional, user-defined tag for the evaluation.
227
+
228
+ extra_headers: Send extra headers
229
+
230
+ extra_query: Add additional query parameters to the request
231
+
232
+ extra_body: Add additional JSON properties to the request
233
+
234
+ timeout: Override the client-level default timeout for this request, in seconds
235
+ """
236
+ return await self._post(
237
+ "/evaluate",
238
+ body=await async_maybe_transform(
239
+ {
240
+ "model_input": model_input,
241
+ "model_output": model_output,
242
+ "run_mode": run_mode,
243
+ "guardrail_metrics": guardrail_metrics,
244
+ "model_used": model_used,
245
+ "nametag": nametag,
246
+ },
247
+ evaluate_create_params.EvaluateCreateParams,
248
+ ),
249
+ options=make_request_options(
250
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
251
+ ),
252
+ cast_to=Evaluation,
253
+ )
254
+
255
+ async def retrieve(
256
+ self,
257
+ eval_id: str,
258
+ *,
259
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
260
+ # The extra values given here take precedence over values defined on the client or passed to this method.
261
+ extra_headers: Headers | None = None,
262
+ extra_query: Query | None = None,
263
+ extra_body: Body | None = None,
264
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
265
+ ) -> Evaluation:
266
+ """
267
+ Retrieve the evaluation record for a given evaluation ID.
268
+
269
+ Args:
270
+ extra_headers: Send extra headers
271
+
272
+ extra_query: Add additional query parameters to the request
273
+
274
+ extra_body: Add additional JSON properties to the request
275
+
276
+ timeout: Override the client-level default timeout for this request, in seconds
277
+ """
278
+ if not eval_id:
279
+ raise ValueError(f"Expected a non-empty value for `eval_id` but received {eval_id!r}")
280
+ return await self._get(
281
+ f"/evaluate/{eval_id}",
282
+ options=make_request_options(
283
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
284
+ ),
285
+ cast_to=Evaluation,
286
+ )
287
+
288
+
289
+ class EvaluateResourceWithRawResponse:
290
+ def __init__(self, evaluate: EvaluateResource) -> None:
291
+ self._evaluate = evaluate
292
+
293
+ self.create = to_raw_response_wrapper(
294
+ evaluate.create,
295
+ )
296
+ self.retrieve = to_raw_response_wrapper(
297
+ evaluate.retrieve,
298
+ )
299
+
300
+
301
+ class AsyncEvaluateResourceWithRawResponse:
302
+ def __init__(self, evaluate: AsyncEvaluateResource) -> None:
303
+ self._evaluate = evaluate
304
+
305
+ self.create = async_to_raw_response_wrapper(
306
+ evaluate.create,
307
+ )
308
+ self.retrieve = async_to_raw_response_wrapper(
309
+ evaluate.retrieve,
310
+ )
311
+
312
+
313
+ class EvaluateResourceWithStreamingResponse:
314
+ def __init__(self, evaluate: EvaluateResource) -> None:
315
+ self._evaluate = evaluate
316
+
317
+ self.create = to_streamed_response_wrapper(
318
+ evaluate.create,
319
+ )
320
+ self.retrieve = to_streamed_response_wrapper(
321
+ evaluate.retrieve,
322
+ )
323
+
324
+
325
+ class AsyncEvaluateResourceWithStreamingResponse:
326
+ def __init__(self, evaluate: AsyncEvaluateResource) -> None:
327
+ self._evaluate = evaluate
328
+
329
+ self.create = async_to_streamed_response_wrapper(
330
+ evaluate.create,
331
+ )
332
+ self.retrieve = async_to_streamed_response_wrapper(
333
+ evaluate.retrieve,
334
+ )