policythread 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- policythread-0.1.0/PKG-INFO +18 -0
- policythread-0.1.0/README.md +33 -0
- policythread-0.1.0/policythread.egg-info/PKG-INFO +18 -0
- policythread-0.1.0/policythread.egg-info/SOURCES.txt +8 -0
- policythread-0.1.0/policythread.egg-info/dependency_links.txt +1 -0
- policythread-0.1.0/policythread.egg-info/requires.txt +1 -0
- policythread-0.1.0/policythread.egg-info/top_level.txt +1 -0
- policythread-0.1.0/policythread.py +98 -0
- policythread-0.1.0/setup.cfg +4 -0
- policythread-0.1.0/setup.py +17 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: policythread
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Define what your AI must always do and never do. PolicyThread watches every live interaction and tells you when it breaks the rules.
|
|
5
|
+
Home-page: https://github.com/eugene001dayne/policy-thread
|
|
6
|
+
Author: Eugene Dayne Mawuli
|
|
7
|
+
Author-email: bitelance.team@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Requires-Dist: httpx
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: requires-dist
|
|
17
|
+
Dynamic: requires-python
|
|
18
|
+
Dynamic: summary
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# policythread
|
|
2
|
+
|
|
3
|
+
Define what your AI must always do and never do. PolicyThread watches every live interaction and tells you when it breaks the rules.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
pip install policythread
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
from policythread import PolicyThread
|
|
12
|
+
|
|
13
|
+
pt = PolicyThread()
|
|
14
|
+
|
|
15
|
+
policy = pt.create_policy(
|
|
16
|
+
name="No competitor mentions",
|
|
17
|
+
description="AI output must never reference competitors",
|
|
18
|
+
condition={"type": "keyword_exclude", "keywords": ["CompetitorA", "CompetitorB"]},
|
|
19
|
+
severity="high",
|
|
20
|
+
on_violation="alert"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
result = pt.evaluate(
|
|
24
|
+
user_input="Which product should I use?",
|
|
25
|
+
ai_output="You should try CompetitorA.",
|
|
26
|
+
model_used="gpt-4o",
|
|
27
|
+
session_id="session-123"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if not result["passed"]:
|
|
31
|
+
print("Violation:", result["violations"][0]["reason"])
|
|
32
|
+
|
|
33
|
+
stats = pt.stats()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: policythread
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Define what your AI must always do and never do. PolicyThread watches every live interaction and tells you when it breaks the rules.
|
|
5
|
+
Home-page: https://github.com/eugene001dayne/policy-thread
|
|
6
|
+
Author: Eugene Dayne Mawuli
|
|
7
|
+
Author-email: bitelance.team@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Requires-Dist: httpx
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: requires-dist
|
|
17
|
+
Dynamic: requires-python
|
|
18
|
+
Dynamic: summary
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
httpx
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
policythread
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
class PolicyThread:
|
|
4
|
+
def __init__(self, base_url="https://policy-thread.onrender.com"):
|
|
5
|
+
self.base_url = base_url.rstrip("/")
|
|
6
|
+
|
|
7
|
+
def _get(self, path, params=None):
|
|
8
|
+
with httpx.Client() as client:
|
|
9
|
+
r = client.get(f"{self.base_url}{path}", params=params)
|
|
10
|
+
r.raise_for_status()
|
|
11
|
+
return r.json()
|
|
12
|
+
|
|
13
|
+
def _post(self, path, data):
|
|
14
|
+
with httpx.Client() as client:
|
|
15
|
+
r = client.post(f"{self.base_url}{path}", json=data)
|
|
16
|
+
r.raise_for_status()
|
|
17
|
+
return r.json()
|
|
18
|
+
|
|
19
|
+
def _patch(self, path, data=None):
|
|
20
|
+
with httpx.Client() as client:
|
|
21
|
+
r = client.patch(f"{self.base_url}{path}", json=data or {})
|
|
22
|
+
r.raise_for_status()
|
|
23
|
+
return r.json()
|
|
24
|
+
|
|
25
|
+
def _delete(self, path):
|
|
26
|
+
with httpx.Client() as client:
|
|
27
|
+
r = client.delete(f"{self.base_url}{path}")
|
|
28
|
+
r.raise_for_status()
|
|
29
|
+
return r.json()
|
|
30
|
+
|
|
31
|
+
# Policies
|
|
32
|
+
def create_policy(self, name, description=None, condition=None, severity="high", on_violation="alert"):
|
|
33
|
+
return self._post("/policies", {
|
|
34
|
+
"name": name,
|
|
35
|
+
"description": description,
|
|
36
|
+
"condition": condition or {},
|
|
37
|
+
"severity": severity,
|
|
38
|
+
"on_violation": on_violation
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
def list_policies(self):
|
|
42
|
+
return self._get("/policies")
|
|
43
|
+
|
|
44
|
+
def get_policy(self, policy_id):
|
|
45
|
+
return self._get(f"/policies/{policy_id}")
|
|
46
|
+
|
|
47
|
+
def update_policy(self, policy_id, **kwargs):
|
|
48
|
+
return self._post(f"/policies/{policy_id}", kwargs)
|
|
49
|
+
|
|
50
|
+
def deactivate_policy(self, policy_id):
|
|
51
|
+
return self._delete(f"/policies/{policy_id}")
|
|
52
|
+
|
|
53
|
+
def get_policy_history(self, policy_id):
|
|
54
|
+
return self._get(f"/policies/{policy_id}/history")
|
|
55
|
+
|
|
56
|
+
# Evaluate
|
|
57
|
+
def evaluate(self, user_input, ai_output, session_id=None, model_used=None, metadata=None):
|
|
58
|
+
return self._post("/evaluate", {
|
|
59
|
+
"user_input": user_input,
|
|
60
|
+
"ai_output": ai_output,
|
|
61
|
+
"session_id": session_id,
|
|
62
|
+
"model_used": model_used,
|
|
63
|
+
"metadata": metadata or {}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
def evaluate_batch(self, interactions):
|
|
67
|
+
return self._post("/evaluate/batch", {"interactions": interactions})
|
|
68
|
+
|
|
69
|
+
# Violations
|
|
70
|
+
def list_violations(self, severity=None, policy_id=None, resolved=None):
|
|
71
|
+
params = {}
|
|
72
|
+
if severity:
|
|
73
|
+
params["severity"] = severity
|
|
74
|
+
if policy_id:
|
|
75
|
+
params["policy_id"] = policy_id
|
|
76
|
+
if resolved is not None:
|
|
77
|
+
params["resolved"] = resolved
|
|
78
|
+
return self._get("/violations", params=params)
|
|
79
|
+
|
|
80
|
+
def get_violation(self, violation_id):
|
|
81
|
+
return self._get(f"/violations/{violation_id}")
|
|
82
|
+
|
|
83
|
+
def resolve_violation(self, violation_id):
|
|
84
|
+
return self._patch(f"/violations/{violation_id}/resolve")
|
|
85
|
+
|
|
86
|
+
# Interactions
|
|
87
|
+
def list_interactions(self):
|
|
88
|
+
return self._get("/interactions")
|
|
89
|
+
|
|
90
|
+
def get_interaction(self, interaction_id):
|
|
91
|
+
return self._get(f"/interactions/{interaction_id}")
|
|
92
|
+
|
|
93
|
+
# Dashboard
|
|
94
|
+
def stats(self):
|
|
95
|
+
return self._get("/dashboard/stats")
|
|
96
|
+
|
|
97
|
+
def health(self):
|
|
98
|
+
return self._get("/health")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="policythread",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="Define what your AI must always do and never do. PolicyThread watches every live interaction and tells you when it breaks the rules.",
|
|
7
|
+
author="Eugene Dayne Mawuli",
|
|
8
|
+
author_email="bitelance.team@gmail.com",
|
|
9
|
+
url="https://github.com/eugene001dayne/policy-thread",
|
|
10
|
+
py_modules=["policythread"],
|
|
11
|
+
install_requires=["httpx"],
|
|
12
|
+
python_requires=">=3.8",
|
|
13
|
+
classifiers=[
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
],
|
|
17
|
+
)
|