Skip to content

Commit 0043b28

Browse files
author
Paweł Kędzia
committed
Replace GuardrailModelFactory with GuardrailClassifierModelFactory and enforce explicit MODEL_PATH env var; rename factory alias accordingly
1 parent d01d755 commit 0043b28

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

llm_router_services/guardrails/inference/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ def create(
4848

4949

5050
# Public alias expected by the Flask app
51-
GuardrailModelFactory = create
51+
GuardrailClassifierModelFactory = create

llm_router_services/guardrails/nask/nask_pib_guard_app.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,30 @@
44
from flask import Flask, request, jsonify
55

66
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+
)
810

9-
# Import the NASK‑specific configuration
1011
from llm_router_services.guardrails.nask.config import NaskModelConfig
1112

12-
# -----------------------------------------------------------------------
13-
# Environment prefix – all configuration keys start with this value
14-
# -----------------------------------------------------------------------
1513
_ENV_PREFIX = "LLM_ROUTER_NASK_PIB_GUARD_"
1614

1715
app = Flask(__name__)
1816

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+
)
2323

24-
# Keep only a single constant for the device (CPU by default)
2524
DEFAULT_DEVICE = int(os.getenv(f"{_ENV_PREFIX}DEVICE", "-1"))
2625

27-
# -----------------------------------------------------------------------
28-
# Build the guardrail object via the factory, passing the NASK‑specific config
29-
# -----------------------------------------------------------------------
30-
guardrail = GuardrailModelFactory(
26+
guardrail = GuardrailClassifierModelFactory(
3127
model_type="text_classification",
3228
model_path=MODEL_PATH,
3329
device=DEFAULT_DEVICE,
34-
config=NaskModelConfig(), # <-- NASK‑specific thresholds & batch size
30+
config=NaskModelConfig(),
3531
)
3632

3733

run_nask_guardrail.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
: "${LLM_ROUTER_NASK_PIB_GUARD_MODEL_PATH:=NASK-PIB/HerBERT-PL-Guard}"
1717
: "${LLM_ROUTER_NASK_PIB_GUARD_DEVICE:=0}"
1818

19-
#: "${LLM_ROUTER_NASK_PIB_GUARD_MODEL_PATH:=/mnt/data2/llms/models/community/NASK-PIB/HerBERT-PL-Guard}"
20-
2119
# Export them so the Python process can read them
2220
export LLM_ROUTER_NASK_PIB_GUARD_FLASK_HOST
2321
export LLM_ROUTER_NASK_PIB_GUARD_FLASK_PORT

0 commit comments

Comments
 (0)