|
4 | 4 | from flask import Flask, request, jsonify |
5 | 5 |
|
6 | 6 | from llm_router_services.guardrails.constants import SERVICES_API_PREFIX |
7 | | -from llm_router_services.guardrails.inference.factory import GuardrailModelFactory |
| 7 | +from llm_router_services.guardrails.inference.factory import ( |
| 8 | + GuardrailClassifierModelFactory, |
| 9 | +) |
8 | 10 |
|
9 | | -# Import the NASK‑specific configuration |
10 | 11 | from llm_router_services.guardrails.nask.config import NaskModelConfig |
11 | 12 |
|
12 | | -# ----------------------------------------------------------------------- |
13 | | -# Environment prefix – all configuration keys start with this value |
14 | | -# ----------------------------------------------------------------------- |
15 | 13 | _ENV_PREFIX = "LLM_ROUTER_NASK_PIB_GUARD_" |
16 | 14 |
|
17 | 15 | app = Flask(__name__) |
18 | 16 |
|
19 | | -MODEL_PATH = os.getenv( |
20 | | - f"{_ENV_PREFIX}MODEL_PATH", |
21 | | - "/mnt/data2/llms/models/community/NASK-PIB/HerBERT-PL-Guard", |
22 | | -) |
| 17 | +MODEL_PATH = os.getenv(f"{_ENV_PREFIX}MODEL_PATH", None) |
| 18 | +if not MODEL_PATH: |
| 19 | + raise Exception( |
| 20 | + f"NASK-PIB guardrail model path is not set! " |
| 21 | + f"Export {_ENV_PREFIX}MODEL_PATH with proper model path" |
| 22 | + ) |
23 | 23 |
|
24 | | -# Keep only a single constant for the device (CPU by default) |
25 | 24 | DEFAULT_DEVICE = int(os.getenv(f"{_ENV_PREFIX}DEVICE", "-1")) |
26 | 25 |
|
27 | | -# ----------------------------------------------------------------------- |
28 | | -# Build the guardrail object via the factory, passing the NASK‑specific config |
29 | | -# ----------------------------------------------------------------------- |
30 | | -guardrail = GuardrailModelFactory( |
| 26 | +guardrail = GuardrailClassifierModelFactory( |
31 | 27 | model_type="text_classification", |
32 | 28 | model_path=MODEL_PATH, |
33 | 29 | device=DEFAULT_DEVICE, |
34 | | - config=NaskModelConfig(), # <-- NASK‑specific thresholds & batch size |
| 30 | + config=NaskModelConfig(), |
35 | 31 | ) |
36 | 32 |
|
37 | 33 |
|
|
0 commit comments