Skip to content

Commit ab4af78

Browse files
committed
v1.0.0: bundle trained model, fix model path resolution
- Ship tfidf_injection_clf.pkl inside the package (200KB) - Update SemanticScanner to find bundled model in installed package - Add package-data config for pkl and py.typed - Bump to 1.0.0 stable
1 parent 662630f commit ab4af78

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "safehere"
7-
version = "1.0.0b1"
7+
version = "1.0.0"
88
description = "Runtime tool-output scanning for Cohere agents. Detects and blocks prompt injection attacks in tool results."
99
readme = "README.md"
1010
requires-python = ">=3.9"
@@ -55,5 +55,8 @@ Issues = "https://github.com/Expl0dingCat/safehere/issues"
5555
[tool.setuptools.packages.find]
5656
where = ["src"]
5757

58+
[tool.setuptools.package-data]
59+
safehere = ["tfidf_injection_clf.pkl", "py.typed"]
60+
5861
[tool.pytest.ini_options]
5962
testpaths = ["tests"]

src/safehere/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""safehere - runtime tool-output scanning for Cohere agents."""
22

3-
__version__ = "1.0.0b1"
3+
__version__ = "1.0.0"
44
__author__ = "SafeHere Contributors"
55

66
from .guard import ToolGuard

src/safehere/scanners/semantic.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,26 @@
2626

2727
def _default_model_path():
2828
# type: () -> str
29-
return os.path.join(
29+
"""Find the model file. Checks two locations:
30+
1. Inside the installed package (src/safehere/tfidf_injection_clf.pkl)
31+
2. In the dev models/ directory (for local development)
32+
"""
33+
# shipped with the package
34+
pkg_path = os.path.join(
35+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
36+
"tfidf_injection_clf.pkl",
37+
)
38+
if os.path.isfile(pkg_path):
39+
return pkg_path
40+
# local dev fallback
41+
dev_path = os.path.join(
3042
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(
3143
os.path.abspath(__file__)
3244
)))),
3345
"models",
3446
"tfidf_injection_clf.pkl",
3547
)
48+
return dev_path
3649

3750

3851
class SemanticScanner(BaseScanner):
200 KB
Binary file not shown.

0 commit comments

Comments
 (0)