auditai-client 1.0.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.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: auditai-client
3
+ Version: 1.0.0
4
+ Summary: AuditAI – AI Reliability & Compliance Auditor SDK
5
+ Author: AuditAI Team
6
+ Requires-Python: >=3.9
7
+ Requires-Dist: requests>=2.28.0
8
+ Dynamic: author
9
+ Dynamic: requires-dist
10
+ Dynamic: requires-python
11
+ Dynamic: summary
@@ -0,0 +1,44 @@
1
+ # AuditAI Python SDK
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ pip install -e .
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ from auditai import AuditAI
13
+
14
+ # Initialize with your API key (JWT token)
15
+ client = AuditAI(api_key="your-jwt-token", base_url="http://localhost:8000")
16
+
17
+ # Log an execution trace
18
+ result = client.log_execution(
19
+ project_name="my-rag-app",
20
+ prompt="What is the capital of France?",
21
+ response="The capital of France is Paris.",
22
+ retrieval_docs=["France is a country in Europe. Its capital is Paris."],
23
+ tools=[{"name": "search", "arguments": {"query": "capital of France"}}],
24
+ tool_outputs=[{"result": "Paris is the capital of France"}],
25
+ model="gpt-4",
26
+ total_tokens=150,
27
+ latency_ms=1200.0,
28
+ )
29
+
30
+ print(f"Execution ID: {result['id']}")
31
+
32
+ # Trigger evaluation
33
+ evaluation = client.evaluate(result['id'])
34
+ print(f"Overall Score: {evaluation['overall_score']}")
35
+
36
+ # Run adversarial tests
37
+ tests = client.run_adversarial(result['id'])
38
+ for test in tests:
39
+ print(f"{test['test_type']}: {test['result_score']}")
40
+
41
+ # Get dashboard stats
42
+ stats = client.get_dashboard()
43
+ print(f"Total Executions: {stats['total_executions']}")
44
+ ```
@@ -0,0 +1,6 @@
1
+ """AuditAI Python SDK"""
2
+
3
+ from auditai.client import AuditAI
4
+
5
+ __all__ = ["AuditAI"]
6
+ __version__ = "1.0.0"
@@ -0,0 +1,177 @@
1
+ """
2
+ AuditAI Python SDK Client
3
+
4
+ Usage:
5
+ from auditai import AuditAI
6
+
7
+ client = AuditAI(api_key="your-api-key", base_url="https://your-api.com")
8
+
9
+ client.log_execution(
10
+ project_name="my-rag-app",
11
+ prompt="What is the capital of France?",
12
+ response="The capital of France is Paris.",
13
+ retrieval_docs=["France is a country in Europe. Its capital is Paris."],
14
+ tools=[{"name": "search", "arguments": {"query": "capital of France"}}],
15
+ tool_outputs=[{"result": "Paris is the capital of France"}],
16
+ model="gpt-4",
17
+ total_tokens=150,
18
+ latency_ms=1200.0,
19
+ )
20
+ """
21
+
22
+ import json
23
+ from typing import Optional, List, Dict, Any
24
+
25
+ try:
26
+ import requests
27
+ except ImportError:
28
+ import urllib.request
29
+ import urllib.error
30
+ requests = None
31
+
32
+
33
+ class AuditAI:
34
+ """AuditAI SDK Client for logging execution traces."""
35
+
36
+ def __init__(self, api_key: str, base_url: str = "http://localhost:8000"):
37
+ self.api_key = api_key
38
+ self.base_url = base_url.rstrip("/")
39
+
40
+ def _headers(self) -> dict:
41
+ return {
42
+ "Authorization": f"Bearer {self.api_key}",
43
+ "Content-Type": "application/json",
44
+ }
45
+
46
+ def _post(self, endpoint: str, data: dict) -> dict:
47
+ url = f"{self.base_url}{endpoint}"
48
+ if requests:
49
+ resp = requests.post(url, json=data, headers=self._headers(), timeout=30)
50
+ resp.raise_for_status()
51
+ return resp.json()
52
+ else:
53
+ # Fallback to urllib
54
+ req = urllib.request.Request(
55
+ url,
56
+ data=json.dumps(data).encode("utf-8"),
57
+ headers=self._headers(),
58
+ method="POST",
59
+ )
60
+ try:
61
+ with urllib.request.urlopen(req, timeout=30) as resp:
62
+ return json.loads(resp.read().decode("utf-8"))
63
+ except urllib.error.HTTPError as e:
64
+ raise Exception(f"HTTP {e.code}: {e.read().decode('utf-8')}")
65
+
66
+ def _get(self, endpoint: str) -> dict:
67
+ url = f"{self.base_url}{endpoint}"
68
+ if requests:
69
+ resp = requests.get(url, headers=self._headers(), timeout=30)
70
+ resp.raise_for_status()
71
+ return resp.json()
72
+ else:
73
+ req = urllib.request.Request(url, headers=self._headers())
74
+ with urllib.request.urlopen(req, timeout=30) as resp:
75
+ return json.loads(resp.read().decode("utf-8"))
76
+
77
+ def log_execution(
78
+ self,
79
+ project_name: str,
80
+ prompt: str,
81
+ response: str,
82
+ system_prompt: Optional[str] = None,
83
+ retrieval_docs: Optional[List[str]] = None,
84
+ tools: Optional[List[Dict[str, Any]]] = None,
85
+ tool_outputs: Optional[List[Dict[str, Any]]] = None,
86
+ model: str = "unknown",
87
+ total_tokens: int = 0,
88
+ latency_ms: float = 0.0,
89
+ ) -> dict:
90
+ """Log an execution trace to AuditAI."""
91
+ payload = {
92
+ "project_name": project_name,
93
+ "prompt": prompt,
94
+ "response": response,
95
+ "system_prompt": system_prompt,
96
+ "retrieval_docs": retrieval_docs,
97
+ "tools": tools,
98
+ "tool_outputs": tool_outputs,
99
+ "model": model,
100
+ "total_tokens": total_tokens,
101
+ "latency_ms": latency_ms,
102
+ }
103
+ return self._post("/api/executions/ingest", payload)
104
+
105
+ def list_projects(self) -> list:
106
+ """List all projects."""
107
+ return self._get("/api/projects/")
108
+
109
+ def list_executions(self, project_id: Optional[str] = None) -> list:
110
+ """List executions, optionally filtered by project."""
111
+ endpoint = "/api/executions/"
112
+ if project_id:
113
+ endpoint += f"?project_id={project_id}"
114
+ return self._get(endpoint)
115
+
116
+ def evaluate(self, execution_id: str) -> dict:
117
+ """Trigger evaluation for an execution."""
118
+ return self._post(f"/api/executions/{execution_id}/evaluate", {})
119
+
120
+ def run_adversarial(self, execution_id: str) -> list:
121
+ """Run adversarial tests on an execution."""
122
+ return self._post(f"/api/adversarial/{execution_id}/run", {})
123
+
124
+ def get_dashboard(self) -> dict:
125
+ """Get dashboard statistics."""
126
+ return self._get("/api/dashboard/stats")
127
+
128
+ def _resolve_project(self, project_name: str) -> str:
129
+ if not project_name:
130
+ raise ValueError("project_name is required")
131
+ projects = self.list_projects()
132
+ for p in projects:
133
+ if p.get("name") == project_name:
134
+ return p.get("id")
135
+ # If not found, maybe create it or raise. The ingest endpoint creates it.
136
+ # But we need ID here, so raise.
137
+ raise ValueError(f"Project '{project_name}' not found. Please create it first.")
138
+
139
+ def evaluate_with_aegis(
140
+ self,
141
+ agent_input: str,
142
+ agent_output: str,
143
+ context_docs: list[str] = None,
144
+ policy_mode: str = "warn",
145
+ project_name: str = None,
146
+ ) -> dict:
147
+ """
148
+ Run aegis-agent safety evaluation on an agent's output.
149
+
150
+ Returns risk score, risk level, flags, and whether output was blocked.
151
+ """
152
+ return self._post("/api/aegis/evaluate", {
153
+ "agent_input": agent_input,
154
+ "agent_output": agent_output,
155
+ "context_docs": context_docs or [],
156
+ "policy_mode": policy_mode,
157
+ "project_id": self._resolve_project(project_name),
158
+ })
159
+
160
+ def create_benchmark(
161
+ self,
162
+ name: str,
163
+ models: list[str],
164
+ test_cases: list[dict],
165
+ project_name: str = None,
166
+ ) -> dict:
167
+ """
168
+ Create and run a model reliability benchmark.
169
+ """
170
+ benchmark = self._post("/api/benchmarks/", {
171
+ "project_id": self._resolve_project(project_name),
172
+ "name": name,
173
+ "models": models,
174
+ "test_cases": test_cases
175
+ })
176
+ self._post(f"/api/benchmarks/{benchmark['id']}/run", {})
177
+ return benchmark
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: auditai-client
3
+ Version: 1.0.0
4
+ Summary: AuditAI – AI Reliability & Compliance Auditor SDK
5
+ Author: AuditAI Team
6
+ Requires-Python: >=3.9
7
+ Requires-Dist: requests>=2.28.0
8
+ Dynamic: author
9
+ Dynamic: requires-dist
10
+ Dynamic: requires-python
11
+ Dynamic: summary
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ auditai/__init__.py
4
+ auditai/client.py
5
+ auditai_client.egg-info/PKG-INFO
6
+ auditai_client.egg-info/SOURCES.txt
7
+ auditai_client.egg-info/dependency_links.txt
8
+ auditai_client.egg-info/requires.txt
9
+ auditai_client.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests>=2.28.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,11 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="auditai-client",
5
+ version="1.0.0",
6
+ description="AuditAI – AI Reliability & Compliance Auditor SDK",
7
+ author="AuditAI Team",
8
+ packages=find_packages(),
9
+ install_requires=["requests>=2.28.0"],
10
+ python_requires=">=3.9",
11
+ )