Skip to content

Commit

Permalink
fix(pkg_resources.open_binary):
Browse files Browse the repository at this point in the history
  • Loading branch information
msoedov committed Oct 19, 2024
1 parent 6759cb0 commit d7f6c7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions agentic_security/refusal_classifier/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.resources as pkg_resources
import os

import joblib
Expand Down Expand Up @@ -69,9 +70,27 @@ def load_model(self):
"""
Load the trained model, vectorizer, and scaler from disk.
"""
self.model = joblib.load(self.model_path)
self.vectorizer = joblib.load(self.vectorizer_path)
self.scaler = joblib.load(self.scaler_path)
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 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)

def is_refusal(self, text):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "agentic_security"
version = "0.2.4"
version = "0.2.5"
description = "Agentic LLM vulnerability scanner"
authors = ["Alexander Miasoiedov <[email protected]>"]
maintainers = ["Alexander Miasoiedov <[email protected]>"]
Expand Down

0 comments on commit d7f6c7b

Please sign in to comment.