agenta 0.20.0a9__py3-none-any.whl → 0.20.0a11__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/sdk/decorators/llm_entrypoint.py +6 -6
- agenta/sdk/decorators/tracing.py +1 -1
- agenta/sdk/tracing/callbacks.py +40 -18
- agenta/sdk/tracing/llm_tracing.py +5 -2
- {agenta-0.20.0a9.dist-info → agenta-0.20.0a11.dist-info}/METADATA +1 -1
- {agenta-0.20.0a9.dist-info → agenta-0.20.0a11.dist-info}/RECORD +8 -8
- {agenta-0.20.0a9.dist-info → agenta-0.20.0a11.dist-info}/WHEEL +0 -0
- {agenta-0.20.0a9.dist-info → agenta-0.20.0a11.dist-info}/entry_points.txt +0 -0
|
@@ -120,7 +120,7 @@ class entrypoint(BaseDecorator):
|
|
|
120
120
|
routes = list()
|
|
121
121
|
|
|
122
122
|
def __init__(self, func: Callable[..., Any], route_path=""):
|
|
123
|
-
|
|
123
|
+
logging.info(f"Using Agenta Python SDK version {version('agenta')}")
|
|
124
124
|
|
|
125
125
|
DEFAULT_PATH = "generate"
|
|
126
126
|
PLAYGROUND_PATH = "/playground"
|
|
@@ -293,11 +293,11 @@ class entrypoint(BaseDecorator):
|
|
|
293
293
|
For synchronous functions, it calls them directly, while for asynchronous functions,
|
|
294
294
|
it awaits their execution.
|
|
295
295
|
"""
|
|
296
|
-
|
|
296
|
+
logging.info(f"Using Agenta Python SDK version {version('agenta')}")
|
|
297
297
|
|
|
298
298
|
WAIT_FOR_SPANS = True
|
|
299
|
-
TIMEOUT =
|
|
300
|
-
TIMESTEP = 0.
|
|
299
|
+
TIMEOUT = 1
|
|
300
|
+
TIMESTEP = 0.1
|
|
301
301
|
NOFSTEPS = TIMEOUT / TIMESTEP
|
|
302
302
|
|
|
303
303
|
data = None
|
|
@@ -319,7 +319,7 @@ class entrypoint(BaseDecorator):
|
|
|
319
319
|
remaining_steps = NOFSTEPS
|
|
320
320
|
|
|
321
321
|
while not ag.tracing.is_trace_ready() and remaining_steps > 0:
|
|
322
|
-
await asyncio.sleep(
|
|
322
|
+
await asyncio.sleep(TIMESTEP)
|
|
323
323
|
remaining_steps -= 1
|
|
324
324
|
|
|
325
325
|
trace = ag.tracing.dump_trace()
|
|
@@ -355,7 +355,7 @@ class entrypoint(BaseDecorator):
|
|
|
355
355
|
|
|
356
356
|
response = BaseResponse(data=data, trace=trace)
|
|
357
357
|
|
|
358
|
-
logging.debug(response)
|
|
358
|
+
# logging.debug(response)
|
|
359
359
|
|
|
360
360
|
return response
|
|
361
361
|
|
agenta/sdk/decorators/tracing.py
CHANGED
|
@@ -79,7 +79,7 @@ class instrument(BaseDecorator):
|
|
|
79
79
|
and "cost" in result.keys()
|
|
80
80
|
and "usage" in result.keys()
|
|
81
81
|
):
|
|
82
|
-
outputs = {
|
|
82
|
+
outputs = {TRACE_DEFAULT_KEY: result["message"]}
|
|
83
83
|
|
|
84
84
|
ag.tracing.store_cost(result["cost"])
|
|
85
85
|
ag.tracing.store_usage(result["usage"])
|
agenta/sdk/tracing/callbacks.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import agenta as ag
|
|
2
2
|
|
|
3
3
|
from agenta.sdk.tracing.tracing_context import tracing_context, TracingContext
|
|
4
|
+
from agenta.sdk.tracing.logger import llm_logger as logging
|
|
4
5
|
|
|
5
6
|
from agenta.sdk.utils.debug import debug
|
|
6
7
|
|
|
8
|
+
TRACE_DEFAULT_KEY = "__default__"
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
def litellm_handler():
|
|
9
12
|
try:
|
|
@@ -47,6 +50,7 @@ def litellm_handler():
|
|
|
47
50
|
spankind=span_kind,
|
|
48
51
|
active=False,
|
|
49
52
|
)
|
|
53
|
+
logging.info(f"log_pre_api_call({self.span.id})")
|
|
50
54
|
ag.tracing.set_attributes(
|
|
51
55
|
{
|
|
52
56
|
"model_config": {
|
|
@@ -59,30 +63,37 @@ def litellm_handler():
|
|
|
59
63
|
)
|
|
60
64
|
|
|
61
65
|
@debug()
|
|
62
|
-
def log_stream_event(self, kwargs,
|
|
66
|
+
def log_stream_event(self, kwargs, response_obj, start_time, end_time):
|
|
67
|
+
logging.info(f"log_stream_event({self.span.id})")
|
|
63
68
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
64
69
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
65
|
-
ag.tracing.store_usage(
|
|
70
|
+
ag.tracing.store_usage(
|
|
71
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
72
|
+
)
|
|
66
73
|
ag.tracing.store_outputs(
|
|
67
74
|
# the complete streamed response (only set if `completion(..stream=True)`
|
|
68
|
-
outputs={
|
|
75
|
+
outputs={TRACE_DEFAULT_KEY: kwargs.get("complete_streaming_response")},
|
|
69
76
|
span_id=self.span.id,
|
|
70
77
|
)
|
|
71
78
|
ag.tracing.close_span(span_id=self.span.id)
|
|
72
79
|
|
|
73
80
|
@debug()
|
|
74
|
-
def log_success_event(self, kwargs,
|
|
81
|
+
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
|
82
|
+
logging.info(f"log_success_event({self.span.id})")
|
|
75
83
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
76
84
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
77
|
-
ag.tracing.store_usage(
|
|
85
|
+
ag.tracing.store_usage(
|
|
86
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
87
|
+
)
|
|
78
88
|
ag.tracing.store_outputs(
|
|
79
|
-
outputs={
|
|
89
|
+
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
80
90
|
span_id=self.span.id,
|
|
81
91
|
)
|
|
82
92
|
ag.tracing.close_span(span_id=self.span.id)
|
|
83
93
|
|
|
84
94
|
@debug()
|
|
85
|
-
def log_failure_event(self, kwargs,
|
|
95
|
+
def log_failure_event(self, kwargs, response_obj, start_time, end_time):
|
|
96
|
+
logging.info("log_failure_event()", self.span)
|
|
86
97
|
ag.tracing.set_status(status="ERROR", span_id=self.span.id)
|
|
87
98
|
ag.tracing.set_attributes(
|
|
88
99
|
{
|
|
@@ -96,45 +107,54 @@ def litellm_handler():
|
|
|
96
107
|
span_id=self.span.id,
|
|
97
108
|
)
|
|
98
109
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
99
|
-
ag.tracing.store_usage(
|
|
110
|
+
ag.tracing.store_usage(
|
|
111
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
112
|
+
)
|
|
100
113
|
ag.tracing.store_outputs(
|
|
101
114
|
# the Exception raised
|
|
102
|
-
outputs={
|
|
115
|
+
outputs={TRACE_DEFAULT_KEY: repr(kwargs["exception"])},
|
|
103
116
|
span_id=self.span.id,
|
|
104
117
|
)
|
|
105
118
|
ag.tracing.close_span(span_id=self.span.id)
|
|
106
119
|
|
|
107
120
|
@debug()
|
|
108
121
|
async def async_log_stream_event(
|
|
109
|
-
self, kwargs,
|
|
122
|
+
self, kwargs, response_obj, start_time, end_time
|
|
110
123
|
):
|
|
124
|
+
logging.info(f"async_log_stream_event({self.span.id})")
|
|
111
125
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
112
126
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
113
|
-
ag.tracing.store_usage(
|
|
127
|
+
ag.tracing.store_usage(
|
|
128
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
129
|
+
)
|
|
114
130
|
ag.tracing.store_outputs(
|
|
115
131
|
# the complete streamed response (only set if `completion(..stream=True)`)
|
|
116
|
-
outputs={
|
|
132
|
+
outputs={TRACE_DEFAULT_KEY: kwargs.get("complete_streaming_response")},
|
|
117
133
|
span_id=self.span.id,
|
|
118
134
|
)
|
|
119
135
|
ag.tracing.close_span(span_id=self.span.id)
|
|
120
136
|
|
|
121
137
|
@debug()
|
|
122
138
|
async def async_log_success_event(
|
|
123
|
-
self, kwargs,
|
|
139
|
+
self, kwargs, response_obj, start_time, end_time
|
|
124
140
|
):
|
|
141
|
+
logging.info(f"async_log_success_event({self.span.id})")
|
|
125
142
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
126
143
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
127
|
-
ag.tracing.store_usage(
|
|
144
|
+
ag.tracing.store_usage(
|
|
145
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
146
|
+
)
|
|
128
147
|
ag.tracing.store_outputs(
|
|
129
|
-
outputs={
|
|
148
|
+
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
130
149
|
span_id=self.span.id,
|
|
131
150
|
)
|
|
132
151
|
ag.tracing.close_span(span_id=self.span.id)
|
|
133
152
|
|
|
134
153
|
@debug()
|
|
135
154
|
async def async_log_failure_event(
|
|
136
|
-
self, kwargs,
|
|
155
|
+
self, kwargs, response_obj, start_time, end_time
|
|
137
156
|
):
|
|
157
|
+
logging.info(f"async_log_failure_event({self.span.id})")
|
|
138
158
|
ag.tracing.set_status(status="ERROR", span_id=self.span.id)
|
|
139
159
|
ag.tracing.set_attributes(
|
|
140
160
|
{
|
|
@@ -148,10 +168,12 @@ def litellm_handler():
|
|
|
148
168
|
span_id=self.span.id,
|
|
149
169
|
)
|
|
150
170
|
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
151
|
-
ag.tracing.store_usage(
|
|
171
|
+
ag.tracing.store_usage(
|
|
172
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
173
|
+
)
|
|
152
174
|
ag.tracing.store_outputs(
|
|
153
175
|
# the Exception raised
|
|
154
|
-
outputs={
|
|
176
|
+
outputs={TRACE_DEFAULT_KEY: repr(kwargs["exception"])},
|
|
155
177
|
span_id=self.span.id,
|
|
156
178
|
)
|
|
157
179
|
ag.tracing.close_span(span_id=self.span.id)
|
|
@@ -267,7 +267,7 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
267
267
|
outputs=None,
|
|
268
268
|
tags=None,
|
|
269
269
|
user=None,
|
|
270
|
-
end_time=
|
|
270
|
+
end_time=None,
|
|
271
271
|
tokens=None,
|
|
272
272
|
cost=None,
|
|
273
273
|
token_consumption=None,
|
|
@@ -372,7 +372,7 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
372
372
|
tracing.active_span = parent_span
|
|
373
373
|
### --- TO BE CLEANED --- <<<
|
|
374
374
|
|
|
375
|
-
logging.info(f"Closed span {
|
|
375
|
+
logging.info(f"Closed span {span.id} {spankind}")
|
|
376
376
|
|
|
377
377
|
@debug()
|
|
378
378
|
def store_internals(
|
|
@@ -457,6 +457,9 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
457
457
|
trace["trace_id"] = tracing.trace_id
|
|
458
458
|
|
|
459
459
|
for span in tracing.spans.values():
|
|
460
|
+
if span.end_time is None:
|
|
461
|
+
span.end_time = span.start_time
|
|
462
|
+
|
|
460
463
|
if span.parent_span_id is None:
|
|
461
464
|
trace["cost"] = span.cost
|
|
462
465
|
trace["usage"] = (
|
|
@@ -131,13 +131,13 @@ agenta/sdk/agenta_init.py,sha256=8MfDuypxohd0qRTdtGjX7L17KW-1UGmzNVdiqF15_ak,979
|
|
|
131
131
|
agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
|
|
132
132
|
agenta/sdk/context.py,sha256=q-PxL05-I84puunUAs9LGsffEXcYhDxhQxjuOz2vK90,901
|
|
133
133
|
agenta/sdk/decorators/base.py,sha256=9aNdX5h8a2mFweuhdO-BQPwXGKY9ONPIdLRhSGAGMfY,217
|
|
134
|
-
agenta/sdk/decorators/llm_entrypoint.py,sha256=
|
|
135
|
-
agenta/sdk/decorators/tracing.py,sha256=
|
|
134
|
+
agenta/sdk/decorators/llm_entrypoint.py,sha256=9GFT6dpVWY2_1Ckh1Y_N0xSXwosoSjtNtqMEM7u55uY,28224
|
|
135
|
+
agenta/sdk/decorators/tracing.py,sha256=J9MG04g0OoN_nGB1JkkVzCX1XPaouQr93SR54-TSRTA,4379
|
|
136
136
|
agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
|
|
137
137
|
agenta/sdk/tracing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
138
|
-
agenta/sdk/tracing/callbacks.py,sha256=
|
|
138
|
+
agenta/sdk/tracing/callbacks.py,sha256=JD6Q7_geFzZSwCnW8u3ISw3cWCYc2TEjGg-rf-colf8,7333
|
|
139
139
|
agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
|
|
140
|
-
agenta/sdk/tracing/llm_tracing.py,sha256=
|
|
140
|
+
agenta/sdk/tracing/llm_tracing.py,sha256=FfZQcID-8E4G0R34H29SA05yFUNDMEPccb4MqVcNDLM,18064
|
|
141
141
|
agenta/sdk/tracing/logger.py,sha256=GfH7V-jBHcn7h5dbdrnkDMe_ml3wkXFBeoQiqR4KVRc,474
|
|
142
142
|
agenta/sdk/tracing/tasks_manager.py,sha256=FBSFOWIKBycyA4ShB2ZVMzrzYQ8pWGWWBClFX8nlZFA,3726
|
|
143
143
|
agenta/sdk/tracing/tracing_context.py,sha256=nt3ewa-TK9BRJviGIZYazsAQUiG4daWxjtsbjeaDprs,789
|
|
@@ -161,7 +161,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
161
161
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
162
162
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
163
163
|
agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
|
|
164
|
-
agenta-0.20.
|
|
165
|
-
agenta-0.20.
|
|
166
|
-
agenta-0.20.
|
|
167
|
-
agenta-0.20.
|
|
164
|
+
agenta-0.20.0a11.dist-info/METADATA,sha256=ehpOsYlSZ6gwcRxA9_kBHrCfGvaAIp9uE3aUFmOfYnQ,26463
|
|
165
|
+
agenta-0.20.0a11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
166
|
+
agenta-0.20.0a11.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
167
|
+
agenta-0.20.0a11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|