deeprails 1.0.0__py3-none-any.whl → 1.3.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/__init__.py +0 -2
- deeprails/_client.py +13 -72
- deeprails/_version.py +1 -1
- deeprails/resources/{defend/defend.py → defend.py} +247 -62
- deeprails/resources/evaluate.py +6 -6
- deeprails/resources/monitor.py +20 -12
- deeprails/types/__init__.py +2 -0
- deeprails/types/api_response.py +0 -1
- deeprails/types/defend_create_workflow_params.py +1 -1
- deeprails/types/defend_response.py +1 -1
- deeprails/types/{defend/event_submit_event_params.py → defend_submit_event_params.py} +2 -2
- deeprails/types/defend_update_workflow_params.py +1 -4
- deeprails/types/monitor_retrieve_response.py +0 -1
- deeprails/types/monitor_submit_event_response.py +0 -1
- deeprails/types/{defend/workflow_event_response.py → workflow_event_response.py} +1 -1
- {deeprails-1.0.0.dist-info → deeprails-1.3.0.dist-info}/METADATA +50 -223
- {deeprails-1.0.0.dist-info → deeprails-1.3.0.dist-info}/RECORD +19 -22
- deeprails/resources/defend/__init__.py +0 -33
- deeprails/resources/defend/events.py +0 -311
- deeprails/types/defend/__init__.py +0 -6
- {deeprails-1.0.0.dist-info → deeprails-1.3.0.dist-info}/WHEEL +0 -0
- {deeprails-1.0.0.dist-info → deeprails-1.3.0.dist-info}/licenses/LICENSE +0 -0
deeprails/resources/monitor.py
CHANGED
|
@@ -33,7 +33,7 @@ class MonitorResource(SyncAPIResource):
|
|
|
33
33
|
This property can be used as a prefix for any HTTP method call to return
|
|
34
34
|
the raw response object instead of the parsed content.
|
|
35
35
|
|
|
36
|
-
For more information, see https://www.github.com/deeprails/deeprails-python
|
|
36
|
+
For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
|
|
37
37
|
"""
|
|
38
38
|
return MonitorResourceWithRawResponse(self)
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ class MonitorResource(SyncAPIResource):
|
|
|
42
42
|
"""
|
|
43
43
|
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
44
44
|
|
|
45
|
-
For more information, see https://www.github.com/deeprails/deeprails-python
|
|
45
|
+
For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
|
|
46
46
|
"""
|
|
47
47
|
return MonitorResourceWithStreamingResponse(self)
|
|
48
48
|
|
|
@@ -59,7 +59,8 @@ class MonitorResource(SyncAPIResource):
|
|
|
59
59
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
60
60
|
) -> APIResponse:
|
|
61
61
|
"""
|
|
62
|
-
|
|
62
|
+
Use this endpoint to create a new monitor to evaluate model inputs and outputs
|
|
63
|
+
using guardrails
|
|
63
64
|
|
|
64
65
|
Args:
|
|
65
66
|
name: Name of the new monitor.
|
|
@@ -102,7 +103,8 @@ class MonitorResource(SyncAPIResource):
|
|
|
102
103
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
103
104
|
) -> MonitorRetrieveResponse:
|
|
104
105
|
"""
|
|
105
|
-
|
|
106
|
+
Use this endpoint to retrieve the details and evaluations associated with a
|
|
107
|
+
specific monitor
|
|
106
108
|
|
|
107
109
|
Args:
|
|
108
110
|
limit: Limit the returned events associated with this monitor. Defaults to 10.
|
|
@@ -144,7 +146,8 @@ class MonitorResource(SyncAPIResource):
|
|
|
144
146
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
145
147
|
) -> APIResponse:
|
|
146
148
|
"""
|
|
147
|
-
|
|
149
|
+
Use this endpoint to update the name, description, or status of an existing
|
|
150
|
+
monitor
|
|
148
151
|
|
|
149
152
|
Args:
|
|
150
153
|
description: Description of the monitor.
|
|
@@ -207,7 +210,8 @@ class MonitorResource(SyncAPIResource):
|
|
|
207
210
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
208
211
|
) -> MonitorSubmitEventResponse:
|
|
209
212
|
"""
|
|
210
|
-
|
|
213
|
+
Use this endpoint to submit a model input and output pair to a monitor for
|
|
214
|
+
evaluation
|
|
211
215
|
|
|
212
216
|
Args:
|
|
213
217
|
guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
|
|
@@ -267,7 +271,7 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
267
271
|
This property can be used as a prefix for any HTTP method call to return
|
|
268
272
|
the raw response object instead of the parsed content.
|
|
269
273
|
|
|
270
|
-
For more information, see https://www.github.com/deeprails/deeprails-python
|
|
274
|
+
For more information, see https://www.github.com/deeprails/deeprails-sdk-python#accessing-raw-response-data-eg-headers
|
|
271
275
|
"""
|
|
272
276
|
return AsyncMonitorResourceWithRawResponse(self)
|
|
273
277
|
|
|
@@ -276,7 +280,7 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
276
280
|
"""
|
|
277
281
|
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
278
282
|
|
|
279
|
-
For more information, see https://www.github.com/deeprails/deeprails-python
|
|
283
|
+
For more information, see https://www.github.com/deeprails/deeprails-sdk-python#with_streaming_response
|
|
280
284
|
"""
|
|
281
285
|
return AsyncMonitorResourceWithStreamingResponse(self)
|
|
282
286
|
|
|
@@ -293,7 +297,8 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
293
297
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
294
298
|
) -> APIResponse:
|
|
295
299
|
"""
|
|
296
|
-
|
|
300
|
+
Use this endpoint to create a new monitor to evaluate model inputs and outputs
|
|
301
|
+
using guardrails
|
|
297
302
|
|
|
298
303
|
Args:
|
|
299
304
|
name: Name of the new monitor.
|
|
@@ -336,7 +341,8 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
336
341
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
337
342
|
) -> MonitorRetrieveResponse:
|
|
338
343
|
"""
|
|
339
|
-
|
|
344
|
+
Use this endpoint to retrieve the details and evaluations associated with a
|
|
345
|
+
specific monitor
|
|
340
346
|
|
|
341
347
|
Args:
|
|
342
348
|
limit: Limit the returned events associated with this monitor. Defaults to 10.
|
|
@@ -378,7 +384,8 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
378
384
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
379
385
|
) -> APIResponse:
|
|
380
386
|
"""
|
|
381
|
-
|
|
387
|
+
Use this endpoint to update the name, description, or status of an existing
|
|
388
|
+
monitor
|
|
382
389
|
|
|
383
390
|
Args:
|
|
384
391
|
description: Description of the monitor.
|
|
@@ -441,7 +448,8 @@ class AsyncMonitorResource(AsyncAPIResource):
|
|
|
441
448
|
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
442
449
|
) -> MonitorSubmitEventResponse:
|
|
443
450
|
"""
|
|
444
|
-
|
|
451
|
+
Use this endpoint to submit a model input and output pair to a monitor for
|
|
452
|
+
evaluation
|
|
445
453
|
|
|
446
454
|
Args:
|
|
447
455
|
guardrail_metrics: An array of guardrail metrics that the model input and output pair will be
|
deeprails/types/__init__.py
CHANGED
|
@@ -9,7 +9,9 @@ from .monitor_create_params import MonitorCreateParams as MonitorCreateParams
|
|
|
9
9
|
from .monitor_update_params import MonitorUpdateParams as MonitorUpdateParams
|
|
10
10
|
from .evaluate_create_params import EvaluateCreateParams as EvaluateCreateParams
|
|
11
11
|
from .monitor_retrieve_params import MonitorRetrieveParams as MonitorRetrieveParams
|
|
12
|
+
from .workflow_event_response import WorkflowEventResponse as WorkflowEventResponse
|
|
12
13
|
from .monitor_retrieve_response import MonitorRetrieveResponse as MonitorRetrieveResponse
|
|
14
|
+
from .defend_submit_event_params import DefendSubmitEventParams as DefendSubmitEventParams
|
|
13
15
|
from .monitor_submit_event_params import MonitorSubmitEventParams as MonitorSubmitEventParams
|
|
14
16
|
from .defend_create_workflow_params import DefendCreateWorkflowParams as DefendCreateWorkflowParams
|
|
15
17
|
from .defend_update_workflow_params import DefendUpdateWorkflowParams as DefendUpdateWorkflowParams
|
deeprails/types/api_response.py
CHANGED
|
@@ -41,7 +41,6 @@ class APIResponse(BaseModel):
|
|
|
41
41
|
"""Represents whether the request was completed successfully."""
|
|
42
42
|
|
|
43
43
|
data: Optional[Data] = None
|
|
44
|
-
"""Response payload for creating or updating a monitor."""
|
|
45
44
|
|
|
46
45
|
message: Optional[str] = None
|
|
47
46
|
"""The accompanying message for the request.
|
|
@@ -13,7 +13,7 @@ class DefendCreateWorkflowParams(TypedDict, total=False):
|
|
|
13
13
|
"""
|
|
14
14
|
The action used to improve outputs that fail one or guardrail metrics for the
|
|
15
15
|
workflow events. May be `regenerate`, `fixit`, or null which represents “do
|
|
16
|
-
nothing”.
|
|
16
|
+
nothing”. Regenerate runs the user's input prompt with minor induced variance.
|
|
17
17
|
Fixit attempts to directly address the shortcomings of the output using the
|
|
18
18
|
guardrail failure rationale. Do nothing does not attempt any improvement.
|
|
19
19
|
"""
|
|
@@ -26,7 +26,7 @@ class DefendResponse(BaseModel):
|
|
|
26
26
|
"""
|
|
27
27
|
The action used to improve outputs that fail one or more guardrail metrics for
|
|
28
28
|
the workflow events. May be `regenerate`, `fixit`, or null which represents “do
|
|
29
|
-
nothing”.
|
|
29
|
+
nothing”. Regenerate runs the user's input prompt with minor induced variance.
|
|
30
30
|
Fixit attempts to directly address the shortcomings of the output using the
|
|
31
31
|
guardrail failure rationale. Do nothing does not attempt any improvement.
|
|
32
32
|
"""
|
|
@@ -5,10 +5,10 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import Dict, Union
|
|
6
6
|
from typing_extensions import Literal, Required, TypeAlias, TypedDict
|
|
7
7
|
|
|
8
|
-
__all__ = ["
|
|
8
|
+
__all__ = ["DefendSubmitEventParams", "ModelInput"]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class DefendSubmitEventParams(TypedDict, total=False):
|
|
12
12
|
model_input: Required[ModelInput]
|
|
13
13
|
"""A dictionary of inputs sent to the LLM to generate output.
|
|
14
14
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing_extensions import
|
|
5
|
+
from typing_extensions import TypedDict
|
|
6
6
|
|
|
7
7
|
__all__ = ["DefendUpdateWorkflowParams"]
|
|
8
8
|
|
|
@@ -13,6 +13,3 @@ class DefendUpdateWorkflowParams(TypedDict, total=False):
|
|
|
13
13
|
|
|
14
14
|
name: str
|
|
15
15
|
"""Name of the workflow."""
|
|
16
|
-
|
|
17
|
-
type: Literal["automatic", "custom"]
|
|
18
|
-
"""Type of thresholds to use for the workflow, either `automatic` or `custom`."""
|
|
@@ -72,7 +72,6 @@ class MonitorRetrieveResponse(BaseModel):
|
|
|
72
72
|
"""Represents whether the request was completed successfully."""
|
|
73
73
|
|
|
74
74
|
data: Optional[Data] = None
|
|
75
|
-
"""Detailed response payload for retrieving a monitor and its evaluations."""
|
|
76
75
|
|
|
77
76
|
message: Optional[str] = None
|
|
78
77
|
"""The accompanying message for the request.
|
|
@@ -27,7 +27,6 @@ class MonitorSubmitEventResponse(BaseModel):
|
|
|
27
27
|
"""Represents whether the request was completed successfully."""
|
|
28
28
|
|
|
29
29
|
data: Optional[Data] = None
|
|
30
|
-
"""Response payload for monitor event operations."""
|
|
31
30
|
|
|
32
31
|
message: Optional[str] = None
|
|
33
32
|
"""The accompanying message for the request.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: deeprails
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: The official Python library for the deeprails API
|
|
5
|
-
Project-URL: Homepage, https://
|
|
6
|
-
Project-URL: Repository, https://github.com/deeprails/deeprails-python
|
|
7
|
-
Author-email:
|
|
5
|
+
Project-URL: Homepage, https://docs.deeprails.com/
|
|
6
|
+
Project-URL: Repository, https://github.com/deeprails/deeprails-sdk-python
|
|
7
|
+
Author-email: DeepRails <support@deeprails.ai>
|
|
8
8
|
License: Apache-2.0
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
10
10
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -42,11 +42,9 @@ The Deeprails Python library provides convenient access to the Deeprails REST AP
|
|
|
42
42
|
application. The library includes type definitions for all request params and response fields,
|
|
43
43
|
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
|
|
44
44
|
|
|
45
|
-
It is generated with [Stainless](https://www.stainless.com/).
|
|
46
|
-
|
|
47
45
|
## Documentation
|
|
48
46
|
|
|
49
|
-
The full API of this library can be found in [api.md](https://github.com/deeprails/deeprails-python
|
|
47
|
+
The REST API documentation can be found on [docs.deeprails.com](https://docs.deeprails.com). The full API of this library can be found in [api.md](https://github.com/deeprails/deeprails-sdk-python/tree/main/api.md).
|
|
50
48
|
|
|
51
49
|
## Installation
|
|
52
50
|
|
|
@@ -57,7 +55,7 @@ pip install deeprails
|
|
|
57
55
|
|
|
58
56
|
## Usage
|
|
59
57
|
|
|
60
|
-
The full API of this library can be found in [api.md](https://github.com/deeprails/deeprails-python
|
|
58
|
+
The full API of this library can be found in [api.md](https://github.com/deeprails/deeprails-sdk-python/tree/main/api.md).
|
|
61
59
|
|
|
62
60
|
```python
|
|
63
61
|
import os
|
|
@@ -65,26 +63,16 @@ from deeprails import Deeprails
|
|
|
65
63
|
|
|
66
64
|
client = Deeprails(
|
|
67
65
|
api_key=os.environ.get("DEEPRAILS_API_KEY"), # This is the default and can be omitted
|
|
68
|
-
# defaults to "production".
|
|
69
|
-
environment="environment_1",
|
|
70
66
|
)
|
|
71
67
|
|
|
72
68
|
defend_response = client.defend.create_workflow(
|
|
73
|
-
improvement_action="
|
|
69
|
+
improvement_action="fixit",
|
|
74
70
|
metrics={
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"2": 0,
|
|
78
|
-
"3": 0,
|
|
79
|
-
"4": 0,
|
|
80
|
-
"5": 0,
|
|
81
|
-
"6": 0,
|
|
82
|
-
"7": 0,
|
|
83
|
-
"8": 0,
|
|
84
|
-
"9": 0,
|
|
71
|
+
"completeness": 0.8,
|
|
72
|
+
"instruction_adherence": 0.75,
|
|
85
73
|
},
|
|
86
|
-
name="
|
|
87
|
-
type="
|
|
74
|
+
name="Push Alert Workflow",
|
|
75
|
+
type="custom",
|
|
88
76
|
)
|
|
89
77
|
print(defend_response.workflow_id)
|
|
90
78
|
```
|
|
@@ -105,28 +93,18 @@ from deeprails import AsyncDeeprails
|
|
|
105
93
|
|
|
106
94
|
client = AsyncDeeprails(
|
|
107
95
|
api_key=os.environ.get("DEEPRAILS_API_KEY"), # This is the default and can be omitted
|
|
108
|
-
# defaults to "production".
|
|
109
|
-
environment="environment_1",
|
|
110
96
|
)
|
|
111
97
|
|
|
112
98
|
|
|
113
99
|
async def main() -> None:
|
|
114
100
|
defend_response = await client.defend.create_workflow(
|
|
115
|
-
improvement_action="
|
|
101
|
+
improvement_action="fixit",
|
|
116
102
|
metrics={
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"2": 0,
|
|
120
|
-
"3": 0,
|
|
121
|
-
"4": 0,
|
|
122
|
-
"5": 0,
|
|
123
|
-
"6": 0,
|
|
124
|
-
"7": 0,
|
|
125
|
-
"8": 0,
|
|
126
|
-
"9": 0,
|
|
103
|
+
"completeness": 0.8,
|
|
104
|
+
"instruction_adherence": 0.75,
|
|
127
105
|
},
|
|
128
|
-
name="
|
|
129
|
-
type="
|
|
106
|
+
name="Push Alert Workflow",
|
|
107
|
+
type="custom",
|
|
130
108
|
)
|
|
131
109
|
print(defend_response.workflow_id)
|
|
132
110
|
|
|
@@ -161,21 +139,13 @@ async def main() -> None:
|
|
|
161
139
|
http_client=DefaultAioHttpClient(),
|
|
162
140
|
) as client:
|
|
163
141
|
defend_response = await client.defend.create_workflow(
|
|
164
|
-
improvement_action="
|
|
142
|
+
improvement_action="fixit",
|
|
165
143
|
metrics={
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"2": 0,
|
|
169
|
-
"3": 0,
|
|
170
|
-
"4": 0,
|
|
171
|
-
"5": 0,
|
|
172
|
-
"6": 0,
|
|
173
|
-
"7": 0,
|
|
174
|
-
"8": 0,
|
|
175
|
-
"9": 0,
|
|
144
|
+
"completeness": 0.8,
|
|
145
|
+
"instruction_adherence": 0.75,
|
|
176
146
|
},
|
|
177
|
-
name="
|
|
178
|
-
type="
|
|
147
|
+
name="Push Alert Workflow",
|
|
148
|
+
type="custom",
|
|
179
149
|
)
|
|
180
150
|
print(defend_response.workflow_id)
|
|
181
151
|
|
|
@@ -201,7 +171,7 @@ from deeprails import Deeprails
|
|
|
201
171
|
|
|
202
172
|
client = Deeprails()
|
|
203
173
|
|
|
204
|
-
workflow_event_response = client.defend.
|
|
174
|
+
workflow_event_response = client.defend.submit_event(
|
|
205
175
|
workflow_id="workflow_id",
|
|
206
176
|
model_input={"user_prompt": "user_prompt"},
|
|
207
177
|
model_output="model_output",
|
|
@@ -229,21 +199,13 @@ client = Deeprails()
|
|
|
229
199
|
|
|
230
200
|
try:
|
|
231
201
|
client.defend.create_workflow(
|
|
232
|
-
improvement_action="
|
|
202
|
+
improvement_action="fixit",
|
|
233
203
|
metrics={
|
|
234
|
-
"
|
|
235
|
-
"
|
|
236
|
-
"2": 0,
|
|
237
|
-
"3": 0,
|
|
238
|
-
"4": 0,
|
|
239
|
-
"5": 0,
|
|
240
|
-
"6": 0,
|
|
241
|
-
"7": 0,
|
|
242
|
-
"8": 0,
|
|
243
|
-
"9": 0,
|
|
204
|
+
"completeness": 0.8,
|
|
205
|
+
"instruction_adherence": 0.75,
|
|
244
206
|
},
|
|
245
|
-
name="
|
|
246
|
-
type="
|
|
207
|
+
name="Push Alert Workflow",
|
|
208
|
+
type="custom",
|
|
247
209
|
)
|
|
248
210
|
except deeprails.APIConnectionError as e:
|
|
249
211
|
print("The server could not be reached")
|
|
@@ -288,21 +250,13 @@ client = Deeprails(
|
|
|
288
250
|
|
|
289
251
|
# Or, configure per-request:
|
|
290
252
|
client.with_options(max_retries=5).defend.create_workflow(
|
|
291
|
-
improvement_action="
|
|
253
|
+
improvement_action="fixit",
|
|
292
254
|
metrics={
|
|
293
|
-
"
|
|
294
|
-
"
|
|
295
|
-
"2": 0,
|
|
296
|
-
"3": 0,
|
|
297
|
-
"4": 0,
|
|
298
|
-
"5": 0,
|
|
299
|
-
"6": 0,
|
|
300
|
-
"7": 0,
|
|
301
|
-
"8": 0,
|
|
302
|
-
"9": 0,
|
|
255
|
+
"completeness": 0.8,
|
|
256
|
+
"instruction_adherence": 0.75,
|
|
303
257
|
},
|
|
304
|
-
name="
|
|
305
|
-
type="
|
|
258
|
+
name="Push Alert Workflow",
|
|
259
|
+
type="custom",
|
|
306
260
|
)
|
|
307
261
|
```
|
|
308
262
|
|
|
@@ -327,27 +281,19 @@ client = Deeprails(
|
|
|
327
281
|
|
|
328
282
|
# Override per-request:
|
|
329
283
|
client.with_options(timeout=5.0).defend.create_workflow(
|
|
330
|
-
improvement_action="
|
|
284
|
+
improvement_action="fixit",
|
|
331
285
|
metrics={
|
|
332
|
-
"
|
|
333
|
-
"
|
|
334
|
-
"2": 0,
|
|
335
|
-
"3": 0,
|
|
336
|
-
"4": 0,
|
|
337
|
-
"5": 0,
|
|
338
|
-
"6": 0,
|
|
339
|
-
"7": 0,
|
|
340
|
-
"8": 0,
|
|
341
|
-
"9": 0,
|
|
286
|
+
"completeness": 0.8,
|
|
287
|
+
"instruction_adherence": 0.75,
|
|
342
288
|
},
|
|
343
|
-
name="
|
|
344
|
-
type="
|
|
289
|
+
name="Push Alert Workflow",
|
|
290
|
+
type="custom",
|
|
345
291
|
)
|
|
346
292
|
```
|
|
347
293
|
|
|
348
294
|
On timeout, an `APITimeoutError` is thrown.
|
|
349
295
|
|
|
350
|
-
Note that requests that time out are [retried twice by default](https://github.com/deeprails/deeprails-python
|
|
296
|
+
Note that requests that time out are [retried twice by default](https://github.com/deeprails/deeprails-sdk-python/tree/main/#retries).
|
|
351
297
|
|
|
352
298
|
## Advanced
|
|
353
299
|
|
|
@@ -384,21 +330,13 @@ from deeprails import Deeprails
|
|
|
384
330
|
|
|
385
331
|
client = Deeprails()
|
|
386
332
|
response = client.defend.with_raw_response.create_workflow(
|
|
387
|
-
improvement_action="
|
|
333
|
+
improvement_action="fixit",
|
|
388
334
|
metrics={
|
|
389
|
-
"
|
|
390
|
-
"
|
|
391
|
-
"2": 0,
|
|
392
|
-
"3": 0,
|
|
393
|
-
"4": 0,
|
|
394
|
-
"5": 0,
|
|
395
|
-
"6": 0,
|
|
396
|
-
"7": 0,
|
|
397
|
-
"8": 0,
|
|
398
|
-
"9": 0,
|
|
335
|
+
"completeness": 0.8,
|
|
336
|
+
"instruction_adherence": 0.75,
|
|
399
337
|
},
|
|
400
|
-
name="
|
|
401
|
-
type="
|
|
338
|
+
name="Push Alert Workflow",
|
|
339
|
+
type="custom",
|
|
402
340
|
)
|
|
403
341
|
print(response.headers.get('X-My-Header'))
|
|
404
342
|
|
|
@@ -406,9 +344,9 @@ defend = response.parse() # get the object that `defend.create_workflow()` woul
|
|
|
406
344
|
print(defend.workflow_id)
|
|
407
345
|
```
|
|
408
346
|
|
|
409
|
-
These methods return an [`APIResponse`](https://github.com/deeprails/deeprails-python
|
|
347
|
+
These methods return an [`APIResponse`](https://github.com/deeprails/deeprails-sdk-python/tree/main/src/deeprails/_response.py) object.
|
|
410
348
|
|
|
411
|
-
The async client returns an [`AsyncAPIResponse`](https://github.com/deeprails/deeprails-python
|
|
349
|
+
The async client returns an [`AsyncAPIResponse`](https://github.com/deeprails/deeprails-sdk-python/tree/main/src/deeprails/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
|
|
412
350
|
|
|
413
351
|
#### `.with_streaming_response`
|
|
414
352
|
|
|
@@ -418,21 +356,13 @@ To stream the response body, use `.with_streaming_response` instead, which requi
|
|
|
418
356
|
|
|
419
357
|
```python
|
|
420
358
|
with client.defend.with_streaming_response.create_workflow(
|
|
421
|
-
improvement_action="
|
|
359
|
+
improvement_action="fixit",
|
|
422
360
|
metrics={
|
|
423
|
-
"
|
|
424
|
-
"
|
|
425
|
-
"2": 0,
|
|
426
|
-
"3": 0,
|
|
427
|
-
"4": 0,
|
|
428
|
-
"5": 0,
|
|
429
|
-
"6": 0,
|
|
430
|
-
"7": 0,
|
|
431
|
-
"8": 0,
|
|
432
|
-
"9": 0,
|
|
361
|
+
"completeness": 0.8,
|
|
362
|
+
"instruction_adherence": 0.75,
|
|
433
363
|
},
|
|
434
|
-
name="
|
|
435
|
-
type="
|
|
364
|
+
name="Push Alert Workflow",
|
|
365
|
+
type="custom",
|
|
436
366
|
) as response:
|
|
437
367
|
print(response.headers.get("X-My-Header"))
|
|
438
368
|
|
|
@@ -442,109 +372,6 @@ with client.defend.with_streaming_response.create_workflow(
|
|
|
442
372
|
|
|
443
373
|
The context manager is required so that the response will reliably be closed.
|
|
444
374
|
|
|
445
|
-
### Making custom/undocumented requests
|
|
446
|
-
|
|
447
|
-
This library is typed for convenient access to the documented API.
|
|
448
|
-
|
|
449
|
-
If you need to access undocumented endpoints, params, or response properties, the library can still be used.
|
|
450
|
-
|
|
451
|
-
#### Undocumented endpoints
|
|
452
|
-
|
|
453
|
-
To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
|
|
454
|
-
http verbs. Options on the client will be respected (such as retries) when making this request.
|
|
455
|
-
|
|
456
|
-
```py
|
|
457
|
-
import httpx
|
|
458
|
-
|
|
459
|
-
response = client.post(
|
|
460
|
-
"/foo",
|
|
461
|
-
cast_to=httpx.Response,
|
|
462
|
-
body={"my_param": True},
|
|
463
|
-
)
|
|
464
|
-
|
|
465
|
-
print(response.headers.get("x-foo"))
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
#### Undocumented request params
|
|
469
|
-
|
|
470
|
-
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
|
|
471
|
-
options.
|
|
472
|
-
|
|
473
|
-
#### Undocumented response properties
|
|
474
|
-
|
|
475
|
-
To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
|
|
476
|
-
can also get all the extra fields on the Pydantic model as a dict with
|
|
477
|
-
[`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
|
|
478
|
-
|
|
479
|
-
### Configuring the HTTP client
|
|
480
|
-
|
|
481
|
-
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
|
|
482
|
-
|
|
483
|
-
- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
|
|
484
|
-
- Custom [transports](https://www.python-httpx.org/advanced/transports/)
|
|
485
|
-
- Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
|
|
486
|
-
|
|
487
|
-
```python
|
|
488
|
-
import httpx
|
|
489
|
-
from deeprails import Deeprails, DefaultHttpxClient
|
|
490
|
-
|
|
491
|
-
client = Deeprails(
|
|
492
|
-
# Or use the `DEEPRAILS_BASE_URL` env var
|
|
493
|
-
base_url="http://my.test.server.example.com:8083",
|
|
494
|
-
http_client=DefaultHttpxClient(
|
|
495
|
-
proxy="http://my.test.proxy.example.com",
|
|
496
|
-
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
497
|
-
),
|
|
498
|
-
)
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
You can also customize the client on a per-request basis by using `with_options()`:
|
|
502
|
-
|
|
503
|
-
```python
|
|
504
|
-
client.with_options(http_client=DefaultHttpxClient(...))
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
### Managing HTTP resources
|
|
508
|
-
|
|
509
|
-
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
|
|
510
|
-
|
|
511
|
-
```py
|
|
512
|
-
from deeprails import Deeprails
|
|
513
|
-
|
|
514
|
-
with Deeprails() as client:
|
|
515
|
-
# make requests here
|
|
516
|
-
...
|
|
517
|
-
|
|
518
|
-
# HTTP client is now closed
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
## Versioning
|
|
522
|
-
|
|
523
|
-
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
|
524
|
-
|
|
525
|
-
1. Changes that only affect static types, without breaking runtime behavior.
|
|
526
|
-
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
|
|
527
|
-
3. Changes that we do not expect to impact the vast majority of users in practice.
|
|
528
|
-
|
|
529
|
-
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
|
530
|
-
|
|
531
|
-
We are keen for your feedback; please open an [issue](https://www.github.com/deeprails/deeprails-python-sdk/issues) with questions, bugs, or suggestions.
|
|
532
|
-
|
|
533
|
-
### Determining the installed version
|
|
534
|
-
|
|
535
|
-
If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
|
|
536
|
-
|
|
537
|
-
You can determine the version that is being used at runtime with:
|
|
538
|
-
|
|
539
|
-
```py
|
|
540
|
-
import deeprails
|
|
541
|
-
print(deeprails.__version__)
|
|
542
|
-
```
|
|
543
|
-
|
|
544
375
|
## Requirements
|
|
545
376
|
|
|
546
377
|
Python 3.8 or higher.
|
|
547
|
-
|
|
548
|
-
## Contributing
|
|
549
|
-
|
|
550
|
-
See [the contributing documentation](https://github.com/deeprails/deeprails-python-sdk/tree/main/./CONTRIBUTING.md).
|