agenta 0.20.0a11__py3-none-any.whl → 0.20.0a13__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/tracing.py +45 -45
- agenta/sdk/tracing/callbacks.py +18 -12
- {agenta-0.20.0a11.dist-info → agenta-0.20.0a13.dist-info}/METADATA +1 -1
- {agenta-0.20.0a11.dist-info → agenta-0.20.0a13.dist-info}/RECORD +6 -7
- agenta/sdk/tracing/context_manager.py +0 -13
- {agenta-0.20.0a11.dist-info → agenta-0.20.0a13.dist-info}/WHEEL +0 -0
- {agenta-0.20.0a11.dist-info → agenta-0.20.0a13.dist-info}/entry_points.txt +0 -0
agenta/sdk/decorators/tracing.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import inspect
|
|
3
3
|
import traceback
|
|
4
4
|
from functools import wraps
|
|
5
|
-
from typing import Any, Callable, Optional
|
|
5
|
+
from typing import Any, Callable, Optional, List, Union
|
|
6
6
|
|
|
7
7
|
# Own Imports
|
|
8
8
|
import agenta as ag
|
|
@@ -40,9 +40,13 @@ class instrument(BaseDecorator):
|
|
|
40
40
|
self,
|
|
41
41
|
config: Optional[dict] = None,
|
|
42
42
|
spankind: str = "workflow",
|
|
43
|
+
ignore_inputs: Union[List[str], bool] = False,
|
|
44
|
+
ignore_outputs: Union[List[str], bool] = False,
|
|
43
45
|
) -> None:
|
|
44
46
|
self.config = config
|
|
45
47
|
self.spankind = spankind
|
|
48
|
+
self.ignore_inputs = ignore_inputs
|
|
49
|
+
self.ignore_outputs = ignore_outputs
|
|
46
50
|
|
|
47
51
|
def __call__(self, func: Callable[..., Any]):
|
|
48
52
|
is_coroutine_function = inspect.iscoroutinefunction(func)
|
|
@@ -54,38 +58,54 @@ class instrument(BaseDecorator):
|
|
|
54
58
|
|
|
55
59
|
return input_dict
|
|
56
60
|
|
|
61
|
+
def redact(io, blacklist):
|
|
62
|
+
return {
|
|
63
|
+
key: io[key]
|
|
64
|
+
for key in io.keys()
|
|
65
|
+
if key
|
|
66
|
+
not in (
|
|
67
|
+
blacklist
|
|
68
|
+
if isinstance(blacklist, list)
|
|
69
|
+
else []
|
|
70
|
+
if blacklist is False
|
|
71
|
+
else io.keys()
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
def patch(result):
|
|
76
|
+
TRACE_DEFAULT_KEY = "__default__"
|
|
77
|
+
|
|
78
|
+
outputs = result
|
|
79
|
+
|
|
80
|
+
# PATCH : if result is not a dict, make it a dict
|
|
81
|
+
if not isinstance(result, dict):
|
|
82
|
+
outputs = {TRACE_DEFAULT_KEY: result}
|
|
83
|
+
else:
|
|
84
|
+
# PATCH : if result is a legacy dict, clean it up
|
|
85
|
+
if (
|
|
86
|
+
"message" in result.keys()
|
|
87
|
+
and "cost" in result.keys()
|
|
88
|
+
and "usage" in result.keys()
|
|
89
|
+
):
|
|
90
|
+
outputs = {TRACE_DEFAULT_KEY: result["message"]}
|
|
91
|
+
|
|
92
|
+
ag.tracing.store_cost(result["cost"])
|
|
93
|
+
ag.tracing.store_usage(result["usage"])
|
|
94
|
+
|
|
95
|
+
return outputs
|
|
96
|
+
|
|
57
97
|
@wraps(func)
|
|
58
98
|
async def async_wrapper(*args, **kwargs):
|
|
59
99
|
async def wrapped_func(*args, **kwargs):
|
|
60
100
|
with ag.tracing.Context(
|
|
61
101
|
name=func.__name__,
|
|
62
|
-
input=get_inputs(*args, **kwargs),
|
|
102
|
+
input=redact(get_inputs(*args, **kwargs), self.ignore_inputs),
|
|
63
103
|
spankind=self.spankind,
|
|
64
104
|
config=self.config,
|
|
65
105
|
):
|
|
66
106
|
result = await func(*args, **kwargs)
|
|
67
107
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
outputs = result
|
|
71
|
-
|
|
72
|
-
# PATCH : if result is not a dict, make it a dict
|
|
73
|
-
if not isinstance(result, dict):
|
|
74
|
-
outputs = {TRACE_DEFAULT_KEY: result}
|
|
75
|
-
else:
|
|
76
|
-
# PATCH : if result is a legacy dict, clean it up
|
|
77
|
-
if (
|
|
78
|
-
"message" in result.keys()
|
|
79
|
-
and "cost" in result.keys()
|
|
80
|
-
and "usage" in result.keys()
|
|
81
|
-
):
|
|
82
|
-
outputs = {TRACE_DEFAULT_KEY: result["message"]}
|
|
83
|
-
|
|
84
|
-
ag.tracing.store_cost(result["cost"])
|
|
85
|
-
ag.tracing.store_usage(result["usage"])
|
|
86
|
-
# END OF PATH
|
|
87
|
-
|
|
88
|
-
ag.tracing.store_outputs(outputs)
|
|
108
|
+
ag.tracing.store_outputs(redact(patch(result), self.ignore_outputs))
|
|
89
109
|
|
|
90
110
|
return result
|
|
91
111
|
|
|
@@ -96,33 +116,13 @@ class instrument(BaseDecorator):
|
|
|
96
116
|
def wrapped_func(*args, **kwargs):
|
|
97
117
|
with ag.tracing.Context(
|
|
98
118
|
name=func.__name__,
|
|
99
|
-
input=get_inputs(*args, **kwargs),
|
|
119
|
+
input=redact(get_inputs(*args, **kwargs), self.ignore_inputs),
|
|
100
120
|
spankind=self.spankind,
|
|
101
121
|
config=self.config,
|
|
102
122
|
):
|
|
103
123
|
result = func(*args, **kwargs)
|
|
104
124
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
outputs = result
|
|
108
|
-
|
|
109
|
-
# PATCH : if result is not a dict, make it a dict
|
|
110
|
-
if not isinstance(result, dict):
|
|
111
|
-
outputs = {TRACE_DEFAULT_KEY: result}
|
|
112
|
-
else:
|
|
113
|
-
# PATCH : if result is a legacy dict, clean it up
|
|
114
|
-
if (
|
|
115
|
-
"message" in result.keys()
|
|
116
|
-
and "cost" in result.keys()
|
|
117
|
-
and "usage" in result.keys()
|
|
118
|
-
):
|
|
119
|
-
outputs = {"message": result["message"]}
|
|
120
|
-
|
|
121
|
-
ag.tracing.store_cost(result["cost"])
|
|
122
|
-
ag.tracing.store_usage(result["usage"])
|
|
123
|
-
# END OF PATH
|
|
124
|
-
|
|
125
|
-
ag.tracing.store_outputs(outputs)
|
|
125
|
+
ag.tracing.store_outputs(redact(patch(result), self.ignore_outputs))
|
|
126
126
|
|
|
127
127
|
return result
|
|
128
128
|
|
agenta/sdk/tracing/callbacks.py
CHANGED
|
@@ -66,9 +66,10 @@ def litellm_handler():
|
|
|
66
66
|
def log_stream_event(self, kwargs, response_obj, start_time, end_time):
|
|
67
67
|
logging.info(f"log_stream_event({self.span.id})")
|
|
68
68
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
69
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
69
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
70
70
|
ag.tracing.store_usage(
|
|
71
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
71
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
72
|
+
span_id=self.span.id,
|
|
72
73
|
)
|
|
73
74
|
ag.tracing.store_outputs(
|
|
74
75
|
# the complete streamed response (only set if `completion(..stream=True)`
|
|
@@ -81,9 +82,10 @@ def litellm_handler():
|
|
|
81
82
|
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
|
82
83
|
logging.info(f"log_success_event({self.span.id})")
|
|
83
84
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
84
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
85
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
85
86
|
ag.tracing.store_usage(
|
|
86
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
87
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
88
|
+
span_id=self.span.id,
|
|
87
89
|
)
|
|
88
90
|
ag.tracing.store_outputs(
|
|
89
91
|
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
@@ -106,9 +108,10 @@ def litellm_handler():
|
|
|
106
108
|
},
|
|
107
109
|
span_id=self.span.id,
|
|
108
110
|
)
|
|
109
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
111
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
110
112
|
ag.tracing.store_usage(
|
|
111
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
113
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
114
|
+
span_id=self.span.id,
|
|
112
115
|
)
|
|
113
116
|
ag.tracing.store_outputs(
|
|
114
117
|
# the Exception raised
|
|
@@ -123,9 +126,10 @@ def litellm_handler():
|
|
|
123
126
|
):
|
|
124
127
|
logging.info(f"async_log_stream_event({self.span.id})")
|
|
125
128
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
126
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
129
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
127
130
|
ag.tracing.store_usage(
|
|
128
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
131
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
132
|
+
span_id=self.span.id,
|
|
129
133
|
)
|
|
130
134
|
ag.tracing.store_outputs(
|
|
131
135
|
# the complete streamed response (only set if `completion(..stream=True)`)
|
|
@@ -140,9 +144,10 @@ def litellm_handler():
|
|
|
140
144
|
):
|
|
141
145
|
logging.info(f"async_log_success_event({self.span.id})")
|
|
142
146
|
ag.tracing.set_status(status="OK", span_id=self.span.id)
|
|
143
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
147
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
144
148
|
ag.tracing.store_usage(
|
|
145
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
149
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
150
|
+
span_id=self.span.id,
|
|
146
151
|
)
|
|
147
152
|
ag.tracing.store_outputs(
|
|
148
153
|
outputs={TRACE_DEFAULT_KEY: response_obj.choices[0].message.content},
|
|
@@ -167,9 +172,10 @@ def litellm_handler():
|
|
|
167
172
|
},
|
|
168
173
|
span_id=self.span.id,
|
|
169
174
|
)
|
|
170
|
-
ag.tracing.store_cost(kwargs.get("response_cost"))
|
|
175
|
+
ag.tracing.store_cost(kwargs.get("response_cost"), span_id=self.span.id)
|
|
171
176
|
ag.tracing.store_usage(
|
|
172
|
-
response_obj.usage.dict() if hasattr(response_obj, "usage") else None
|
|
177
|
+
response_obj.usage.dict() if hasattr(response_obj, "usage") else None,
|
|
178
|
+
span_id=self.span.id,
|
|
173
179
|
)
|
|
174
180
|
ag.tracing.store_outputs(
|
|
175
181
|
# the Exception raised
|
|
@@ -132,11 +132,10 @@ 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
134
|
agenta/sdk/decorators/llm_entrypoint.py,sha256=9GFT6dpVWY2_1Ckh1Y_N0xSXwosoSjtNtqMEM7u55uY,28224
|
|
135
|
-
agenta/sdk/decorators/tracing.py,sha256=
|
|
135
|
+
agenta/sdk/decorators/tracing.py,sha256=e0olx2EEdjXY0NqpIoDJSVxCnUmv0woewTUuCJXy2tM,4166
|
|
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=
|
|
139
|
-
agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
|
|
138
|
+
agenta/sdk/tracing/callbacks.py,sha256=ug9xeXLgJEpx4l3x1BrJD2bFrH83I3kajlGsU8WtG4U,7699
|
|
140
139
|
agenta/sdk/tracing/llm_tracing.py,sha256=FfZQcID-8E4G0R34H29SA05yFUNDMEPccb4MqVcNDLM,18064
|
|
141
140
|
agenta/sdk/tracing/logger.py,sha256=GfH7V-jBHcn7h5dbdrnkDMe_ml3wkXFBeoQiqR4KVRc,474
|
|
142
141
|
agenta/sdk/tracing/tasks_manager.py,sha256=FBSFOWIKBycyA4ShB2ZVMzrzYQ8pWGWWBClFX8nlZFA,3726
|
|
@@ -161,7 +160,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
161
160
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
162
161
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
163
162
|
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.
|
|
163
|
+
agenta-0.20.0a13.dist-info/METADATA,sha256=oJVH3pqpuNq7If3Mhg9s6_4ZqYo-wNbF5IjFWIxYQvo,26463
|
|
164
|
+
agenta-0.20.0a13.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
165
|
+
agenta-0.20.0a13.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
166
|
+
agenta-0.20.0a13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|