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.
- deeprails/__init__.py +104 -1
- deeprails/_base_client.py +1995 -0
- deeprails/_client.py +478 -0
- deeprails/_compat.py +219 -0
- deeprails/_constants.py +14 -0
- deeprails/_exceptions.py +108 -0
- deeprails/_files.py +123 -0
- deeprails/_models.py +835 -0
- deeprails/_qs.py +150 -0
- deeprails/_resource.py +43 -0
- deeprails/_response.py +830 -0
- deeprails/_streaming.py +333 -0
- deeprails/_types.py +260 -0
- deeprails/_utils/__init__.py +64 -0
- deeprails/_utils/_compat.py +45 -0
- deeprails/_utils/_datetime_parse.py +136 -0
- deeprails/_utils/_logs.py +25 -0
- deeprails/_utils/_proxy.py +65 -0
- deeprails/_utils/_reflection.py +42 -0
- deeprails/_utils/_resources_proxy.py +24 -0
- deeprails/_utils/_streams.py +12 -0
- deeprails/_utils/_sync.py +86 -0
- deeprails/_utils/_transform.py +457 -0
- deeprails/_utils/_typing.py +156 -0
- deeprails/_utils/_utils.py +421 -0
- deeprails/_version.py +4 -0
- deeprails/lib/.keep +4 -0
- deeprails/py.typed +0 -0
- deeprails/resources/__init__.py +47 -0
- deeprails/resources/defend/__init__.py +33 -0
- deeprails/resources/defend/defend.py +480 -0
- deeprails/resources/defend/events.py +311 -0
- deeprails/resources/evaluate.py +334 -0
- deeprails/resources/monitor.py +566 -0
- deeprails/types/__init__.py +16 -0
- deeprails/types/api_response.py +50 -0
- deeprails/types/defend/__init__.py +6 -0
- deeprails/types/defend/event_submit_event_params.py +44 -0
- deeprails/types/defend/workflow_event_response.py +33 -0
- deeprails/types/defend_create_workflow_params.py +56 -0
- deeprails/types/defend_response.py +50 -0
- deeprails/types/defend_update_workflow_params.py +18 -0
- deeprails/types/evaluate_create_params.py +60 -0
- deeprails/types/evaluation.py +113 -0
- deeprails/types/monitor_create_params.py +15 -0
- deeprails/types/monitor_retrieve_params.py +12 -0
- deeprails/types/monitor_retrieve_response.py +81 -0
- deeprails/types/monitor_submit_event_params.py +63 -0
- deeprails/types/monitor_submit_event_response.py +36 -0
- deeprails/types/monitor_update_params.py +22 -0
- deeprails-1.0.0.dist-info/METADATA +550 -0
- deeprails-1.0.0.dist-info/RECORD +54 -0
- {deeprails-0.3.1.dist-info → deeprails-1.0.0.dist-info}/WHEEL +1 -1
- deeprails-1.0.0.dist-info/licenses/LICENSE +201 -0
- deeprails/client.py +0 -285
- deeprails/exceptions.py +0 -10
- deeprails/schemas.py +0 -92
- deeprails-0.3.1.dist-info/METADATA +0 -235
- deeprails-0.3.1.dist-info/RECORD +0 -8
- deeprails-0.3.1.dist-info/licenses/LICENSE +0 -11
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deeprails
|
|
3
|
-
Version: 0.3.1
|
|
4
|
-
Summary: Python SDK for interacting with the DeepRails API
|
|
5
|
-
Project-URL: Homepage, https://deeprails.com
|
|
6
|
-
Project-URL: Documentation, https://docs.deeprails.com
|
|
7
|
-
Author-email: Neil Mate <support@deeprails.ai>
|
|
8
|
-
License: MIT License
|
|
9
|
-
|
|
10
|
-
Copyright (c) [2025] [DeepRails Inc.ß]
|
|
11
|
-
|
|
12
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
|
-
License-File: LICENSE
|
|
20
|
-
Keywords: ai,deeprails,evaluation,genai,guardrails,sdk
|
|
21
|
-
Classifier: Intended Audience :: Developers
|
|
22
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
23
|
-
Classifier: Operating System :: OS Independent
|
|
24
|
-
Classifier: Programming Language :: Python :: 3
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
26
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
27
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
28
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
29
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
30
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
31
|
-
Requires-Python: >=3.8
|
|
32
|
-
Requires-Dist: httpx<0.29.0,>=0.28.1
|
|
33
|
-
Requires-Dist: pydantic<3.0.0,>=2.11.7
|
|
34
|
-
Description-Content-Type: text/markdown
|
|
35
|
-
|
|
36
|
-
# DeepRails Python SDK
|
|
37
|
-
|
|
38
|
-
Official Python SDK for interacting with the DeepRails API. [DeepRails](https://deeprails.com) is a powerful developer tool with a comprehesive set of adaptive guardrails to protect against LLM hallucinations - deploy our Evaluate, Monitor, and Defend APIs in <15 mins for the best out-of-the-box guardrails in the market.
|
|
39
|
-
|
|
40
|
-
Supports DeepRails API Version v2.0
|
|
41
|
-
|
|
42
|
-
## Installation
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
pip install deeprails
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Quick Start
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
from deeprails import DeepRails
|
|
52
|
-
|
|
53
|
-
# Initialize with your API token
|
|
54
|
-
client = DeepRails(token="YOUR_API_KEY")
|
|
55
|
-
|
|
56
|
-
# Create an evaluation
|
|
57
|
-
evaluation = client.create_evaluation(
|
|
58
|
-
model_input={"user_prompt": "Prompt used to generate completion"},
|
|
59
|
-
model_output="Generated output",
|
|
60
|
-
model_used="gpt-4o-mini",
|
|
61
|
-
guardrail_metrics=["correctness", "completeness"]
|
|
62
|
-
)
|
|
63
|
-
print(f"Evaluation created with ID: {evaluation.eval_id}")
|
|
64
|
-
|
|
65
|
-
# Create a monitor
|
|
66
|
-
monitor = client.create_monitor(
|
|
67
|
-
name="Production Assistant Monitor",
|
|
68
|
-
description="Tracking our production assistant quality"
|
|
69
|
-
)
|
|
70
|
-
print(f"Monitor created with ID: {monitor.monitor_id}")
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Features
|
|
74
|
-
|
|
75
|
-
- **Simple API**: Just a few lines of code to integrate evaluation into your workflow
|
|
76
|
-
- **Comprehensive Metrics**: Evaluate outputs on correctness, completeness, and more
|
|
77
|
-
- **Real-time Progress**: Track evaluation progress in real-time
|
|
78
|
-
- **Detailed Results**: Get detailed scores and rationales for each metric
|
|
79
|
-
- **Continuous Monitoring**: Create monitors to track AI system performance over time
|
|
80
|
-
|
|
81
|
-
## Authentication
|
|
82
|
-
|
|
83
|
-
All API requests require authentication using your DeepRails API key. Your API key is a sensitive credential that should be kept secure.
|
|
84
|
-
|
|
85
|
-
```python
|
|
86
|
-
# Best practice: Load token from environment variable
|
|
87
|
-
import os
|
|
88
|
-
token = os.environ.get("DEEPRAILS_API_KEY")
|
|
89
|
-
client = DeepRails(token=token)
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Evaluation Service
|
|
93
|
-
|
|
94
|
-
### Creating Evaluations
|
|
95
|
-
|
|
96
|
-
```python
|
|
97
|
-
try:
|
|
98
|
-
evaluation = client.create_evaluation(
|
|
99
|
-
model_input={"user_prompt": "Prompt used to generate completion"},
|
|
100
|
-
model_output="Generated output",
|
|
101
|
-
model_used="gpt-4o-mini",
|
|
102
|
-
guardrail_metrics=["correctness", "completeness"]
|
|
103
|
-
)
|
|
104
|
-
print(f"ID: {evaluation.eval_id}")
|
|
105
|
-
print(f"Status: {evaluation.evaluation_status}")
|
|
106
|
-
print(f"Progress: {evaluation.progress}%")
|
|
107
|
-
except Exception as e:
|
|
108
|
-
print(f"Error: {e}")
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
#### Parameters
|
|
112
|
-
|
|
113
|
-
- `model_input`: Dictionary containing the prompt and any context (must include `user_prompt`)
|
|
114
|
-
- `model_output`: The generated output to evaluate
|
|
115
|
-
- `model_used`: (Optional) The model that generated the output
|
|
116
|
-
- `run_mode`: (Optional) Evaluation run mode - defaults to "smart"
|
|
117
|
-
- `guardrail_metrics`: (Optional) List of metrics to evaluate
|
|
118
|
-
- `nametag`: (Optional) Custom identifier for this evaluation
|
|
119
|
-
- `webhook`: (Optional) URL to receive completion notifications
|
|
120
|
-
|
|
121
|
-
### Retrieving Evaluations
|
|
122
|
-
|
|
123
|
-
```python
|
|
124
|
-
try:
|
|
125
|
-
eval_id = "eval-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
126
|
-
evaluation = client.get_evaluation(eval_id)
|
|
127
|
-
|
|
128
|
-
print(f"Status: {evaluation.evaluation_status}")
|
|
129
|
-
|
|
130
|
-
if evaluation.evaluation_result:
|
|
131
|
-
print("\nResults:")
|
|
132
|
-
for metric, result in evaluation.evaluation_result.items():
|
|
133
|
-
score = result.get('score', 'N/A')
|
|
134
|
-
print(f" {metric}: {score}")
|
|
135
|
-
except Exception as e:
|
|
136
|
-
print(f"Error: {e}")
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## Monitor Service
|
|
140
|
-
|
|
141
|
-
### Creating Monitors
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
try:
|
|
145
|
-
# Create a monitor
|
|
146
|
-
monitor = client.create_monitor(
|
|
147
|
-
name="Production Chat Assistant Monitor",
|
|
148
|
-
description="Monitoring our production chatbot responses"
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
print(f"Monitor created with ID: {monitor.monitor_id}")
|
|
152
|
-
except Exception as e:
|
|
153
|
-
print(f"Error: {e}")
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Logging Monitor Events
|
|
157
|
-
|
|
158
|
-
```python
|
|
159
|
-
try:
|
|
160
|
-
# Add an event to the monitor
|
|
161
|
-
event = client.create_monitor_event(
|
|
162
|
-
monitor_id="mon-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
163
|
-
model_input={"user_prompt": "Tell me about renewable energy"},
|
|
164
|
-
model_output="Renewable energy comes from natural sources...",
|
|
165
|
-
model_used="gpt-4o-mini",
|
|
166
|
-
guardrail_metrics=["correctness", "completeness", "comprehensive_safety"]
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
print(f"Monitor event created with ID: {event.event_id}")
|
|
170
|
-
print(f"Associated evaluation ID: {event.evaluation_id}")
|
|
171
|
-
except Exception as e:
|
|
172
|
-
print(f"Error: {e}")
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Retrieving Monitor Data
|
|
176
|
-
|
|
177
|
-
```python
|
|
178
|
-
try:
|
|
179
|
-
# Get monitor details
|
|
180
|
-
monitor = client.get_monitor("mon-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
|
|
181
|
-
print(f"Monitor name: {monitor.name}")
|
|
182
|
-
print(f"Status: {monitor.monitor_status}")
|
|
183
|
-
|
|
184
|
-
# Get monitor events
|
|
185
|
-
events = client.get_monitor_events(
|
|
186
|
-
monitor_id="mon-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
187
|
-
limit=10
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
for event in events:
|
|
191
|
-
print(f"Event ID: {event.event_id}")
|
|
192
|
-
print(f"Evaluation ID: {event.evaluation_id}")
|
|
193
|
-
|
|
194
|
-
# List all monitors with filtering
|
|
195
|
-
monitors = client.get_monitors(
|
|
196
|
-
limit=5,
|
|
197
|
-
monitor_status=["active"],
|
|
198
|
-
sort_by="created_at",
|
|
199
|
-
sort_order="desc"
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
print(f"Total monitors: {monitors.pagination.total_count}")
|
|
203
|
-
for m in monitors.monitors:
|
|
204
|
-
print(f"{m.name}: {m.event_count} events")
|
|
205
|
-
except Exception as e:
|
|
206
|
-
print(f"Error: {e}")
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Available Metrics
|
|
210
|
-
|
|
211
|
-
- `correctness`: Measures factual accuracy by evaluating whether each claim in the output is true and verifiable.
|
|
212
|
-
- `completeness`: Assesses whether the response addresses all necessary parts of the prompt with sufficient detail and relevance.
|
|
213
|
-
- `instruction_adherence`: Checks whether the AI followed the explicit instructions in the prompt and system directives.
|
|
214
|
-
- `context_adherence`: Determines whether each factual claim is directly supported by the provided context.
|
|
215
|
-
- `ground_truth_adherence`: Measures how closely the output matches a known correct answer (gold standard).
|
|
216
|
-
- `comprehensive_safety`: Detects and categorizes safety violations across areas like PII, CBRN, hate speech, self-harm, and more.
|
|
217
|
-
|
|
218
|
-
## Error Handling
|
|
219
|
-
|
|
220
|
-
The SDK throws `DeepRailsAPIError` for API-related errors, with status code and detailed message.
|
|
221
|
-
|
|
222
|
-
```python
|
|
223
|
-
from deeprails import DeepRailsAPIError
|
|
224
|
-
|
|
225
|
-
try:
|
|
226
|
-
# SDK operations
|
|
227
|
-
except DeepRailsAPIError as e:
|
|
228
|
-
print(f"API Error: {e.status_code} - {e.error_detail}")
|
|
229
|
-
except Exception as e:
|
|
230
|
-
print(f"Unexpected error: {e}")
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## Support
|
|
234
|
-
|
|
235
|
-
For questions or support, please contact support@deeprails.ai.
|
deeprails-0.3.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
deeprails/__init__.py,sha256=7ccTz1heYcCd3DIH3wmHc67FD6CUzM8_J4WmDeq0RZ0,29
|
|
2
|
-
deeprails/client.py,sha256=Jv4Z4LR3g_eYO4L86sabOAibHJGV9p8naDOl1Yw-2L0,10406
|
|
3
|
-
deeprails/exceptions.py,sha256=ipwFq4lROv7XpcBC5h9cGqPf6f68zeOMEyKPVy7H0co,405
|
|
4
|
-
deeprails/schemas.py,sha256=XqBUFNEW4nwxm53YIUWVk4fEPsDGC6gzzXGL9lPuRAU,2870
|
|
5
|
-
deeprails-0.3.1.dist-info/METADATA,sha256=uPQ35AwbQiucWBX5STCIUw76PsVksQskx5F_1fPvp3A,8538
|
|
6
|
-
deeprails-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
deeprails-0.3.1.dist-info/licenses/LICENSE,sha256=GsV7lN6fihCcDgkJbfs0rq1q9d6IyB0TFQ8HLKUpSXM,1077
|
|
8
|
-
deeprails-0.3.1.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) [2025] [DeepRails Inc.ß]
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
10
|
-
|
|
11
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|