deeprails 0.1.0__py3-none-any.whl → 0.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.
- deeprails/__init__.py +1 -0
- deeprails/client.py +92 -22
- deeprails/exceptions.py +10 -0
- deeprails/schemas.py +30 -0
- deeprails-0.2.0.dist-info/METADATA +154 -0
- deeprails-0.2.0.dist-info/RECORD +8 -0
- {deeprails-0.1.0.dist-info → deeprails-0.2.0.dist-info}/WHEEL +1 -2
- deeprails/evaluate.py +0 -46
- deeprails/monitor.py +0 -50
- deeprails-0.1.0.dist-info/METADATA +0 -86
- deeprails-0.1.0.dist-info/RECORD +0 -9
- deeprails-0.1.0.dist-info/top_level.txt +0 -1
- {deeprails-0.1.0.dist-info → deeprails-0.2.0.dist-info/licenses}/LICENSE +0 -0
deeprails/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import DeepRails
|
deeprails/client.py
CHANGED
|
@@ -1,31 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
from typing import Dict, Any
|
|
1
|
+
import httpx
|
|
2
|
+
from typing import List, Optional, Dict, Any
|
|
3
3
|
|
|
4
|
-
from .
|
|
5
|
-
from .
|
|
4
|
+
from .schemas import EvaluationResponse
|
|
5
|
+
from .exceptions import DeepRailsAPIError
|
|
6
6
|
|
|
7
7
|
class DeepRails:
|
|
8
8
|
"""
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Usage:
|
|
12
|
-
from deeprails import DeepRails
|
|
13
|
-
|
|
14
|
-
client = DeepRails(token="YOUR_TOKEN")
|
|
15
|
-
resp = client.evaluate.create({...})
|
|
9
|
+
Python SDK client for the DeepRails API.
|
|
16
10
|
"""
|
|
17
|
-
def __init__(self, token: str, base_url: str = "https://deeprails.
|
|
11
|
+
def __init__(self, token: str, base_url: str = "https://api.deeprails.com"):
|
|
18
12
|
"""
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
Initializes the DeepRails client.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
token: Your DeepRails API key (starts with 'sk_').
|
|
17
|
+
base_url: The base URL of the DeepRails API.
|
|
21
18
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
self.
|
|
19
|
+
if not token:
|
|
20
|
+
raise ValueError("A valid DeepRails API token is required.")
|
|
21
|
+
|
|
22
|
+
self._base_url = base_url
|
|
23
|
+
self._headers = {
|
|
24
|
+
"Authorization": f"Bearer {token}",
|
|
26
25
|
"Content-Type": "application/json",
|
|
27
|
-
"
|
|
26
|
+
"User-Agent": "deeprails-python-sdk/0.2.0"
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
self._client = httpx.Client(base_url=self._base_url, headers=self._headers, timeout=30.0)
|
|
29
|
+
|
|
30
|
+
def _request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
|
31
|
+
"""Helper method to make requests and handle API errors."""
|
|
32
|
+
try:
|
|
33
|
+
response = self._client.request(method, endpoint, **kwargs)
|
|
34
|
+
response.raise_for_status()
|
|
35
|
+
return response
|
|
36
|
+
except httpx.HTTPStatusError as e:
|
|
37
|
+
error_detail = "No detail provided."
|
|
38
|
+
try:
|
|
39
|
+
error_detail = e.response.json().get("detail", error_detail)
|
|
40
|
+
except Exception:
|
|
41
|
+
error_detail = e.response.text
|
|
42
|
+
raise DeepRailsAPIError(status_code=e.response.status_code, error_detail=error_detail) from e
|
|
43
|
+
except httpx.RequestError as e:
|
|
44
|
+
raise DeepRailsAPIError(status_code=500, error_detail=f"Request failed: {e}") from e
|
|
45
|
+
|
|
46
|
+
def create_evaluation(
|
|
47
|
+
self,
|
|
48
|
+
*,
|
|
49
|
+
model_input: Dict[str, Any],
|
|
50
|
+
model_output: str,
|
|
51
|
+
model_used: Optional[str] = None,
|
|
52
|
+
run_mode: Optional[str] = "smart", # Set default to "smart"
|
|
53
|
+
guardrail_metrics: Optional[List[str]] = None,
|
|
54
|
+
nametag: Optional[str] = None,
|
|
55
|
+
webhook: Optional[str] = None
|
|
56
|
+
) -> EvaluationResponse:
|
|
57
|
+
"""
|
|
58
|
+
Creates a new evaluation and immediately processes it.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
model_input: A dictionary containing the inputs for the model.
|
|
62
|
+
Must contain a "user_prompt" key.
|
|
63
|
+
model_output: The response generated by the model you are evaluating.
|
|
64
|
+
model_used: The name or identifier of the model being evaluated.
|
|
65
|
+
run_mode: The evaluation mode (e.g., "smart", "dev").
|
|
66
|
+
guardrail_metrics: A list of metrics to evaluate.
|
|
67
|
+
nametag: A user-defined name or tag for the evaluation.
|
|
68
|
+
webhook: A URL to send a POST request to upon evaluation completion.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
An EvaluationResponse object with the details of the created evaluation.
|
|
72
|
+
"""
|
|
73
|
+
if "user_prompt" not in model_input:
|
|
74
|
+
raise ValueError("`model_input` must contain a 'user_prompt' key.")
|
|
75
|
+
|
|
76
|
+
payload = {
|
|
77
|
+
"model_input": model_input,
|
|
78
|
+
"model_output": model_output,
|
|
79
|
+
"model_used": model_used,
|
|
80
|
+
"run_mode": run_mode,
|
|
81
|
+
"guardrail_metrics": guardrail_metrics,
|
|
82
|
+
"nametag": nametag,
|
|
83
|
+
"webhook": webhook,
|
|
84
|
+
}
|
|
85
|
+
json_payload = {k: v for k, v in payload.items() if v is not None}
|
|
86
|
+
|
|
87
|
+
response = self._request("POST", "/evaluate", json=json_payload)
|
|
88
|
+
return EvaluationResponse.parse_obj(response.json())
|
|
89
|
+
|
|
90
|
+
def get_evaluation(self, eval_id: str) -> EvaluationResponse:
|
|
91
|
+
"""
|
|
92
|
+
Retrieves the status and results of a specific evaluation.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
eval_id: The unique identifier of the evaluation.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
An EvaluationResponse object with the full, up-to-date details of the evaluation.
|
|
99
|
+
"""
|
|
100
|
+
response = self._request("GET", f"/evaluate/{eval_id}")
|
|
101
|
+
return EvaluationResponse.parse_obj(response.json())
|
deeprails/exceptions.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class DeepRailsError(Exception):
|
|
2
|
+
"""Base exception class for the DeepRails SDK."""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
class DeepRailsAPIError(DeepRailsError):
|
|
6
|
+
"""Raised when the DeepRails API returns an error."""
|
|
7
|
+
def __init__(self, status_code: int, error_detail: str):
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
self.error_detail = error_detail
|
|
10
|
+
super().__init__(f"API Error {status_code}: {error_detail}")
|
deeprails/schemas.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from typing import List, Optional, Dict, Any
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class EvaluationResponse(BaseModel):
|
|
7
|
+
"""Represents the response for an evaluation from the DeepRails API."""
|
|
8
|
+
eval_id: str
|
|
9
|
+
evaluation_status: str
|
|
10
|
+
guardrail_metrics: Optional[List[str]] = None
|
|
11
|
+
model_used: Optional[str] = None
|
|
12
|
+
run_mode: Optional[str] = None
|
|
13
|
+
model_input: Optional[Dict[str, Any]] = None
|
|
14
|
+
model_output: Optional[str] = None
|
|
15
|
+
estimated_cost: Optional[float] = None
|
|
16
|
+
input_tokens: Optional[int] = None
|
|
17
|
+
output_tokens: Optional[int] = None
|
|
18
|
+
nametag: Optional[str] = None
|
|
19
|
+
progress: Optional[int] = Field(None, ge=0, le=100)
|
|
20
|
+
start_timestamp: Optional[datetime] = None
|
|
21
|
+
completion_timestamp: Optional[datetime] = None
|
|
22
|
+
error_message: Optional[str] = None
|
|
23
|
+
error_timestamp: Optional[datetime] = None
|
|
24
|
+
evaluation_result: Optional[Dict[str, Any]] = None
|
|
25
|
+
evaluation_total_cost: Optional[float] = None
|
|
26
|
+
created_at: Optional[datetime] = None
|
|
27
|
+
modified_at: Optional[datetime] = None
|
|
28
|
+
|
|
29
|
+
class Config:
|
|
30
|
+
extra = 'ignore'
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deeprails
|
|
3
|
+
Version: 0.2.0
|
|
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
|
+
A lightweight, intuitive Python SDK for interacting with the DeepRails API. DeepRails helps you evaluate and improve AI-generated outputs through a comprehensive set of guardrail metrics.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install deeprails
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from deeprails import DeepRails
|
|
50
|
+
|
|
51
|
+
# Initialize with your API token
|
|
52
|
+
client = DeepRails(token="YOUR_API_KEY")
|
|
53
|
+
|
|
54
|
+
# Create an evaluation
|
|
55
|
+
evaluation = client.create_evaluation(
|
|
56
|
+
model_input={"user_prompt": "Prompt used to generate completion"},
|
|
57
|
+
model_output="Generated output",
|
|
58
|
+
model_used="gpt-4o-mini (LLM used to generate completion)",
|
|
59
|
+
guardrail_metrics=["correctness", "completeness"]
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Print evaluation ID
|
|
63
|
+
print(f"Evaluation created with ID: {evaluation.eval_id}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Features
|
|
67
|
+
|
|
68
|
+
- **Simple API**: Just a few lines of code to integrate evaluation into your workflow
|
|
69
|
+
- **Comprehensive Metrics**: Evaluate outputs on correctness, completeness, and more
|
|
70
|
+
- **Real-time Progress**: Track evaluation progress in real-time
|
|
71
|
+
- **Detailed Results**: Get detailed scores and rationales for each metric
|
|
72
|
+
|
|
73
|
+
## Authentication
|
|
74
|
+
|
|
75
|
+
All API requests require authentication using your DeepRails API key. Your API key is a sensitive credential that should be kept secure.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# Best practice: Load token from environment variable
|
|
79
|
+
import os
|
|
80
|
+
token = os.environ.get("DEEPRAILS_API_KEY")
|
|
81
|
+
client = DeepRails(token=token)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Creating Evaluations
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
try:
|
|
88
|
+
evaluation = client.create_evaluation(
|
|
89
|
+
model_input={"user_prompt": "Prompt used to generate completion"},
|
|
90
|
+
model_output="Generated output",
|
|
91
|
+
model_used="gpt-4o-mini (LLM used to generate completion)",
|
|
92
|
+
guardrail_metrics=["correctness", "completeness"]
|
|
93
|
+
)
|
|
94
|
+
print(f"ID: {evaluation.eval_id}")
|
|
95
|
+
print(f"Status: {evaluation.evaluation_status}")
|
|
96
|
+
print(f"Progress: {evaluation.progress}%")
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(f"Error: {e}")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Parameters
|
|
102
|
+
|
|
103
|
+
- `model_input`: Dictionary containing the prompt and any context (must include `user_prompt`)
|
|
104
|
+
- `model_output`: The generated output to evaluate
|
|
105
|
+
- `model_used`: (Optional) The model that generated the output
|
|
106
|
+
- `run_mode`: (Optional) Evaluation run mode - defaults to "smart"
|
|
107
|
+
- `guardrail_metrics`: (Optional) List of metrics to evaluate
|
|
108
|
+
- `nametag`: (Optional) Custom identifier for this evaluation
|
|
109
|
+
- `webhook`: (Optional) URL to receive completion notifications
|
|
110
|
+
|
|
111
|
+
## Retrieving Evaluations
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
try:
|
|
115
|
+
eval_id = "eval-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
116
|
+
evaluation = client.get_evaluation(eval_id)
|
|
117
|
+
|
|
118
|
+
print(f"Status: {evaluation.evaluation_status}")
|
|
119
|
+
|
|
120
|
+
if evaluation.evaluation_result:
|
|
121
|
+
print("\nResults:")
|
|
122
|
+
for metric, result in evaluation.evaluation_result.items():
|
|
123
|
+
score = result.get('score', 'N/A')
|
|
124
|
+
print(f" {metric}: {score}")
|
|
125
|
+
except Exception as e:
|
|
126
|
+
print(f"Error: {e}")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Available Metrics
|
|
130
|
+
|
|
131
|
+
- `correctness`: Evaluates factual accuracy of the output
|
|
132
|
+
- `completeness`: Checks if the output addresses all aspects of the prompt
|
|
133
|
+
- `harmfulness`: Detects potentially harmful content
|
|
134
|
+
- `bias`: Identifies biased language or reasoning
|
|
135
|
+
- And more...
|
|
136
|
+
|
|
137
|
+
## Error Handling
|
|
138
|
+
|
|
139
|
+
The SDK throws `DeepRailsAPIError` for API-related errors, with status code and detailed message.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from deeprails import DeepRailsAPIError
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
# SDK operations
|
|
146
|
+
except DeepRailsAPIError as e:
|
|
147
|
+
print(f"API Error: {e.status_code} - {e.error_detail}")
|
|
148
|
+
except Exception as e:
|
|
149
|
+
print(f"Unexpected error: {e}")
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Support
|
|
153
|
+
|
|
154
|
+
For questions or support, please contact support@deeprails.ai.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
deeprails/__init__.py,sha256=7ccTz1heYcCd3DIH3wmHc67FD6CUzM8_J4WmDeq0RZ0,29
|
|
2
|
+
deeprails/client.py,sha256=gm3aq5FQj7qpLbWeyKkew3gbRI0l9QyGhvk7m0N7JxU,4004
|
|
3
|
+
deeprails/exceptions.py,sha256=ipwFq4lROv7XpcBC5h9cGqPf6f68zeOMEyKPVy7H0co,405
|
|
4
|
+
deeprails/schemas.py,sha256=pqZ-J7mIVdYe-q8sPSw07fe3H4YFCYb-PrshA_qU8RU,1113
|
|
5
|
+
deeprails-0.2.0.dist-info/METADATA,sha256=Evweth9DLw-iHgbfZQdhfFG0i6MMXnm0GRkPyhscJe0,5759
|
|
6
|
+
deeprails-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
deeprails-0.2.0.dist-info/licenses/LICENSE,sha256=GsV7lN6fihCcDgkJbfs0rq1q9d6IyB0TFQ8HLKUpSXM,1077
|
|
8
|
+
deeprails-0.2.0.dist-info/RECORD,,
|
deeprails/evaluate.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from typing import Dict, Any
|
|
3
|
-
|
|
4
|
-
class EvaluateClient:
|
|
5
|
-
"""
|
|
6
|
-
Client for the Evaluate endpoints:
|
|
7
|
-
- POST / (create a new evaluation)
|
|
8
|
-
- GET /{eval_id} (fetch an existing evaluation)
|
|
9
|
-
"""
|
|
10
|
-
def __init__(self, base_url: str, headers: Dict[str, str]):
|
|
11
|
-
self.base_url = f"{base_url}/evaluate"
|
|
12
|
-
self.headers = headers
|
|
13
|
-
|
|
14
|
-
def create(self, evaluation_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
15
|
-
"""
|
|
16
|
-
Create a new evaluation by POSTing to /evaluate.
|
|
17
|
-
|
|
18
|
-
:param evaluation_data: Dict matching the EvaluateCreate model:
|
|
19
|
-
{
|
|
20
|
-
"model_input": {...},
|
|
21
|
-
"model_output": "...",
|
|
22
|
-
"type": "...",
|
|
23
|
-
"guardrails_metrics": [...],
|
|
24
|
-
"score_format": "...",
|
|
25
|
-
"webhook": "..."
|
|
26
|
-
}
|
|
27
|
-
:return: The JSON response from the API as a Python dict
|
|
28
|
-
matching EvaluationResponse.
|
|
29
|
-
"""
|
|
30
|
-
url = self.base_url # e.g. https://deeprails.ai/evaluate
|
|
31
|
-
response = requests.post(url, json=evaluation_data, headers=self.headers)
|
|
32
|
-
response.raise_for_status()
|
|
33
|
-
return response.json()
|
|
34
|
-
|
|
35
|
-
def fetch(self, eval_id: str) -> Dict[str, Any]:
|
|
36
|
-
"""
|
|
37
|
-
Fetch an existing evaluation by GETting /evaluate/{eval_id}.
|
|
38
|
-
|
|
39
|
-
:param eval_id: The ID of the evaluation to retrieve
|
|
40
|
-
:return: The JSON response as a Python dict
|
|
41
|
-
matching EvaluationResponse.
|
|
42
|
-
"""
|
|
43
|
-
url = f"{self.base_url}/{eval_id}"
|
|
44
|
-
response = requests.get(url, headers=self.headers)
|
|
45
|
-
response.raise_for_status()
|
|
46
|
-
return response.json()
|
deeprails/monitor.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from typing import Dict, Any
|
|
3
|
-
|
|
4
|
-
class MonitorClient:
|
|
5
|
-
"""
|
|
6
|
-
Client for the Monitor endpoints:
|
|
7
|
-
- POST / (create a new monitor)
|
|
8
|
-
- POST /{monitor_id}/event (log an event)
|
|
9
|
-
"""
|
|
10
|
-
def __init__(self, base_url: str, headers: Dict[str, str]):
|
|
11
|
-
self.base_url = f"{base_url}/monitor"
|
|
12
|
-
self.headers = headers
|
|
13
|
-
|
|
14
|
-
def create(self, monitor_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
15
|
-
"""
|
|
16
|
-
Create a new monitor.
|
|
17
|
-
|
|
18
|
-
:param monitor_data: Dict matching the MonitorCreate model:
|
|
19
|
-
{
|
|
20
|
-
"name": "...",
|
|
21
|
-
"description": "...",
|
|
22
|
-
"metrics": [...]
|
|
23
|
-
}
|
|
24
|
-
:return: Dictionary with e.g. {"monitor_id": "..."} from the API.
|
|
25
|
-
"""
|
|
26
|
-
url = self.base_url # e.g. https://deeprails.ai/monitor
|
|
27
|
-
response = requests.post(url, json=monitor_data, headers=self.headers)
|
|
28
|
-
response.raise_for_status()
|
|
29
|
-
return response.json()
|
|
30
|
-
|
|
31
|
-
def log(self, monitor_id: str, event_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
32
|
-
"""
|
|
33
|
-
Log an event under a specific monitor.
|
|
34
|
-
|
|
35
|
-
:param monitor_id: ID of the monitor to which we log the event
|
|
36
|
-
:param event_data: Dict matching MonitorEventCreate:
|
|
37
|
-
{
|
|
38
|
-
"model_input": {...},
|
|
39
|
-
"model_output": {...},
|
|
40
|
-
"temperature": 0.7,
|
|
41
|
-
"top_p": 1.0,
|
|
42
|
-
"model": "gpt-3.5-turbo",
|
|
43
|
-
...
|
|
44
|
-
}
|
|
45
|
-
:return: Dictionary with e.g. {"event_id": "..."} from the API.
|
|
46
|
-
"""
|
|
47
|
-
url = f"{self.base_url}/{monitor_id}/event"
|
|
48
|
-
response = requests.post(url, json=event_data, headers=self.headers)
|
|
49
|
-
response.raise_for_status()
|
|
50
|
-
return response.json()
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: deeprails
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Python client library for deeprails.ai
|
|
5
|
-
Home-page: https://github.com/yourusername/deeprails
|
|
6
|
-
Author: Your Name or Organization
|
|
7
|
-
Author-email: your.email@example.com
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.7
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: requests (>=2.0.0)
|
|
17
|
-
|
|
18
|
-
# DeepRails
|
|
19
|
-
|
|
20
|
-
A Python client library for interacting with the [DeepRails.ai](https://deeprails.ai) API. This package exposes high-level methods for creating and fetching evaluations, as well as creating monitors and logging monitor events.
|
|
21
|
-
|
|
22
|
-
## Features
|
|
23
|
-
|
|
24
|
-
- **Evaluation**:
|
|
25
|
-
- `client.evaluate.create(data)` – Create an evaluation
|
|
26
|
-
- `client.evaluate.fetch(eval_id)` – Retrieve the status and results of an evaluation
|
|
27
|
-
|
|
28
|
-
- **Monitor**:
|
|
29
|
-
- `client.monitor.create(data)` – Create a monitor
|
|
30
|
-
- `client.monitor.log(monitor_id, data)` – Log an event under a monitor
|
|
31
|
-
|
|
32
|
-
## Installation
|
|
33
|
-
|
|
34
|
-
Install via [PyPI](https://pypi.org/) using:
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
pip install deeprails
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Quick Start
|
|
41
|
-
```python
|
|
42
|
-
from deeprails import DeepRails
|
|
43
|
-
|
|
44
|
-
# Initialize the client (replace "YOUR_TOKEN" with a valid token)
|
|
45
|
-
client = DeepRails(token="YOUR_TOKEN")
|
|
46
|
-
|
|
47
|
-
# 1) Create an evaluation
|
|
48
|
-
eval_request_data = {
|
|
49
|
-
"model_input": {"user_prompt": "Write a poem about winter"},
|
|
50
|
-
"model_output": "A frosty greeting on a snowy morn...",
|
|
51
|
-
"type": "text",
|
|
52
|
-
"guardrails_metrics": ["correctness", "completeness"],
|
|
53
|
-
"score_format": "continuous",
|
|
54
|
-
"webhook": None
|
|
55
|
-
}
|
|
56
|
-
eval_response = client.evaluate.create(eval_request_data)
|
|
57
|
-
print("Evaluation created:", eval_response)
|
|
58
|
-
|
|
59
|
-
# 2) Fetch the evaluation by ID
|
|
60
|
-
evaluation = client.evaluate.fetch(eval_response["eval_id"])
|
|
61
|
-
print("Fetched evaluation:", evaluation)
|
|
62
|
-
|
|
63
|
-
# 3) Create a new monitor
|
|
64
|
-
monitor_data = {
|
|
65
|
-
"name": "My Example Monitor",
|
|
66
|
-
"description": "Track LLM usage in production",
|
|
67
|
-
"metrics": ["correctness", "completeness"]
|
|
68
|
-
}
|
|
69
|
-
monitor_resp = client.monitor.create(monitor_data)
|
|
70
|
-
monitor_id = monitor_resp["monitor_id"]
|
|
71
|
-
print("Monitor created:", monitor_resp)
|
|
72
|
-
|
|
73
|
-
# 4) Log an event under that monitor
|
|
74
|
-
event_data = {
|
|
75
|
-
"model_input": {"user_prompt": "Tell me a joke"},
|
|
76
|
-
"model_output": {"response": "Why did the chicken cross the road..."},
|
|
77
|
-
"temperature": 0.7,
|
|
78
|
-
"top_p": 1.0,
|
|
79
|
-
"model": "gpt-3.5-turbo"
|
|
80
|
-
}
|
|
81
|
-
event_resp = client.monitor.log(monitor_id, event_data)
|
|
82
|
-
print("Monitor event logged:", event_resp)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
deeprails-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
deeprails/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
deeprails/client.py,sha256=28vSTSp2tWzFLJq4racWW4lXMXOyF3W9hEvROhZd5VU,983
|
|
3
|
-
deeprails/evaluate.py,sha256=HJ3QtGiCho169r8dx1LXV6U7xjbreTr1X2BjDEfFwuw,1647
|
|
4
|
-
deeprails/monitor.py,sha256=XYtl5TdNqRHtrUetSYHxAOJNisFE_uLmbFSa__q08kA,1743
|
|
5
|
-
deeprails-0.1.0.dist-info/LICENSE,sha256=GsV7lN6fihCcDgkJbfs0rq1q9d6IyB0TFQ8HLKUpSXM,1077
|
|
6
|
-
deeprails-0.1.0.dist-info/METADATA,sha256=kmaiXXtnBuZQhT_tV0vKJH1P3Z3RVU3Npk-dRkg4cj8,2578
|
|
7
|
-
deeprails-0.1.0.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
|
8
|
-
deeprails-0.1.0.dist-info/top_level.txt,sha256=8-3gictPOXqg2k5S_yW66DdO8EqZ-YFab0LNarWUv4Q,10
|
|
9
|
-
deeprails-0.1.0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
deeprails
|
|
File without changes
|