fix(warnings):

This commit is contained in:
Alexander Myasoedov
2025-11-30 18:30:55 +02:00
parent 8ddfec303f
commit b3ae0026fb
3 changed files with 43 additions and 19 deletions
+1
View File
@@ -19,3 +19,4 @@ docx/
agentic_security.toml
/venv
*.csv
agentic_security/agents/operator_agno.py
+26 -18
View File
@@ -1,9 +1,11 @@
import importlib.resources as pkg_resources
import os
import warnings
import joblib
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.exceptions import InconsistentVersionWarning
from sklearn.preprocessing import StandardScaler
from sklearn.svm import OneClassSVM
@@ -70,27 +72,33 @@ class RefusalClassifier:
"""
Load the trained model, vectorizer, and scaler from disk.
"""
try:
self.model = joblib.load(self.model_path)
self.vectorizer = joblib.load(self.vectorizer_path)
self.scaler = joblib.load(self.scaler_path)
except FileNotFoundError:
# Load from package resources
package = (
__package__ # This should be 'agentic_security.refusal_classifier'
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
try:
self.model = joblib.load(self.model_path)
self.vectorizer = joblib.load(self.vectorizer_path)
self.scaler = joblib.load(self.scaler_path)
except FileNotFoundError:
# Load from package resources
package = (
__package__ # This should be 'agentic_security.refusal_classifier'
)
# Load model
with pkg_resources.open_binary(package, "oneclass_svm_model.joblib") as f:
self.model = joblib.load(f)
# Load model
with pkg_resources.open_binary(
package, "oneclass_svm_model.joblib"
) as f:
self.model = joblib.load(f)
# Load vectorizer
with pkg_resources.open_binary(package, "tfidf_vectorizer.joblib") as f:
self.vectorizer = joblib.load(f)
# Load vectorizer
with pkg_resources.open_binary(
package, "tfidf_vectorizer.joblib"
) as f:
self.vectorizer = joblib.load(f)
# Load scaler
with pkg_resources.open_binary(package, "scaler.joblib") as f:
self.scaler = joblib.load(f)
# Load scaler
with pkg_resources.open_binary(package, "scaler.joblib") as f:
self.scaler = joblib.load(f)
def is_refusal(self, text):
"""
+16 -1
View File
@@ -1,10 +1,25 @@
import os
import warnings
import pytest
from cache_to_disk import delete_old_disk_caches
from sklearn.exceptions import InconsistentVersionWarning
from agentic_security.logutils import logger
# Silence noisy third-party warnings that do not impact test behavior
warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
try:
from langchain_core._api import LangChainDeprecationWarning
warnings.filterwarnings("ignore", category=LangChainDeprecationWarning)
except Exception: # pragma: no cover - fallback for older langchain versions
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
module=r"langchain\\.agents",
message=r".*langchain_core.pydantic_v1.*",
)
def pytest_runtest_setup(item):
if "slow" in item.keywords and not os.getenv("RUN_SLOW_TESTS"):