agenta 0.25.4a1__py3-none-any.whl → 0.25.4a3__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.

@@ -656,8 +656,7 @@ class entrypoint:
656
656
 
657
657
  SHOW_DETAILS = True
658
658
  SHOW_DATA = False
659
- SHOW_SPANS = True
660
- SHOW_SPAN_ATTRIBUTES = False
659
+ SHOW_TRACE = False
661
660
 
662
661
  log.info("\n========= Result =========\n")
663
662
 
@@ -665,14 +664,14 @@ class entrypoint:
665
664
  if SHOW_DETAILS:
666
665
  log.info(f"latency: {result.trace.get('latency')}")
667
666
  log.info(f"cost: {result.trace.get('cost')}")
668
- log.info(f"tokens: {list(result.trace.get('tokens', {}).values())}")
667
+ log.info(f"usage: {list(result.trace.get('usage', {}).values())}")
669
668
 
670
669
  if SHOW_DATA:
671
670
  log.info(" ")
672
671
  log.info(f"data:")
673
672
  log.info(json.dumps(result.data, indent=2))
674
673
 
675
- if SHOW_SPANS:
674
+ if SHOW_TRACE:
676
675
  log.info(" ")
677
676
  log.info(f"trace:")
678
677
  log.info(f"----------------")
@@ -1,5 +1,7 @@
1
1
  import agenta as ag
2
2
 
3
+ from opentelemetry.trace import SpanKind
4
+
3
5
  from agenta.sdk.tracing.spans import CustomSpan
4
6
  from agenta.sdk.utils.exceptions import suppress
5
7
  from agenta.sdk.utils.logging import log
@@ -42,10 +44,10 @@ def litellm_handler():
42
44
  else "embedding"
43
45
  )
44
46
 
45
- kind = "CLIENT"
47
+ kind = SpanKind.CLIENT
46
48
 
47
49
  self.span = CustomSpan(
48
- ag.tracer.start_span(name=f"litellm_{kind.lower()}", kind=kind)
50
+ ag.tracer.start_span(name=f"litellm_{kind.name.lower()}", kind=kind)
49
51
  )
50
52
 
51
53
  self.span.set_attributes(
@@ -999,7 +999,7 @@ def parse_to_agenta_span_dto(
999
999
  ########################################
1000
1000
 
1001
1001
 
1002
- from copy import deepcopy
1002
+ from litellm import cost_calculator
1003
1003
  from opentelemetry.sdk.trace import ReadableSpan
1004
1004
 
1005
1005
 
@@ -1032,6 +1032,7 @@ def parse_inline_trace(
1032
1032
  ###############################################
1033
1033
  ### services.observability.service.ingest() ###
1034
1034
  ### --------------------------------------- ###
1035
+ calculate_cost(span_idx)
1035
1036
  cumulate_costs(span_id_tree, span_idx)
1036
1037
  cumulate_tokens(span_id_tree, span_idx)
1037
1038
  ### --------------------------------------- ###
@@ -1083,7 +1084,7 @@ def parse_inline_trace(
1083
1084
  "trace_id": trace_id,
1084
1085
  "latency": latency,
1085
1086
  "cost": cost,
1086
- "tokens": tokens,
1087
+ "usage": tokens,
1087
1088
  "spans": spans,
1088
1089
  }
1089
1090
 
@@ -1267,3 +1268,38 @@ def _parse_to_legacy_span(span: SpanDTO) -> CreateSpan:
1267
1268
  )
1268
1269
 
1269
1270
  return legacy_span
1271
+
1272
+
1273
+ PAYING_TYPES = [
1274
+ "embedding",
1275
+ "query",
1276
+ "completion",
1277
+ "chat",
1278
+ "rerank",
1279
+ ]
1280
+
1281
+
1282
+ def calculate_cost(span_idx: Dict[str, SpanCreateDTO]):
1283
+ for span in span_idx.values():
1284
+ if span.node.type.name.lower() in PAYING_TYPES and span.meta and span.metrics:
1285
+ try:
1286
+ costs = cost_calculator.cost_per_token(
1287
+ model=span.meta.get("response.model"),
1288
+ prompt_tokens=span.metrics.get("unit.tokens.prompt", 0.0),
1289
+ completion_tokens=span.metrics.get("unit.tokens.completion", 0.0),
1290
+ call_type=span.node.type.name.lower(),
1291
+ response_time_ms=span.time.span // 1_000,
1292
+ )
1293
+
1294
+ if not costs:
1295
+ continue
1296
+
1297
+ prompt_cost, completion_cost = costs
1298
+ total_cost = prompt_cost + completion_cost
1299
+
1300
+ span.metrics["unit.costs.prompt"] = prompt_cost
1301
+ span.metrics["unit.costs.completion"] = completion_cost
1302
+ span.metrics["unit.costs.total"] = total_cost
1303
+
1304
+ except:
1305
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agenta
3
- Version: 0.25.4a1
3
+ Version: 0.25.4a3
4
4
  Summary: The SDK for agenta is an open-source LLMOps platform.
5
5
  Home-page: https://agenta.ai
6
6
  Keywords: LLMOps,LLM,evaluation,prompt engineering
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
17
18
  Classifier: Topic :: Software Development :: Libraries
18
19
  Requires-Dist: cachetools (>=5.3.3,<6.0.0)
19
20
  Requires-Dist: click (>=8.1.3,<9.0.0)
@@ -22,6 +23,7 @@ Requires-Dist: fastapi (>=0.100.0)
22
23
  Requires-Dist: httpx (>=0.24,<0.28)
23
24
  Requires-Dist: importlib-metadata (>=8.0.0,<9.0)
24
25
  Requires-Dist: ipdb (>=0.13)
26
+ Requires-Dist: litellm (>=1.48.0,<2.0.0)
25
27
  Requires-Dist: opentelemetry-api (>=1.27.0,<2.0.0)
26
28
  Requires-Dist: opentelemetry-exporter-otlp (>=1.27.0,<2.0.0)
27
29
  Requires-Dist: opentelemetry-sdk (>=1.27.0,<2.0.0)
@@ -141,17 +141,17 @@ agenta/sdk/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
141
141
  agenta/sdk/context/routing.py,sha256=gOoOM88hSjIjzQ3ni68TjUoq7WtwSH3kB07YjCYvW2c,631
142
142
  agenta/sdk/context/tracing.py,sha256=UmmW15UFFsvxS0myS6aD9wBk5iNepNlQi4tEQ_ejfYM,96
143
143
  agenta/sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
144
- agenta/sdk/decorators/routing.py,sha256=iEHHCuMj38UZ49QWlt4j6LSmFNJWq4Um2j37OBTCLzM,35465
144
+ agenta/sdk/decorators/routing.py,sha256=4vJsFwyXUx1cuzILVOzELDfv17QnYTXpIE2NwFnC__I,35427
145
145
  agenta/sdk/decorators/tracing.py,sha256=atMLiRpQCFSAVK-rPlN781DUq7gARe0XgJJHBKqBAUc,11657
146
146
  agenta/sdk/litellm/__init__.py,sha256=Bpz1gfHQc0MN1yolWcjifLWznv6GjHggvRGQSpxpihM,37
147
- agenta/sdk/litellm/litellm.py,sha256=klT72xYw3oSvdq5ZHkig2V2oVsqKI3JEHkgLAihQEwc,8235
147
+ agenta/sdk/litellm/litellm.py,sha256=j4WyRTQdxLkvelaPm5BfUbaUxkbQXDhyr3yp9yXo1RQ,8289
148
148
  agenta/sdk/router.py,sha256=mOguvtOwl2wmyAgOuWTsf98pQwpNiUILKIo67W_hR3A,119
149
149
  agenta/sdk/tracing/__init__.py,sha256=rQNe5-zT5Kt7_CDhq-lnUIi1EYTBVzVf_MbfcIxVD98,41
150
150
  agenta/sdk/tracing/attributes.py,sha256=0Ld0A4eL6EAWwbhBY0Qp7MLWXXbBsd8EDtbBuwIy1PI,4775
151
151
  agenta/sdk/tracing/context.py,sha256=KDQYjRcmbpb6e0xEuX-bAQGhEjwx4H2nwybRPOKCDjo,578
152
152
  agenta/sdk/tracing/conventions.py,sha256=YFkKPls77sl5YOXrRjfn4erEjczMXThc7b-rRaVVTuo,722
153
153
  agenta/sdk/tracing/exporters.py,sha256=e-SfpN8dKQ0vuBZQTZ6qgIMBhyriOrVeLYJkv-us0Zs,1328
154
- agenta/sdk/tracing/inline.py,sha256=dtE-1GyEgoC1uiYIWtgUuzsjN10mUB6iQ3SrlT8082w,34605
154
+ agenta/sdk/tracing/inline.py,sha256=o-lRHmcIXVrFLWIj-xeY9LNbkuR8G4IUubwlWVfNC30,35769
155
155
  agenta/sdk/tracing/processors.py,sha256=PRQpj8aOmOjvf71M48AtCurIxVFg2ZZWRtJLtlB4xyE,1974
156
156
  agenta/sdk/tracing/spans.py,sha256=AnQuuyuCGST6n_He4SF5WdrtMts9JlE8v6rVRdm2rRg,3570
157
157
  agenta/sdk/tracing/tracing.py,sha256=5r0whzLzF2bwYKZkUN3QDjq8AketEb-9sM4nqnO9zzM,5168
@@ -179,7 +179,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
179
179
  agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
180
180
  agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
181
181
  agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
182
- agenta-0.25.4a1.dist-info/METADATA,sha256=Ele35Ur00s6c2VEjluz8LFm79r-QO11K7819WuaP0Gg,31646
183
- agenta-0.25.4a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
184
- agenta-0.25.4a1.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
185
- agenta-0.25.4a1.dist-info/RECORD,,
182
+ agenta-0.25.4a3.dist-info/METADATA,sha256=Ve2s3ouTz56d41dEWduIVk06vpAUxFxvq_lqU_0OLSs,31738
183
+ agenta-0.25.4a3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
184
+ agenta-0.25.4a3.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
185
+ agenta-0.25.4a3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any