Skip to content

Commit ea9356b

Browse files
authored
Merge pull request trustyai-explainability#28 from m-misiura/pre-commit-fixes
Apply code quality fixes from pre-commit
2 parents 6c09a35 + 9efba12 commit ea9356b

File tree

11 files changed

+478
-431
lines changed

11 files changed

+478
-431
lines changed

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `trustyai_fms`: out-of-tree remote safety provider for llama stack
22

3-
This repo implements [FMS Guardrails Orchestrator](https://github.com/foundation-model-stack/fms-guardrails-orchestrator) together with community detectors:
3+
This repo implements [FMS Guardrails Orchestrator](https://github.com/foundation-model-stack/fms-guardrails-orchestrator) together with community detectors:
44

55
- [regex detectors](https://github.com/trustyai-explainability/guardrails-regex-detector)
66
- [Hugging Face content detectors](https://github.com/trustyai-explainability/guardrails-detectors)
@@ -42,27 +42,27 @@ as an out-of-tree remote safety provider for [llama stack](https://github.com/me
4242

4343
## Running demos
4444

45-
To run the demos in full, there is a need to deploy the orchestrator and detectors on Openshift, unless you have access to the necessary routes of the deployed services. If you do not have access to these routes, follow
46-
[Part A below](#part-a-openshift-setup-for-the-orchestrator-and-detectors) to set them up.
45+
To run the demos in full, there is a need to deploy the orchestrator and detectors on Openshift, unless you have access to the necessary routes of the deployed services. If you do not have access to these routes, follow
46+
[Part A below](#part-a-openshift-setup-for-the-orchestrator-and-detectors) to set them up.
4747

4848
Subsequently, to create a local llama stack distribution, follow [Part B below](#part-b-setup-to-create-a-local-llama-stack-distribution-with-external-trustyai_fms-remote-safety-provider)
4949

5050
### Part A. Openshift setup for the orchestrator and detectors
5151

52-
The demos require deploying the orchestrator and detectors on Openshift.
52+
The demos require deploying the orchestrator and detectors on Openshift.
5353

54-
The following operators are required in the Openshift cluster:
54+
The following operators are required in the Openshift cluster:
5555

5656
__GPU__ -- follow [this guide](https://docs.nvidia.com/datacenter/cloud-native/openshift/latest/steps-overview.html) and install:
5757
- Node Feature Discovery Operator (4.17.0-202505061137 provided by Red Hat):
5858
- ensure to create an instance of NodeFeatureDiscovery using the NodeFeatureDiscovery tab
5959
- NVIDIA GPU Operator (25.3.0 provided by NVIDIA Corporation)
6060
- ensure to create an instance of ClusterPolicy using the ClusterPolicy tab
6161

62-
__Model Serving__:
62+
__Model Serving__:
6363
- Red Hat OpenShift Service Mesh 2 (2.6.7-0 provided by Red Hat, Inc.)
6464
- Red Hat OpenShift Serverless (1.35.1 provided by Red Hat)
65-
__Authentication__:
65+
__Authentication__:
6666
- Red Hat - Authorino Operator (1.2.1 provided by Red Hat)
6767

6868
__AI Platform__:
@@ -80,14 +80,14 @@ __AI Platform__:
8080
name: knative-serving
8181
```
8282
83-
Once the above steps are completed,
83+
Once the above steps are completed,
8484
8585
1. Create a new project
8686
```bash
8787
oc new-project test
8888
```
8989

90-
2. Apply the manifests in the `openshift-manifests/` directory to deploy the orchestrator and detectors.
90+
2. Apply the manifests in the `openshift-manifests/` directory to deploy the orchestrator and detectors.
9191

9292
```bash
9393
oc apply -k openshift-manifests/
@@ -118,15 +118,15 @@ source .venv/bin/activate
118118
pip install -e .
119119
```
120120

121-
6. Pick a runtime configuration file from `runtime_configurations/` and run the stack:
121+
6. Pick a runtime configuration file from `runtime_configurations/` and run the stack:
122122

123123
a. __for the orchestrator API__:
124124

125125
```bash
126126
llama stack run runtime_configurations/orchestrator_api.yaml --image-type=venv
127127
```
128128

129-
Note that you might need to export the following environment variables:
129+
Note that you might need to export the following environment variables:
130130

131131
```bash
132132
export FMS_ORCHESTRATOR_URL="https://$(oc get routes guardrails-orchestrator-http -o jsonpath='{.spec.host}')"
@@ -138,7 +138,7 @@ pip install -e .
138138
llama stack run runtime_configurations/detector_api.yaml --image-type=venv
139139
```
140140

141-
Not that you might need to export the following environment variables:
141+
Not that you might need to export the following environment variables:
142142

143143
```bash
144144
export FMS_CHAT_URL="http://$(oc get routes granite-2b-detector-route -o jsonpath='{.spec.host}')"
@@ -155,4 +155,3 @@ pip install -e .
155155
```bash
156156
jupyter notebook noteboooks/trustyai-fms-detector-api.ipynb
157157
```
158-

llama_stack_provider_trustyai_fms/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import logging
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any
3+
4+
# Import Safety API
5+
from llama_stack.apis.safety import Safety
6+
from llama_stack.providers.datatypes import Api
37

48
# First import the provider spec to ensure registration
59
from .provider import get_provider_spec
610

711
# Set up logging
812
logger = logging.getLogger(__name__)
913

10-
# Import Safety API
11-
from llama_stack.apis.safety import Safety
12-
from llama_stack.providers.datatypes import Api
13-
1414
# Defer class imports by using a try-except block
1515
try:
1616
from .config import (
@@ -30,10 +30,8 @@
3030
)
3131

3232
# Type aliases for better readability
33-
ConfigType = Union[
34-
ContentDetectorConfig, ChatDetectorConfig, FMSSafetyProviderConfig
35-
]
36-
DetectorType = Union[BaseDetector, DetectorProvider]
33+
ConfigType = ContentDetectorConfig | ChatDetectorConfig | FMSSafetyProviderConfig
34+
DetectorType = BaseDetector | DetectorProvider
3735
except ImportError:
3836
# These will be imported later when actually needed
3937
pass
@@ -45,7 +43,7 @@ class DetectorConfigError(ValueError):
4543
pass
4644

4745

48-
async def create_fms_provider(config: Dict[str, Any]) -> Safety:
46+
async def create_fms_provider(config: dict[str, Any]) -> Safety:
4947
"""Create FMS safety provider instance.
5048
5149
Args:
@@ -63,11 +61,11 @@ async def create_fms_provider(config: Dict[str, Any]) -> Safety:
6361

6462
async def get_adapter_impl(
6563
config: FMSSafetyProviderConfig,
66-
deps: Dict[Api, Any],
64+
deps: dict[Api, Any],
6765
) -> DetectorProvider:
6866
"""Get appropriate detector implementation(s) based on config type."""
6967
try:
70-
detectors: Dict[str, Any] = {}
68+
detectors: dict[str, Any] = {}
7169

7270
# Process shields configuration
7371
for shield_id, shield_config in config.shields.items():
@@ -83,7 +81,7 @@ async def get_adapter_impl(
8381
await impl.initialize()
8482
detectors[shield_id] = impl
8583

86-
detectors_for_provider: Dict[str, BaseDetector] = {}
84+
detectors_for_provider: dict[str, BaseDetector] = {}
8785
for shield_id, detector in detectors.items():
8886
if isinstance(detector, BaseDetector):
8987
detectors_for_provider[shield_id] = detector
@@ -116,4 +114,6 @@ async def get_adapter_impl(
116114
"ConfigType",
117115
"DetectorType",
118116
"DetectorConfigError",
117+
# Side-effect import
118+
"get_provider_spec",
119119
]

0 commit comments

Comments
 (0)