agenta 0.26.0a0__py3-none-any.whl → 0.27.0a0__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.
Potentially problematic release.
This version of agenta might be problematic. Click here for more details.
- agenta/__init__.py +6 -7
- agenta/client/backend/client.py +22 -14
- agenta/client/backend/core/http_client.py +23 -15
- agenta/sdk/__init__.py +27 -6
- agenta/sdk/agenta_init.py +73 -26
- agenta/sdk/config_manager.py +2 -2
- agenta/sdk/context/__init__.py +0 -0
- agenta/sdk/context/routing.py +25 -0
- agenta/sdk/context/tracing.py +3 -0
- agenta/sdk/decorators/__init__.py +0 -0
- agenta/sdk/decorators/{llm_entrypoint.py → routing.py} +137 -124
- agenta/sdk/decorators/tracing.py +228 -76
- agenta/sdk/litellm/__init__.py +1 -0
- agenta/sdk/litellm/litellm.py +277 -0
- agenta/sdk/router.py +0 -7
- agenta/sdk/tracing/__init__.py +1 -0
- agenta/sdk/tracing/attributes.py +181 -0
- agenta/sdk/tracing/context.py +21 -0
- agenta/sdk/tracing/conventions.py +43 -0
- agenta/sdk/tracing/exporters.py +53 -0
- agenta/sdk/tracing/inline.py +1306 -0
- agenta/sdk/tracing/processors.py +65 -0
- agenta/sdk/tracing/spans.py +124 -0
- agenta/sdk/tracing/tracing.py +174 -0
- agenta/sdk/types.py +0 -12
- agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
- agenta/sdk/utils/debug.py +5 -5
- agenta/sdk/utils/exceptions.py +19 -0
- agenta/sdk/utils/globals.py +3 -5
- agenta/sdk/{tracing/logger.py → utils/logging.py} +3 -5
- agenta/sdk/utils/singleton.py +13 -0
- {agenta-0.26.0a0.dist-info → agenta-0.27.0a0.dist-info}/METADATA +5 -1
- {agenta-0.26.0a0.dist-info → agenta-0.27.0a0.dist-info}/RECORD +35 -25
- agenta/sdk/context.py +0 -41
- agenta/sdk/decorators/base.py +0 -10
- agenta/sdk/tracing/callbacks.py +0 -187
- agenta/sdk/tracing/llm_tracing.py +0 -617
- agenta/sdk/tracing/tasks_manager.py +0 -129
- agenta/sdk/tracing/tracing_context.py +0 -27
- {agenta-0.26.0a0.dist-info → agenta-0.27.0a0.dist-info}/WHEEL +0 -0
- {agenta-0.26.0a0.dist-info → agenta-0.27.0a0.dist-info}/entry_points.txt +0 -0
agenta/sdk/decorators/base.py
DELETED
agenta/sdk/tracing/callbacks.py
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import agenta as ag
|
|
2
|
-
|
|
3
|
-
from agenta.sdk.tracing.tracing_context import tracing_context, TracingContext
|
|
4
|
-
from agenta.sdk.tracing.logger import llm_logger as logging
|
|
5
|
-
|
|
6
|
-
from agenta.sdk.utils.debug import debug
|
|
7
|
-
|
|
8
|
-
TRACE_DEFAULT_KEY = "__default__"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def litellm_handler():
|
|
12
|
-
try:
|
|
13
|
-
from litellm.utils import ModelResponse
|
|
14
|
-
from litellm.integrations.custom_logger import (
|
|
15
|
-
CustomLogger as LitellmCustomLogger,
|
|
16
|
-
)
|
|
17
|
-
except ImportError as exc:
|
|
18
|
-
raise ImportError(
|
|
19
|
-
"The litellm SDK is not installed. Please install it using `pip install litellm`."
|
|
20
|
-
) from exc
|
|
21
|
-
except Exception as exc:
|
|
22
|
-
raise Exception(
|
|
23
|
-
"Unexpected error occurred when importing litellm: {}".format(exc)
|
|
24
|
-
) from exc
|
|
25
|
-
|
|
26
|
-
class LitellmHandler(LitellmCustomLogger):
|
|
27
|
-
"""This handler is responsible for instrumenting certain events when using litellm to call LLMs.
|
|
28
|
-
|
|
29
|
-
Args:
|
|
30
|
-
LitellmCustomLogger (object): custom logger that allows us to override the events to capture.
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
def __init__(self):
|
|
34
|
-
self.span = None
|
|
35
|
-
|
|
36
|
-
@property
|
|
37
|
-
def _trace(self):
|
|
38
|
-
return ag.tracing
|
|
39
|
-
|
|
40
|
-
@debug()
|
|
41
|
-
def log_pre_api_call(self, model, messages, kwargs):
|
|
42
|
-
call_type = kwargs.get("call_type")
|
|
43
|
-
span_kind = (
|
|
44
|
-
"llm" if call_type in ["completion", "acompletion"] else "embedding"
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
self.span = ag.tracing.open_span(
|
|
48
|
-
name=f"{span_kind}_call",
|
|
49
|
-
input={"messages": kwargs["messages"]},
|
|
50
|
-
spankind=span_kind,
|
|
51
|
-
active=False,
|
|
52
|
-
)
|
|
53
|
-
logging.info(f"log_pre_api_call({self.span.id})")
|
|
54
|
-
ag.tracing.set_attributes(
|
|
55
|
-
{
|
|
56
|
-
"model_config": {
|
|
57
|
-
"model": kwargs.get("model"),
|
|
58
|
-
**kwargs.get(
|
|
59
|
-
"optional_params"
|
|
60
|
-
), # model-specific params passed in
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
@debug()
|
|
66
|
-
def log_stream_event(self, kwargs, response_obj, start_time, end_time):
|
|
67
|
-
logging.info(f"log_stream_event({self.span.id})")
|
|
68
|
-
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
69
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
70
|
-
ag.tracing.store_usage(
|
|
71
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
72
|
-
span_id=self.span.id,
|
|
73
|
-
)
|
|
74
|
-
ag.tracing.store_outputs(
|
|
75
|
-
# the complete streamed response (only set if `completion(..stream=True)`
|
|
76
|
-
outputs={TRACE_DEFAULT_KEY: kwargs.get("complete_streaming_response")},
|
|
77
|
-
span_id=self.span.id,
|
|
78
|
-
)
|
|
79
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
80
|
-
|
|
81
|
-
@debug()
|
|
82
|
-
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
|
83
|
-
logging.info(f"log_success_event({self.span.id})")
|
|
84
|
-
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
85
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
86
|
-
ag.tracing.store_usage(
|
|
87
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
88
|
-
span_id=self.span.id,
|
|
89
|
-
)
|
|
90
|
-
ag.tracing.store_outputs(
|
|
91
|
-
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
92
|
-
span_id=self.span.id,
|
|
93
|
-
)
|
|
94
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
95
|
-
|
|
96
|
-
@debug()
|
|
97
|
-
def log_failure_event(self, kwargs, response_obj, start_time, end_time):
|
|
98
|
-
logging.info("log_failure_event()", self.span)
|
|
99
|
-
ag.tracing.set_status(status="ERROR", span_id=self.span.id)
|
|
100
|
-
ag.tracing.set_attributes(
|
|
101
|
-
{
|
|
102
|
-
"traceback_exception": repr(
|
|
103
|
-
kwargs["traceback_exception"]
|
|
104
|
-
), # the traceback generated via `traceback.format_exc()`
|
|
105
|
-
"call_end_time": kwargs[
|
|
106
|
-
"end_time"
|
|
107
|
-
], # datetime object of when call was completed
|
|
108
|
-
},
|
|
109
|
-
span_id=self.span.id,
|
|
110
|
-
)
|
|
111
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
112
|
-
ag.tracing.store_usage(
|
|
113
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
114
|
-
span_id=self.span.id,
|
|
115
|
-
)
|
|
116
|
-
ag.tracing.store_outputs(
|
|
117
|
-
# the Exception raised
|
|
118
|
-
outputs={TRACE_DEFAULT_KEY: repr(kwargs["exception"])},
|
|
119
|
-
span_id=self.span.id,
|
|
120
|
-
)
|
|
121
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
122
|
-
|
|
123
|
-
@debug()
|
|
124
|
-
async def async_log_stream_event(
|
|
125
|
-
self, kwargs, response_obj, start_time, end_time
|
|
126
|
-
):
|
|
127
|
-
logging.info(f"async_log_stream_event({self.span.id})")
|
|
128
|
-
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
129
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
130
|
-
ag.tracing.store_usage(
|
|
131
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
132
|
-
span_id=self.span.id,
|
|
133
|
-
)
|
|
134
|
-
ag.tracing.store_outputs(
|
|
135
|
-
# the complete streamed response (only set if `completion(..stream=True)`)
|
|
136
|
-
outputs={TRACE_DEFAULT_KEY: kwargs.get("complete_streaming_response")},
|
|
137
|
-
span_id=self.span.id,
|
|
138
|
-
)
|
|
139
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
140
|
-
|
|
141
|
-
@debug()
|
|
142
|
-
async def async_log_success_event(
|
|
143
|
-
self, kwargs, response_obj, start_time, end_time
|
|
144
|
-
):
|
|
145
|
-
logging.info(f"async_log_success_event({self.span.id})")
|
|
146
|
-
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
147
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
148
|
-
ag.tracing.store_usage(
|
|
149
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
150
|
-
span_id=self.span.id,
|
|
151
|
-
)
|
|
152
|
-
ag.tracing.store_outputs(
|
|
153
|
-
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
154
|
-
span_id=self.span.id,
|
|
155
|
-
)
|
|
156
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
157
|
-
|
|
158
|
-
@debug()
|
|
159
|
-
async def async_log_failure_event(
|
|
160
|
-
self, kwargs, response_obj, start_time, end_time
|
|
161
|
-
):
|
|
162
|
-
logging.info(f"async_log_failure_event({self.span.id})")
|
|
163
|
-
ag.tracing.set_status(status="ERROR", span_id=self.span.id)
|
|
164
|
-
ag.tracing.set_attributes(
|
|
165
|
-
{
|
|
166
|
-
"traceback_exception": kwargs[
|
|
167
|
-
"traceback_exception"
|
|
168
|
-
], # the traceback generated via `traceback.format_exc()`
|
|
169
|
-
"call_end_time": kwargs[
|
|
170
|
-
"end_time"
|
|
171
|
-
], # datetime object of when call was completed
|
|
172
|
-
},
|
|
173
|
-
span_id=self.span.id,
|
|
174
|
-
)
|
|
175
|
-
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
176
|
-
ag.tracing.store_usage(
|
|
177
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
178
|
-
span_id=self.span.id,
|
|
179
|
-
)
|
|
180
|
-
ag.tracing.store_outputs(
|
|
181
|
-
# the Exception raised
|
|
182
|
-
outputs={TRACE_DEFAULT_KEY: repr(kwargs["exception"])},
|
|
183
|
-
span_id=self.span.id,
|
|
184
|
-
)
|
|
185
|
-
ag.tracing.close_span(span_id=self.span.id)
|
|
186
|
-
|
|
187
|
-
return LitellmHandler()
|