auditi 0.1.0__py3-none-any.whl

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.
auditi/__init__.py ADDED
@@ -0,0 +1,47 @@
1
+ """
2
+ Auditi - AI/LLM Evaluation and Monitoring SDK
3
+
4
+ This package provides decorators and utilities for tracing AI agent
5
+ interactions and sending them to the Auditi platform for evaluation.
6
+ """
7
+
8
+ from .client import init, get_client, AuditiClient
9
+ from .decorators import trace_agent, trace_tool, trace_llm, trace_embedding, trace_retrieval
10
+ from .evaluator import BaseEvaluator
11
+ from .context import get_current_trace, set_current_trace, set_context, get_context
12
+ from .client import get_client
13
+ from .evaluator import BaseEvaluator
14
+ from .transport import BaseTransport, SyncHttpTransport, DebugTransport
15
+ from .types import TraceInput, SpanInput, EvaluationResult
16
+ from .events import EventType, StreamEvent
17
+
18
+ __version__ = "0.1.0"
19
+
20
+ __all__ = [
21
+ # Client
22
+ "init",
23
+ "get_client",
24
+ "AuditiClient",
25
+ # Context
26
+ "set_context",
27
+ "get_context",
28
+ # Decorators
29
+ "trace_agent",
30
+ "trace_tool",
31
+ "trace_llm",
32
+ "trace_embedding",
33
+ "trace_retrieval",
34
+ # Evaluator
35
+ "BaseEvaluator",
36
+ # Transport
37
+ "BaseTransport",
38
+ "SyncHttpTransport",
39
+ "DebugTransport",
40
+ # Types
41
+ "TraceInput",
42
+ "SpanInput",
43
+ "EvaluationResult",
44
+ # Events
45
+ "EventType",
46
+ "StreamEvent",
47
+ ]
auditi/client.py ADDED
@@ -0,0 +1,76 @@
1
+ """
2
+ Auditi SDK Client
3
+
4
+ Manages SDK initialization and provides access to the transport layer.
5
+ """
6
+ from typing import Optional
7
+ from .transport import BaseTransport, SyncHttpTransport
8
+
9
+
10
+ class AuditiClient:
11
+ """
12
+ Main client for the Auditi SDK.
13
+ Manages the transport layer for sending traces to the Auditi platform.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ api_key: Optional[str] = None,
19
+ base_url: str = "http://localhost:8000",
20
+ transport: Optional[BaseTransport] = None
21
+ ):
22
+ """
23
+ Initialize the Auditi client.
24
+
25
+ Args:
26
+ api_key: API key for authentication (optional for local development)
27
+ base_url: Base URL of the Auditi API
28
+ transport: Custom transport implementation (optional)
29
+ """
30
+ if transport:
31
+ self.transport = transport
32
+ else:
33
+ self.transport = SyncHttpTransport(base_url, api_key)
34
+
35
+
36
+ # Global client instance
37
+ _client_instance: Optional[AuditiClient] = None
38
+
39
+
40
+ def init(
41
+ api_key: Optional[str] = None,
42
+ base_url: str = "http://localhost:8000",
43
+ transport: Optional[BaseTransport] = None
44
+ ) -> AuditiClient:
45
+ """
46
+ Initialize the Auditi SDK with the given configuration.
47
+
48
+ Args:
49
+ api_key: API key for authentication
50
+ base_url: Base URL of the Auditi API (default: localhost:8000)
51
+ transport: Custom transport implementation
52
+
53
+ Returns:
54
+ The initialized AuditiClient instance
55
+
56
+ Example:
57
+ >>> import auditi
58
+ >>> auditi.init(api_key="your-key", base_url="https://api.auditi.dev")
59
+ """
60
+ global _client_instance
61
+ _client_instance = AuditiClient(api_key, base_url, transport)
62
+ return _client_instance
63
+
64
+
65
+ def get_client() -> AuditiClient:
66
+ """
67
+ Get the current Auditi client instance.
68
+ If not initialized, creates a default client for local development.
69
+
70
+ Returns:
71
+ The current AuditiClient instance
72
+ """
73
+ global _client_instance
74
+ if _client_instance is None:
75
+ _client_instance = AuditiClient()
76
+ return _client_instance
auditi/context.py ADDED
@@ -0,0 +1,71 @@
1
+ """
2
+ Context management for trace and span tracking.
3
+
4
+ Uses Python's contextvars for thread-safe context propagation.
5
+ """
6
+ from contextvars import ContextVar
7
+ from typing import Optional, List
8
+ from .types import TraceInput, SpanInput
9
+
10
+ # Context variables for thread-safe trace tracking
11
+ _current_trace: ContextVar[Optional[TraceInput]] = ContextVar("current_trace", default=None)
12
+ _span_stack: ContextVar[List[SpanInput]] = ContextVar("span_stack", default=[])
13
+ _global_context: ContextVar[dict] = ContextVar("global_context", default={})
14
+
15
+
16
+ def get_current_trace() -> Optional[TraceInput]:
17
+ """Get the current active trace, if any."""
18
+ return _current_trace.get()
19
+
20
+
21
+ def set_current_trace(trace: TraceInput) -> None:
22
+ """Set the current active trace."""
23
+ _current_trace.set(trace)
24
+
25
+
26
+ def clear_current_trace() -> None:
27
+ """Clear the current trace context."""
28
+ _current_trace.set(None)
29
+ _span_stack.set([])
30
+
31
+
32
+ def get_current_span() -> Optional[SpanInput]:
33
+ """Get the current (innermost) span, if any."""
34
+ stack = _span_stack.get()
35
+ if stack:
36
+ return stack[-1]
37
+ return None
38
+
39
+
40
+ def push_span(span: SpanInput) -> None:
41
+ """Push a new span onto the stack."""
42
+ stack = _span_stack.get()
43
+ new_stack = stack.copy()
44
+ new_stack.append(span)
45
+ _span_stack.set(new_stack)
46
+
47
+
48
+ def pop_span() -> Optional[SpanInput]:
49
+ """Pop the current span from the stack."""
50
+ stack = _span_stack.get()
51
+ if not stack:
52
+ return None
53
+ new_stack = stack.copy()
54
+ span = new_stack.pop()
55
+ _span_stack.set(new_stack)
56
+ return span
57
+
58
+
59
+ def set_context(user_id: str = None, session_id: str = None) -> None:
60
+ """Set global context for the current execution context."""
61
+ ctx = _global_context.get().copy()
62
+ if user_id:
63
+ ctx["user_id"] = user_id
64
+ if session_id:
65
+ ctx["session_id"] = session_id
66
+ _global_context.set(ctx)
67
+
68
+
69
+ def get_context() -> dict:
70
+ """Get the current global context."""
71
+ return _global_context.get()