orbitals 0.0.2__py3-none-any.whl → 0.0.3__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.
- orbitals/utils.py +35 -29
- orbitals-0.0.3.dist-info/METADATA +161 -0
- {orbitals-0.0.2.dist-info → orbitals-0.0.3.dist-info}/RECORD +6 -6
- orbitals-0.0.2.dist-info/METADATA +0 -124
- {orbitals-0.0.2.dist-info → orbitals-0.0.3.dist-info}/WHEEL +0 -0
- {orbitals-0.0.2.dist-info → orbitals-0.0.3.dist-info}/entry_points.txt +0 -0
- {orbitals-0.0.2.dist-info → orbitals-0.0.3.dist-info}/licenses/LICENSE +0 -0
orbitals/utils.py
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
import torch
|
|
7
|
-
else:
|
|
8
|
-
try:
|
|
9
|
-
import torch # ty: ignore[unresolved-import]
|
|
10
|
-
except ModuleNotFoundError:
|
|
11
|
-
torch = None # ty: ignore[invalid-assignment]
|
|
12
3
|
|
|
13
4
|
|
|
14
5
|
def maybe_configure_gpu_usage():
|
|
@@ -16,32 +7,47 @@ def maybe_configure_gpu_usage():
|
|
|
16
7
|
If the user hasn't explicitly set CUDA_VISIBLE_DEVICES, auto-configure it for
|
|
17
8
|
optimal usage: search for the gpu with the most free memory, and
|
|
18
9
|
set CUDA_VISIBLE_DEVICES to that GPU only.
|
|
19
|
-
"""
|
|
20
|
-
if torch is None:
|
|
21
|
-
return
|
|
22
10
|
|
|
11
|
+
Uses pynvml to avoid triggering CUDA initialization from torch.
|
|
12
|
+
"""
|
|
23
13
|
if "CUDA_VISIBLE_DEVICES" in os.environ:
|
|
24
14
|
logging.info(
|
|
25
15
|
"CUDA_VISIBLE_DEVICES is already set, not auto-configuring GPU usage"
|
|
26
16
|
)
|
|
27
17
|
return
|
|
28
18
|
|
|
29
|
-
|
|
19
|
+
try:
|
|
20
|
+
import pynvml # ty: ignore[unresolved-import]
|
|
21
|
+
except ModuleNotFoundError:
|
|
22
|
+
logging.debug("pynvml not available, skipping GPU auto-configuration")
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
pynvml.nvmlInit()
|
|
27
|
+
except pynvml.NVMLError:
|
|
28
|
+
logging.debug("NVML initialization failed, skipping GPU auto-configuration")
|
|
30
29
|
return
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
try:
|
|
32
|
+
device_count = pynvml.nvmlDeviceGetCount()
|
|
33
|
+
if device_count == 0:
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
best_idx = None
|
|
37
|
+
best_free = -1
|
|
38
|
+
|
|
39
|
+
for i in range(device_count):
|
|
40
|
+
handle = pynvml.nvmlDeviceGetHandleByIndex(i)
|
|
41
|
+
mem_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
|
|
42
|
+
if mem_info.free > best_free:
|
|
43
|
+
best_idx = i
|
|
44
|
+
best_free = mem_info.free
|
|
45
|
+
|
|
46
|
+
if best_idx is not None:
|
|
47
|
+
if device_count > 1:
|
|
48
|
+
logging.warning(
|
|
49
|
+
f"Auto-configuring to use GPU {best_idx} with {best_free / 1024**3:.2f} GB free"
|
|
50
|
+
)
|
|
51
|
+
os.environ["CUDA_VISIBLE_DEVICES"] = str(best_idx)
|
|
52
|
+
finally:
|
|
53
|
+
pynvml.nvmlShutdown()
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: orbitals
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: LLM Guardrails tailored to your Principles
|
|
5
|
+
Author-email: Luigi Procopio <luigi@principled-intelligence.com>, Edoardo Barba <edoardo@principled-intelligence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
Requires-Dist: pydantic>=2.0.0
|
|
17
|
+
Requires-Dist: requests
|
|
18
|
+
Requires-Dist: typer>=0.12.3
|
|
19
|
+
Provides-Extra: all
|
|
20
|
+
Requires-Dist: accelerate>=1.11.0; extra == 'all'
|
|
21
|
+
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'all'
|
|
22
|
+
Requires-Dist: pynvml; extra == 'all'
|
|
23
|
+
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'all'
|
|
24
|
+
Requires-Dist: uvicorn>=0.29.0; extra == 'all'
|
|
25
|
+
Requires-Dist: vllm>=0.11.0; extra == 'all'
|
|
26
|
+
Requires-Dist: xgrammar; extra == 'all'
|
|
27
|
+
Provides-Extra: scope-guard-all
|
|
28
|
+
Requires-Dist: accelerate>=1.11.0; extra == 'scope-guard-all'
|
|
29
|
+
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'scope-guard-all'
|
|
30
|
+
Requires-Dist: pynvml; extra == 'scope-guard-all'
|
|
31
|
+
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-all'
|
|
32
|
+
Requires-Dist: uvicorn>=0.29.0; extra == 'scope-guard-all'
|
|
33
|
+
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-all'
|
|
34
|
+
Requires-Dist: xgrammar; extra == 'scope-guard-all'
|
|
35
|
+
Provides-Extra: scope-guard-hf
|
|
36
|
+
Requires-Dist: accelerate>=1.11.0; extra == 'scope-guard-hf'
|
|
37
|
+
Requires-Dist: pynvml; extra == 'scope-guard-hf'
|
|
38
|
+
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-hf'
|
|
39
|
+
Provides-Extra: scope-guard-serve
|
|
40
|
+
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'scope-guard-serve'
|
|
41
|
+
Requires-Dist: pynvml; extra == 'scope-guard-serve'
|
|
42
|
+
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-serve'
|
|
43
|
+
Requires-Dist: uvicorn>=0.29.0; extra == 'scope-guard-serve'
|
|
44
|
+
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-serve'
|
|
45
|
+
Requires-Dist: xgrammar; extra == 'scope-guard-serve'
|
|
46
|
+
Provides-Extra: scope-guard-vllm
|
|
47
|
+
Requires-Dist: pynvml; extra == 'scope-guard-vllm'
|
|
48
|
+
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-vllm'
|
|
49
|
+
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-vllm'
|
|
50
|
+
Requires-Dist: xgrammar; extra == 'scope-guard-vllm'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
<div align="center">
|
|
54
|
+
<img src="assets/orbitals-banner.png" width="70%" />
|
|
55
|
+
<h3 align="center">
|
|
56
|
+
<p>
|
|
57
|
+
<b>LLM Guardrails tailored to your Principles</b>
|
|
58
|
+
</p>
|
|
59
|
+
</h4>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<p align="center">
|
|
63
|
+
<img src="https://img.shields.io/pypi/v/orbitals?color=green" alt="PyPI Version">
|
|
64
|
+
<!-- <img src="https://img.shields.io/badge/type%20checked-ty-blue.svg?color=green" alt="Type Checked with ty"> -->
|
|
65
|
+
<img src="https://img.shields.io/pypi/pyversions/orbitals" alt="Python Versions">
|
|
66
|
+
<img src="https://img.shields.io/github/license/principled-intelligence/orbitals" alt="GitHub License">
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
## Overview
|
|
70
|
+
|
|
71
|
+
**Orbitals** is a lightweight Python library for adding LLM guardrails in just a few lines of code. With Orbitals, you can add a governance layer tailored to **user-specific principles**. Rather than enforcing generic notions of safety, compliance, and correctness, Orbitals validates inputs (e.g., user requests) and outputs (e.g., assistant responses) against user-defined specifications and custom policies. This makes guardrails explicit, auditable, and aligned with the user's philosophy.
|
|
72
|
+
|
|
73
|
+
### Key Features
|
|
74
|
+
|
|
75
|
+
- **User-defined specifications** — Guardrails that match your use case and your custom policies, not generic safety rules
|
|
76
|
+
- **Simple integration** — Add guardrails with minimal code changes
|
|
77
|
+
- **Open framework, open models** — Orbitals is open-source and is a simple interface for our open models
|
|
78
|
+
|
|
79
|
+
## Getting started
|
|
80
|
+
|
|
81
|
+
### Installation
|
|
82
|
+
|
|
83
|
+
You can install Orbitals via pip:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install orbitals[all]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Basic Usage
|
|
90
|
+
|
|
91
|
+
Here's a quick example to get you started with Orbitals, in which we use the ScopeGuard module to guard an AI service (for example, a customer support chatbot) from user requests that violate specified principles or fall outside of the scope of the core task of the assistant.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from orbitals.scope_guard import ScopeGuard
|
|
95
|
+
|
|
96
|
+
ai_service_description = "You are a helpful assistant for ..."
|
|
97
|
+
user_message = "Can I buy ..."
|
|
98
|
+
|
|
99
|
+
guardrail = ScopeGuard()
|
|
100
|
+
result = guardrail.validate(user_message, ai_service_description)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The result of a guardrail validation will indicate whether the input or output passed the guardrail checks, along with details on any violations. You can then handle violations as needed, such as by rejecting the input or modifying the output. For example:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
if result.scope_class.value == "Restricted" or result.scope_class.value == "Out of Scope":
|
|
107
|
+
print("Request violates guardrail:", result.evidences)
|
|
108
|
+
else:
|
|
109
|
+
# The user request is safe!
|
|
110
|
+
# We can now pass it to the AI assistant for processing.
|
|
111
|
+
...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Available Guardrails
|
|
115
|
+
|
|
116
|
+
Orbitals currently provides the following guardrail modules:
|
|
117
|
+
|
|
118
|
+
| Guardrail | Description | Hosting Options |
|
|
119
|
+
|:----------|:------------|:----------------|
|
|
120
|
+
| **[ScopeGuard](README.scope-guard.md)** | Classifies user queries against AI assistant specifications to detect out-of-scope requests, policy violations, and chit-chat | Self-hosted / Cloud hosting |
|
|
121
|
+
| 🚀 *Coming Soon* | More guardrails are on the way — stay tuned for updates! | — |
|
|
122
|
+
|
|
123
|
+
#### Hosting Options
|
|
124
|
+
|
|
125
|
+
- **Self-hosted**: Use open-weight models that you can deploy on your own infrastructure, ensuring data privacy and control.
|
|
126
|
+
- **Cloud hosting**: (Coming soon) Managed hosting options for ease of use and scalability
|
|
127
|
+
|
|
128
|
+
### Documentation
|
|
129
|
+
|
|
130
|
+
For detailed documentation, including installation instructions, usage guides, and API references, please visit the Orbitals Documentation.
|
|
131
|
+
|
|
132
|
+
- [ScopeGuard Documentation](README.scope-guard.md)
|
|
133
|
+
|
|
134
|
+
### FAQ
|
|
135
|
+
|
|
136
|
+
- **Can I use Orbitals for commercial applications?**
|
|
137
|
+
Yes, Orbitals is designed to be used in both research and commercial applications. It is licensed under the Apache 2.0 License, which allows for commercial use.
|
|
138
|
+
- **Other questions?**
|
|
139
|
+
Feel free to reach out to us at [orbitals@principled-intelligence.com](mailto:orbitals@principled-intelligence.com)!
|
|
140
|
+
|
|
141
|
+
### Contributing
|
|
142
|
+
|
|
143
|
+
We welcome contributions from the community! If you'd like to contribute to Orbitals, please check out our [Contributing Guide](CONTRIBUTING.md) for guidelines on how to get started.
|
|
144
|
+
|
|
145
|
+
### License
|
|
146
|
+
|
|
147
|
+
This project is licensed under the Apache 2.0 License. See the [LICENSE](LICENSE) file for details.
|
|
148
|
+
|
|
149
|
+
### Contact
|
|
150
|
+
|
|
151
|
+
For questions, feedback, or support, please reach out to us at [orbitals@principled-intelligence.com](mailto:orbitals@principled-intelligence.com).
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
<div align="center">
|
|
156
|
+
<p>
|
|
157
|
+
<b>Built with ❤️ by <a href="https://principled-intelligence.com">Principled Intelligence</a></b>
|
|
158
|
+
<br />
|
|
159
|
+
Follow us on <a href="https://www.linkedin.com/company/principled-ai/">LinkedIn</a> for the latest updates.
|
|
160
|
+
</p>
|
|
161
|
+
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
orbitals/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
|
|
2
2
|
orbitals/types.py,sha256=4oRinWPG6kbtW4lQ8bHrDmxEotncqMIwLCmQ2yGH7PI,1988
|
|
3
|
-
orbitals/utils.py,sha256=
|
|
3
|
+
orbitals/utils.py,sha256=9UFlpzTkSJeyN2n1CzUy5jIZFqnOwNYNpF4c5xIfT3E,1628
|
|
4
4
|
orbitals/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
orbitals/cli/main.py,sha256=p4MEbmtJ0L8mLiyovEq7urnVc6I0mbbCNdGEtGyY60Y,197
|
|
6
6
|
orbitals/scope_guard/__init__.py,sha256=0gzzSXpfRvIcCYpu3AKQSMFYDMDJaknY9pdypt7HiuI,197
|
|
@@ -18,8 +18,8 @@ orbitals/scope_guard/guards/vllm.py,sha256=3LU9DKKniQd90Ibaq2Wef20fyoZXgkeQtc58X
|
|
|
18
18
|
orbitals/scope_guard/serving/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
orbitals/scope_guard/serving/main.py,sha256=pjUol71h7CuU_6PiB7Zjdm5eNyDVH-F8bZVNeyEL-tE,3822
|
|
20
20
|
orbitals/scope_guard/serving/vllm_logging_config.json,sha256=Bc08X8mQWJFAAHEE6ZFVUGnRc77pMVpPvji6BhFTtSE,651
|
|
21
|
-
orbitals-0.0.
|
|
22
|
-
orbitals-0.0.
|
|
23
|
-
orbitals-0.0.
|
|
24
|
-
orbitals-0.0.
|
|
25
|
-
orbitals-0.0.
|
|
21
|
+
orbitals-0.0.3.dist-info/METADATA,sha256=pgtkFPmdlhU9pnorq_cfSnf0Egc36vMEbY1elxaohfU,7148
|
|
22
|
+
orbitals-0.0.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
23
|
+
orbitals-0.0.3.dist-info/entry_points.txt,sha256=fd6lukgEvK9UBwhA1JtcB9MLTqAtntA4H2cc7-nWkeU,51
|
|
24
|
+
orbitals-0.0.3.dist-info/licenses/LICENSE,sha256=Eeclrom-K-omYcKnMvijEMV-IMiQ7X-bdgxlZcXcImI,11360
|
|
25
|
+
orbitals-0.0.3.dist-info/RECORD,,
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: orbitals
|
|
3
|
-
Version: 0.0.2
|
|
4
|
-
Summary: LLM Guardrails tailored to your Principles
|
|
5
|
-
Author-email: Luigi Procopio <luigi@principled-intelligence.com>, Edoardo Barba <edoardo@principled-intelligence.com>
|
|
6
|
-
License: Apache-2.0
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
-
Requires-Python: >=3.10
|
|
15
|
-
Requires-Dist: aiohttp
|
|
16
|
-
Requires-Dist: pydantic>=2.0.0
|
|
17
|
-
Requires-Dist: requests
|
|
18
|
-
Requires-Dist: typer>=0.12.3
|
|
19
|
-
Provides-Extra: all
|
|
20
|
-
Requires-Dist: accelerate>=1.11.0; extra == 'all'
|
|
21
|
-
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'all'
|
|
22
|
-
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'all'
|
|
23
|
-
Requires-Dist: uvicorn>=0.29.0; extra == 'all'
|
|
24
|
-
Requires-Dist: vllm>=0.11.0; extra == 'all'
|
|
25
|
-
Requires-Dist: xgrammar; extra == 'all'
|
|
26
|
-
Provides-Extra: scope-guard-all
|
|
27
|
-
Requires-Dist: accelerate>=1.11.0; extra == 'scope-guard-all'
|
|
28
|
-
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'scope-guard-all'
|
|
29
|
-
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-all'
|
|
30
|
-
Requires-Dist: uvicorn>=0.29.0; extra == 'scope-guard-all'
|
|
31
|
-
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-all'
|
|
32
|
-
Requires-Dist: xgrammar; extra == 'scope-guard-all'
|
|
33
|
-
Provides-Extra: scope-guard-hf
|
|
34
|
-
Requires-Dist: accelerate>=1.11.0; extra == 'scope-guard-hf'
|
|
35
|
-
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-hf'
|
|
36
|
-
Provides-Extra: scope-guard-serve
|
|
37
|
-
Requires-Dist: fastapi[standard]>=0.119.1; extra == 'scope-guard-serve'
|
|
38
|
-
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-serve'
|
|
39
|
-
Requires-Dist: uvicorn>=0.29.0; extra == 'scope-guard-serve'
|
|
40
|
-
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-serve'
|
|
41
|
-
Requires-Dist: xgrammar; extra == 'scope-guard-serve'
|
|
42
|
-
Provides-Extra: scope-guard-vllm
|
|
43
|
-
Requires-Dist: transformers<5.0.0,>=4.47.0; extra == 'scope-guard-vllm'
|
|
44
|
-
Requires-Dist: vllm>=0.11.0; extra == 'scope-guard-vllm'
|
|
45
|
-
Requires-Dist: xgrammar; extra == 'scope-guard-vllm'
|
|
46
|
-
Description-Content-Type: text/markdown
|
|
47
|
-
|
|
48
|
-
<div align="center">
|
|
49
|
-
<img src="assets/orbitals-banner.png" width="70%" />
|
|
50
|
-
<h3 align="center">
|
|
51
|
-
<p>
|
|
52
|
-
<b>LLM Guardrails tailored to your Principles</b>
|
|
53
|
-
</p>
|
|
54
|
-
</h4>
|
|
55
|
-
<hr/>
|
|
56
|
-
</div>
|
|
57
|
-
|
|
58
|
-
<p align="center">
|
|
59
|
-
<img src="https://img.shields.io/badge/type%20checked-ty-blue.svg?color=green" alt="Type Checked with ty">
|
|
60
|
-
<img src="https://img.shields.io/pypi/v/orbitals?color=green" alt="PyPI Version">
|
|
61
|
-
<img src="https://img.shields.io/github/license/principled-intelligence/orbitals" alt="GitHub License">
|
|
62
|
-
<img src="https://img.shields.io/pypi/pyversions/orbitals" alt="Python Versions">
|
|
63
|
-
<img src="https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fprincipled-intelligence%2Forbitals%2Fmain%2Fpyproject.toml" alt="Required Python Version">
|
|
64
|
-
</p>
|
|
65
|
-
|
|
66
|
-
`orbitals` is an ecosystem of LLM guardrails, designed to provide a governance layer tailored to **user-specific principles, requirements and use cases**. Rather than enforcing generic notions of safety, correctness, etc., Orbitals evaluates inputs and outputs against *user-defined specifications*. This makes guardrails explicit, auditable, and aligned with the user's philosophy.
|
|
67
|
-
|
|
68
|
-
Orbitals guardrails fall into two typologies:
|
|
69
|
-
- **Guards** operate on the *input* of a guardrailed LLM, assessing whether a user request is legitimate under the provided specifications.
|
|
70
|
-
- **Supervisors** operate on the *output* of a guardrailed LLM, evaluating the assistant’s response before it is returned.
|
|
71
|
-
|
|
72
|
-
Guardrails may be released under different modality flavors:
|
|
73
|
-
- **Open** (open-source and open-weight), allowing users to run guardrails and underlying models on their own infrastructure.
|
|
74
|
-
- **Hosted**, accessible via simple HTTP calls (API key required).
|
|
75
|
-
|
|
76
|
-
## Available Guardrails
|
|
77
|
-
|
|
78
|
-
| Name | Flavor | Description |
|
|
79
|
-
|-------------|-------------------------|-----------------------------------------------------------------------------|
|
|
80
|
-
| [ScopeGuard](README.scope-guard.md) | Open / Hosted | Validates whether a user request falls within the intended use of an AI service. |
|
|
81
|
-
| RagSupervisor | Coming soon | Ensures LLM responses remain grounded in retrieved context for RAG setups. |
|
|
82
|
-
|
|
83
|
-
<details>
|
|
84
|
-
<summary>ScopeGuard</summary>
|
|
85
|
-
<br>
|
|
86
|
-
|
|
87
|
-
First, we need to install `orbitals` and `scope-guard`:
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
pip install orbitals[scope-guard-vllm]
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Then:
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
from orbitals.scope_guard import ScopeGuard
|
|
97
|
-
|
|
98
|
-
scope_guard = ScopeGuard(
|
|
99
|
-
backend="vllm",
|
|
100
|
-
model="scope-guard-q", # for the Qwen-family model
|
|
101
|
-
# model="scope-guard-g", # for the Gemma-family model
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
ai_service_description = """
|
|
105
|
-
You are a virtual assistant for a parcel delivery service.
|
|
106
|
-
You can only answer questions about package tracking.
|
|
107
|
-
Never respond to requests for refunds.
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
user_query = "If the package hasn't arrived by tomorrow, can I get my money back?"
|
|
111
|
-
result = scope_guard.validate(user_query, ai_service_description)
|
|
112
|
-
|
|
113
|
-
print(f"Scope: {result.scope_class.value}")
|
|
114
|
-
if result.evidences:
|
|
115
|
-
print("Evidences:")
|
|
116
|
-
for evidence in result.evidences:
|
|
117
|
-
print(f" - {evidence}")
|
|
118
|
-
|
|
119
|
-
# Scope: Restricted
|
|
120
|
-
# Evidences:
|
|
121
|
-
# - Never respond to requests for refunds.
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
</details>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|