agenta 0.27.7a2__py3-none-any.whl → 0.27.8a2__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.

@@ -26,7 +26,6 @@ class EvaluationsClient:
26
26
  def fetch_evaluation_ids(
27
27
  self,
28
28
  *,
29
- app_id: str,
30
29
  resource_type: str,
31
30
  resource_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
32
31
  request_options: typing.Optional[RequestOptions] = None,
@@ -35,7 +34,6 @@ class EvaluationsClient:
35
34
  Fetches evaluation ids for a given resource type and id.
36
35
 
37
36
  Arguments:
38
- app_id (str): The ID of the app for which to fetch evaluations.
39
37
  resource_type (str): The type of resource for which to fetch evaluations.
40
38
  resource_ids List[ObjectId]: The IDs of resource for which to fetch evaluations.
41
39
 
@@ -47,8 +45,6 @@ class EvaluationsClient:
47
45
 
48
46
  Parameters
49
47
  ----------
50
- app_id : str
51
-
52
48
  resource_type : str
53
49
 
54
50
  resource_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
@@ -70,7 +66,6 @@ class EvaluationsClient:
70
66
  base_url="https://yourhost.com/path/to/api",
71
67
  )
72
68
  client.evaluations.fetch_evaluation_ids(
73
- app_id="app_id",
74
69
  resource_type="resource_type",
75
70
  )
76
71
  """
@@ -78,7 +73,6 @@ class EvaluationsClient:
78
73
  "evaluations/by_resource",
79
74
  method="GET",
80
75
  params={
81
- "app_id": app_id,
82
76
  "resource_type": resource_type,
83
77
  "resource_ids": resource_ids,
84
78
  },
@@ -714,7 +708,6 @@ class AsyncEvaluationsClient:
714
708
  async def fetch_evaluation_ids(
715
709
  self,
716
710
  *,
717
- app_id: str,
718
711
  resource_type: str,
719
712
  resource_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
720
713
  request_options: typing.Optional[RequestOptions] = None,
@@ -723,7 +716,6 @@ class AsyncEvaluationsClient:
723
716
  Fetches evaluation ids for a given resource type and id.
724
717
 
725
718
  Arguments:
726
- app_id (str): The ID of the app for which to fetch evaluations.
727
719
  resource_type (str): The type of resource for which to fetch evaluations.
728
720
  resource_ids List[ObjectId]: The IDs of resource for which to fetch evaluations.
729
721
 
@@ -735,7 +727,6 @@ class AsyncEvaluationsClient:
735
727
 
736
728
  Parameters
737
729
  ----------
738
- app_id : str
739
730
 
740
731
  resource_type : str
741
732
 
@@ -763,7 +754,6 @@ class AsyncEvaluationsClient:
763
754
 
764
755
  async def main() -> None:
765
756
  await client.evaluations.fetch_evaluation_ids(
766
- app_id="app_id",
767
757
  resource_type="resource_type",
768
758
  )
769
759
 
@@ -774,7 +764,6 @@ class AsyncEvaluationsClient:
774
764
  "evaluations/by_resource",
775
765
  method="GET",
776
766
  params={
777
- "app_id": app_id,
778
767
  "resource_type": resource_type,
779
768
  "resource_ids": resource_ids,
780
769
  },
@@ -28,7 +28,6 @@ class TestsetsClient:
28
28
  file: core.File,
29
29
  upload_type: typing.Optional[str] = OMIT,
30
30
  testset_name: typing.Optional[str] = OMIT,
31
- app_id: typing.Optional[str] = OMIT,
32
31
  request_options: typing.Optional[RequestOptions] = None,
33
32
  ) -> TestSetSimpleResponse:
34
33
  """
@@ -51,8 +50,6 @@ class TestsetsClient:
51
50
 
52
51
  testset_name : typing.Optional[str]
53
52
 
54
- app_id : typing.Optional[str]
55
-
56
53
  request_options : typing.Optional[RequestOptions]
57
54
  Request-specific configuration.
58
55
 
@@ -77,7 +74,6 @@ class TestsetsClient:
77
74
  data={
78
75
  "upload_type": upload_type,
79
76
  "testset_name": testset_name,
80
- "app_id": app_id,
81
77
  },
82
78
  files={
83
79
  "file": file,
@@ -173,18 +169,16 @@ class TestsetsClient:
173
169
 
174
170
  def create_testset(
175
171
  self,
176
- app_id: str,
177
172
  *,
178
173
  name: str,
179
174
  csvdata: typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]],
180
175
  request_options: typing.Optional[RequestOptions] = None,
181
176
  ) -> TestSetSimpleResponse:
182
177
  """
183
- Create a testset with given name and app_name, save the testset to MongoDB.
178
+ Create a testset with given name, save the testset to MongoDB.
184
179
 
185
180
  Args:
186
181
  name (str): name of the test set.
187
- app_name (str): name of the application.
188
182
  testset (Dict[str, str]): test set data.
189
183
 
190
184
  Returns:
@@ -192,8 +186,6 @@ class TestsetsClient:
192
186
 
193
187
  Parameters
194
188
  ----------
195
- app_id : str
196
-
197
189
  name : str
198
190
 
199
191
  csvdata : typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]]
@@ -215,13 +207,12 @@ class TestsetsClient:
215
207
  base_url="https://yourhost.com/path/to/api",
216
208
  )
217
209
  client.testsets.create_testset(
218
- app_id="app_id",
219
210
  name="name",
220
211
  csvdata=[{"key": "value"}],
221
212
  )
222
213
  """
223
214
  _response = self._client_wrapper.httpx_client.request(
224
- f"testsets/{jsonable_encoder(app_id)}",
215
+ "testsets",
225
216
  method="POST",
226
217
  json={
227
218
  "name": name,
@@ -405,7 +396,7 @@ class TestsetsClient:
405
396
  raise ApiError(status_code=_response.status_code, body=_response_json)
406
397
 
407
398
  def get_testsets(
408
- self, *, app_id: str, request_options: typing.Optional[RequestOptions] = None
399
+ self, *, request_options: typing.Optional[RequestOptions] = None
409
400
  ) -> typing.List[TestSetOutputResponse]:
410
401
  """
411
402
  Get all testsets.
@@ -420,8 +411,6 @@ class TestsetsClient:
420
411
 
421
412
  Parameters
422
413
  ----------
423
- app_id : str
424
-
425
414
  request_options : typing.Optional[RequestOptions]
426
415
  Request-specific configuration.
427
416
 
@@ -438,16 +427,11 @@ class TestsetsClient:
438
427
  api_key="YOUR_API_KEY",
439
428
  base_url="https://yourhost.com/path/to/api",
440
429
  )
441
- client.testsets.get_testsets(
442
- app_id="app_id",
443
- )
430
+ client.testsets.get_testsets()
444
431
  """
445
432
  _response = self._client_wrapper.httpx_client.request(
446
433
  "testsets",
447
434
  method="GET",
448
- params={
449
- "app_id": app_id,
450
- },
451
435
  request_options=request_options,
452
436
  )
453
437
  try:
@@ -557,7 +541,6 @@ class AsyncTestsetsClient:
557
541
  file: core.File,
558
542
  upload_type: typing.Optional[str] = OMIT,
559
543
  testset_name: typing.Optional[str] = OMIT,
560
- app_id: typing.Optional[str] = OMIT,
561
544
  request_options: typing.Optional[RequestOptions] = None,
562
545
  ) -> TestSetSimpleResponse:
563
546
  """
@@ -580,8 +563,6 @@ class AsyncTestsetsClient:
580
563
 
581
564
  testset_name : typing.Optional[str]
582
565
 
583
- app_id : typing.Optional[str]
584
-
585
566
  request_options : typing.Optional[RequestOptions]
586
567
  Request-specific configuration.
587
568
 
@@ -614,7 +595,6 @@ class AsyncTestsetsClient:
614
595
  data={
615
596
  "upload_type": upload_type,
616
597
  "testset_name": testset_name,
617
- "app_id": app_id,
618
598
  },
619
599
  files={
620
600
  "file": file,
@@ -718,18 +698,16 @@ class AsyncTestsetsClient:
718
698
 
719
699
  async def create_testset(
720
700
  self,
721
- app_id: str,
722
701
  *,
723
702
  name: str,
724
703
  csvdata: typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]],
725
704
  request_options: typing.Optional[RequestOptions] = None,
726
705
  ) -> TestSetSimpleResponse:
727
706
  """
728
- Create a testset with given name and app_name, save the testset to MongoDB.
707
+ Create a testset with given name, save the testset to MongoDB.
729
708
 
730
709
  Args:
731
710
  name (str): name of the test set.
732
- app_name (str): name of the application.
733
711
  testset (Dict[str, str]): test set data.
734
712
 
735
713
  Returns:
@@ -737,8 +715,6 @@ class AsyncTestsetsClient:
737
715
 
738
716
  Parameters
739
717
  ----------
740
- app_id : str
741
-
742
718
  name : str
743
719
 
744
720
  csvdata : typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]]
@@ -765,7 +741,6 @@ class AsyncTestsetsClient:
765
741
 
766
742
  async def main() -> None:
767
743
  await client.testsets.create_testset(
768
- app_id="app_id",
769
744
  name="name",
770
745
  csvdata=[{"key": "value"}],
771
746
  )
@@ -774,7 +749,7 @@ class AsyncTestsetsClient:
774
749
  asyncio.run(main())
775
750
  """
776
751
  _response = await self._client_wrapper.httpx_client.request(
777
- f"testsets/{jsonable_encoder(app_id)}",
752
+ "testsets",
778
753
  method="POST",
779
754
  json={
780
755
  "name": name,
@@ -974,7 +949,7 @@ class AsyncTestsetsClient:
974
949
  raise ApiError(status_code=_response.status_code, body=_response_json)
975
950
 
976
951
  async def get_testsets(
977
- self, *, app_id: str, request_options: typing.Optional[RequestOptions] = None
952
+ self, *, request_options: typing.Optional[RequestOptions] = None
978
953
  ) -> typing.List[TestSetOutputResponse]:
979
954
  """
980
955
  Get all testsets.
@@ -989,8 +964,6 @@ class AsyncTestsetsClient:
989
964
 
990
965
  Parameters
991
966
  ----------
992
- app_id : str
993
-
994
967
  request_options : typing.Optional[RequestOptions]
995
968
  Request-specific configuration.
996
969
 
@@ -1012,9 +985,7 @@ class AsyncTestsetsClient:
1012
985
 
1013
986
 
1014
987
  async def main() -> None:
1015
- await client.testsets.get_testsets(
1016
- app_id="app_id",
1017
- )
988
+ await client.testsets.get_testsets()
1018
989
 
1019
990
 
1020
991
  asyncio.run(main())
@@ -1022,9 +993,6 @@ class AsyncTestsetsClient:
1022
993
  _response = await self._client_wrapper.httpx_client.request(
1023
994
  "testsets",
1024
995
  method="GET",
1025
- params={
1026
- "app_id": app_id,
1027
- },
1028
996
  request_options=request_options,
1029
997
  )
1030
998
  try:
agenta/sdk/agenta_init.py CHANGED
@@ -1,4 +1,3 @@
1
- import logging
2
1
  import toml
3
2
  from os import getenv
4
3
  from typing import Optional, Callable, Any
@@ -11,10 +10,6 @@ from agenta.sdk.tracing import Tracing
11
10
  from agenta.client.exceptions import APIRequestError
12
11
 
13
12
 
14
- logger = logging.getLogger(__name__)
15
- logger.setLevel(logging.DEBUG)
16
-
17
-
18
13
  class AgentaSingleton:
19
14
  """Singleton class to save all the "global variables" for the sdk."""
20
15
 
@@ -164,7 +159,7 @@ class Config:
164
159
  try:
165
160
  self.push(config_name="default", overwrite=overwrite, **kwargs)
166
161
  except Exception as ex:
167
- logger.warning(
162
+ log.warning(
168
163
  "Unable to push the default configuration to the server. %s", str(ex)
169
164
  )
170
165
 
@@ -185,7 +180,7 @@ class Config:
185
180
  overwrite=overwrite,
186
181
  )
187
182
  except Exception as ex:
188
- logger.warning(
183
+ log.warning(
189
184
  "Failed to push the configuration to the server with error: %s", ex
190
185
  )
191
186
 
@@ -212,14 +207,14 @@ class Config:
212
207
  config_name=config_name,
213
208
  )
214
209
  except Exception as ex:
215
- logger.warning(
210
+ log.warning(
216
211
  "Failed to pull the configuration from the server with error: %s",
217
212
  str(ex),
218
213
  )
219
214
  try:
220
215
  self.set(**{"current_version": config.current_version, **config.parameters})
221
216
  except Exception as ex:
222
- logger.warning("Failed to set the configuration with error: %s", str(ex))
217
+ log.warning("Failed to set the configuration with error: %s", str(ex))
223
218
 
224
219
  def all(self):
225
220
  """Returns all the parameters for the app variant"""
@@ -143,9 +143,7 @@ class entrypoint:
143
143
  _MIDDLEWARES = False
144
144
 
145
145
  except: # pylint: disable=bare-except
146
- log.error("------------------------------------")
147
- log.error("Agenta SDK - failed to secure route: %s", route_path)
148
- log.error("------------------------------------")
146
+ log.warning("Agenta SDK - failed to secure route: %s", route_path)
149
147
  ### --- Update Middleware --- #
150
148
 
151
149
  DEFAULT_PATH = "generate"
@@ -357,9 +355,7 @@ class entrypoint:
357
355
  *args,
358
356
  **func_params,
359
357
  ):
360
- log.info("---------------------------")
361
- log.info(f"Agenta SDK - running route: {repr(self.route_path or '/')}")
362
- log.info("---------------------------")
358
+ log.info("Agenta SDK - handling route: %s", repr(self.route_path or "/"))
363
359
 
364
360
  tracing_context.set(routing_context.get())
365
361
 
@@ -377,7 +373,7 @@ class entrypoint:
377
373
 
378
374
  async def handle_success(self, result: Any, inline_trace: bool):
379
375
  data = None
380
- trace = dict()
376
+ trace = None
381
377
 
382
378
  with suppress():
383
379
  data = self.patch_result(result)
@@ -392,21 +388,17 @@ class entrypoint:
392
388
  return BaseResponse(data=data, tree=trace)
393
389
 
394
390
  def handle_failure(self, error: Exception):
395
- log.error("--------------------------------------------------")
396
- log.error("Agenta SDK - handling application exception below:")
397
- log.error("--------------------------------------------------")
398
- log.error(format_exc().strip("\n"))
399
- log.error("--------------------------------------------------")
391
+ log.warning("--------------------------------------------------")
392
+ log.warning("Agenta SDK - handling application exception below:")
393
+ log.warning("--------------------------------------------------")
394
+ log.warning(format_exc().strip("\n"))
395
+ log.warning("--------------------------------------------------")
400
396
 
401
397
  status_code = error.status_code if hasattr(error, "status_code") else 500
402
398
  message = str(error)
403
399
  stacktrace = format_exception(error, value=error, tb=error.__traceback__) # type: ignore
404
400
  detail = {"message": message, "stacktrace": stacktrace}
405
401
 
406
- log.error(f"----------------------------------")
407
- log.error(f"Agenta SDK - exiting with failure: {status_code}")
408
- log.error(f"----------------------------------")
409
-
410
402
  raise HTTPException(status_code=status_code, detail=detail)
411
403
 
412
404
  def patch_result(self, result: Any):
@@ -683,10 +675,7 @@ class entrypoint:
683
675
 
684
676
  loop = get_event_loop()
685
677
 
686
- with routing_context_manager(
687
- config=args_config_params,
688
- environment="terminal",
689
- ):
678
+ with routing_context_manager(config=args_config_params):
690
679
  result = loop.run_until_complete(
691
680
  self.execute_function(
692
681
  func,
@@ -695,30 +684,23 @@ class entrypoint:
695
684
  )
696
685
  )
697
686
 
698
- SHOW_DETAILS = True
699
- SHOW_DATA = False
700
- SHOW_TRACE = False
701
-
702
687
  if result.trace:
703
688
  log.info("\n========= Result =========\n")
704
689
 
705
690
  log.info(f"trace_id: {result.trace['trace_id']}")
706
- if SHOW_DETAILS:
707
- log.info(f"latency: {result.trace.get('latency')}")
708
- log.info(f"cost: {result.trace.get('cost')}")
709
- log.info(f"usage: {list(result.trace.get('usage', {}).values())}")
710
-
711
- if SHOW_DATA:
712
- log.info(" ")
713
- log.info(f"data:")
714
- log.info(dumps(result.data, indent=2))
715
-
716
- if SHOW_TRACE:
717
- log.info(" ")
718
- log.info(f"trace:")
719
- log.info(f"----------------")
720
- log.info(dumps(result.trace.get("spans", []), indent=2))
721
- log.info(f"----------------")
691
+ log.info(f"latency: {result.trace.get('latency')}")
692
+ log.info(f"cost: {result.trace.get('cost')}")
693
+ log.info(f"usage: {list(result.trace.get('usage', {}).values())}")
694
+
695
+ log.info(" ")
696
+ log.info("data:")
697
+ log.info(dumps(result.data, indent=2))
698
+
699
+ log.info(" ")
700
+ log.info("trace:")
701
+ log.info("----------------")
702
+ log.info(dumps(result.trace.get("spans", []), indent=2))
703
+ log.info("----------------")
722
704
 
723
705
  log.info("\n==========================\n")
724
706
 
@@ -60,7 +60,11 @@ def litellm_handler():
60
60
  )
61
61
 
62
62
  if not self.span:
63
- log.error("LiteLLM callback error: span not found.")
63
+ log.warning("Agenta SDK - litellm tracing failed")
64
+ return
65
+
66
+ if not self.span.is_recording():
67
+ log.error("Agenta SDK - litellm span not recording.")
64
68
  return
65
69
 
66
70
  self.span.set_attributes(
@@ -86,43 +90,11 @@ def litellm_handler():
86
90
  end_time,
87
91
  ):
88
92
  if not self.span:
89
- log.error("LiteLLM callback error: span not found.")
93
+ log.warning("Agenta SDK - litellm tracing failed")
90
94
  return
91
95
 
92
- try:
93
- result = []
94
- for choice in response_obj.choices:
95
- message = choice.message.__dict__
96
- result.append(message)
97
-
98
- outputs = {"completion": result}
99
- self.span.set_attributes(
100
- attributes={"outputs": outputs},
101
- namespace="data",
102
- )
103
-
104
- except Exception as e:
105
- pass
106
-
107
- self.span.set_attributes(
108
- attributes={"total": kwargs.get("response_cost")},
109
- namespace="metrics.unit.costs",
110
- )
111
-
112
- self.span.set_attributes(
113
- attributes=(
114
- {
115
- "prompt": response_obj.usage.prompt_tokens,
116
- "completion": response_obj.usage.completion_tokens,
117
- "total": response_obj.usage.total_tokens,
118
- }
119
- ),
120
- namespace="metrics.unit.tokens",
121
- )
122
-
123
- self.span.set_status(status="OK")
124
-
125
- self.span.end()
96
+ if not self.span.is_recording():
97
+ return
126
98
 
127
99
  def log_success_event(
128
100
  self,
@@ -131,8 +103,14 @@ def litellm_handler():
131
103
  start_time,
132
104
  end_time,
133
105
  ):
106
+ if kwargs.get("stream"):
107
+ return
108
+
134
109
  if not self.span:
135
- log.error("LiteLLM callback error: span not found.")
110
+ log.warning("Agenta SDK - litellm tracing failed")
111
+ return
112
+
113
+ if not self.span.is_recording():
136
114
  return
137
115
 
138
116
  try:
@@ -178,7 +156,10 @@ def litellm_handler():
178
156
  end_time,
179
157
  ):
180
158
  if not self.span:
181
- log.error("LiteLLM callback error: span not found.")
159
+ log.warning("Agenta SDK - litellm tracing failed")
160
+ return
161
+
162
+ if not self.span.is_recording():
182
163
  return
183
164
 
184
165
  self.span.record_exception(kwargs["exception"])
@@ -195,43 +176,11 @@ def litellm_handler():
195
176
  end_time,
196
177
  ):
197
178
  if not self.span:
198
- log.error("LiteLLM callback error: span not found.")
179
+ log.warning("Agenta SDK - litellm tracing failed")
199
180
  return
200
181
 
201
- try:
202
- result = []
203
- for choice in response_obj.choices:
204
- message = choice.message.__dict__
205
- result.append(message)
206
-
207
- outputs = {"completion": result}
208
- self.span.set_attributes(
209
- attributes={"outputs": outputs},
210
- namespace="data",
211
- )
212
-
213
- except Exception as e:
214
- pass
215
-
216
- self.span.set_attributes(
217
- attributes={"total": kwargs.get("response_cost")},
218
- namespace="metrics.unit.costs",
219
- )
220
-
221
- self.span.set_attributes(
222
- attributes=(
223
- {
224
- "prompt": response_obj.usage.prompt_tokens,
225
- "completion": response_obj.usage.completion_tokens,
226
- "total": response_obj.usage.total_tokens,
227
- }
228
- ),
229
- namespace="metrics.unit.tokens",
230
- )
231
-
232
- self.span.set_status(status="OK")
233
-
234
- self.span.end()
182
+ if not self.span.is_recording():
183
+ return
235
184
 
236
185
  async def async_log_success_event(
237
186
  self,
@@ -241,7 +190,10 @@ def litellm_handler():
241
190
  end_time,
242
191
  ):
243
192
  if not self.span:
244
- log.error("LiteLLM callback error: span not found.")
193
+ log.warning("Agenta SDK - litellm tracing failed")
194
+ return
195
+
196
+ if not self.span.is_recording():
245
197
  return
246
198
 
247
199
  try:
@@ -287,7 +239,10 @@ def litellm_handler():
287
239
  end_time,
288
240
  ):
289
241
  if not self.span:
290
- log.error("LiteLLM callback error: span not found.")
242
+ log.warning("Agenta SDK - litellm tracing failed")
243
+ return
244
+
245
+ if not self.span.is_recording():
291
246
  return
292
247
 
293
248
  self.span.record_exception(kwargs["exception"])
@@ -133,10 +133,10 @@ class AuthorizationMiddleware(BaseHTTPMiddleware):
133
133
  return await call_next(request)
134
134
 
135
135
  except: # pylint: disable=bare-except
136
- log.error("------------------------------------------------------")
137
- log.error("Agenta SDK - handling auth middleware exception below:")
138
- log.error("------------------------------------------------------")
139
- log.error(format_exc().strip("\n"))
140
- log.error("------------------------------------------------------")
136
+ log.warning("------------------------------------------------------")
137
+ log.warning("Agenta SDK - handling auth middleware exception below:")
138
+ log.warning("------------------------------------------------------")
139
+ log.warning(format_exc().strip("\n"))
140
+ log.warning("------------------------------------------------------")
141
141
 
142
142
  return Deny()
@@ -14,11 +14,11 @@ def tracing_context_manager():
14
14
  token = tracing_context.set(_tracing_context)
15
15
  try:
16
16
  yield
17
- except Exception as e:
18
- log.error("----------------------------------------------")
19
- log.error("Agenta SDK - handling tracing exception below:")
20
- log.error("----------------------------------------------")
21
- log.error(format_exc().strip("\n"))
22
- log.error("----------------------------------------------")
17
+ except: # pylint: disable=bare-except
18
+ log.warning("----------------------------------------------")
19
+ log.warning("Agenta SDK - handling tracing exception below:")
20
+ log.warning("----------------------------------------------")
21
+ log.warning(format_exc().strip("\n"))
22
+ log.warning("----------------------------------------------")
23
23
  finally:
24
24
  tracing_context.reset(token)
@@ -1118,13 +1118,15 @@ def calculate_costs(span_idx: Dict[str, SpanDTO]):
1118
1118
  and span.meta
1119
1119
  and span.metrics
1120
1120
  ):
1121
+ model = span.meta.get("response.model")
1122
+ prompt_tokens = span.metrics.get("unit.tokens.prompt", 0.0)
1123
+ completion_tokens = span.metrics.get("unit.tokens.completion", 0.0)
1124
+
1121
1125
  try:
1122
1126
  costs = cost_calculator.cost_per_token(
1123
- model=span.meta.get("response.model"),
1124
- prompt_tokens=span.metrics.get("unit.tokens.prompt", 0.0),
1125
- completion_tokens=span.metrics.get("unit.tokens.completion", 0.0),
1126
- call_type=span.node.type.name.lower(),
1127
- response_time_ms=span.time.span // 1_000,
1127
+ model=model,
1128
+ prompt_tokens=prompt_tokens,
1129
+ completion_tokens=completion_tokens,
1128
1130
  )
1129
1131
 
1130
1132
  if not costs:
@@ -1137,5 +1139,8 @@ def calculate_costs(span_idx: Dict[str, SpanDTO]):
1137
1139
  span.metrics["unit.costs.completion"] = completion_cost
1138
1140
  span.metrics["unit.costs.total"] = total_cost
1139
1141
 
1140
- except:
1141
- pass
1142
+ except: # pylint: disable=bare-except
1143
+ print("Failed to calculate costs:")
1144
+ print(
1145
+ f"model={model}, prompt_tokens={prompt_tokens}, completion_tokens={completion_tokens}"
1146
+ )
@@ -91,9 +91,7 @@ class TraceProcessor(BatchSpanProcessor):
91
91
  ret = super().force_flush(timeout_millis)
92
92
 
93
93
  if not ret:
94
- log.error("--------------------------------------------")
95
- log.error("Agenta SDK - skipping export due to timeout.")
96
- log.error("--------------------------------------------")
94
+ log.warning("Agenta SDK - skipping export due to timeout.")
97
95
 
98
96
  def is_ready(
99
97
  self,
@@ -90,7 +90,6 @@ class Tracing(metaclass=Singleton):
90
90
  self.otlp_url,
91
91
  )
92
92
  log.info("--------------------------------------------")
93
-
94
93
  check(
95
94
  self.otlp_url,
96
95
  headers=self.headers,
@@ -106,13 +105,10 @@ class Tracing(metaclass=Singleton):
106
105
  )
107
106
 
108
107
  self.tracer_provider.add_span_processor(_otlp)
109
-
110
108
  log.info("Success: traces will be exported.")
111
109
  log.info("--------------------------------------------")
112
-
113
110
  except: # pylint: disable=bare-except
114
- log.warning("Failure: traces will not be exported.")
115
- log.warning("--------------------------------------------")
111
+ log.warning("Agenta SDK - traces will not be exported.")
116
112
 
117
113
  # GLOBAL TRACER PROVIDER -- INSTRUMENTATION LIBRARIES
118
114
  set_tracer_provider(self.tracer_provider)
@@ -17,11 +17,11 @@ class suppress(AbstractContextManager): # pylint: disable=invalid-name
17
17
  if exc_type is None:
18
18
  return True
19
19
  else:
20
- log.error("-------------------------------------------------")
21
- log.error("Agenta SDK - suppressing tracing exception below:")
22
- log.error("-------------------------------------------------")
23
- log.error(format_exc().strip("\n"))
24
- log.error("-------------------------------------------------")
20
+ log.warning("-------------------------------------------------")
21
+ log.warning("Agenta SDK - suppressing tracing exception below:")
22
+ log.warning("-------------------------------------------------")
23
+ log.warning(format_exc().strip("\n"))
24
+ log.warning("-------------------------------------------------")
25
25
  return True
26
26
 
27
27
 
@@ -34,8 +34,11 @@ def handle_exceptions():
34
34
  try:
35
35
  return await func(*args, **kwargs)
36
36
  except Exception as e:
37
- log.error("--- HANDLING EXCEPTION ---")
38
- log.error("--------------------------")
37
+ log.warning("------------------------------------------")
38
+ log.warning("Agenta SDK - intercepting exception below:")
39
+ log.warning("------------------------------------------")
40
+ log.warning(format_exc().strip("\n"))
41
+ log.warning("------------------------------------------")
39
42
  raise e
40
43
 
41
44
  @wraps(func)
@@ -43,8 +46,11 @@ def handle_exceptions():
43
46
  try:
44
47
  return func(*args, **kwargs)
45
48
  except Exception as e:
46
- log.error("--- HANDLING EXCEPTION ---")
47
- log.error("--------------------------")
49
+ log.warning("------------------------------------------")
50
+ log.warning("Agenta SDK - intercepting exception below:")
51
+ log.warning("------------------------------------------")
52
+ log.warning(format_exc().strip("\n"))
53
+ log.warning("------------------------------------------")
48
54
  raise e
49
55
 
50
56
  return async_wrapper if is_coroutine_function else sync_wrapper
@@ -1,8 +1,12 @@
1
1
  import logging
2
+ from os import getenv
2
3
 
3
4
 
4
5
  class Logger:
5
- def __init__(self, name="agenta.logger", level=logging.DEBUG):
6
+ def __init__(self, name="agenta.logger", level=logging.WARNING):
7
+ if getenv("AGENTA_DEBUG"):
8
+ level = logging.DEBUG
9
+
6
10
  self.logger = logging.getLogger(name)
7
11
  self.logger.setLevel(level)
8
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agenta
3
- Version: 0.27.7a2
3
+ Version: 0.27.8a2
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
@@ -38,7 +38,7 @@ agenta/client/backend/environments/client.py,sha256=JG980MafNEcMX60gCtLdPQb8Ja6R
38
38
  agenta/client/backend/errors/__init__.py,sha256=pbbVUFtB9LCocA1RMWMMF_RKjsy5YkOKX5BAuE49w6g,170
39
39
  agenta/client/backend/errors/unprocessable_entity_error.py,sha256=FvR7XPlV3Xx5nu8HNlmLhBRdk4so_gCHjYT5PyZe6sM,313
40
40
  agenta/client/backend/evaluations/__init__.py,sha256=9mUnTDeA1TxYvkj1l01A1prqsJV0ERRY2tzkY1fA4MQ,64
41
- agenta/client/backend/evaluations/client.py,sha256=T7sDKXeuiihQqxW_TIGrcSShCxduZ2QqjK80nTbTg0w,46698
41
+ agenta/client/backend/evaluations/client.py,sha256=GgBq5iXFR89VMt6SSbSpk6zDseR79brzVtpfJM1XxxA,46339
42
42
  agenta/client/backend/evaluators/__init__.py,sha256=9mUnTDeA1TxYvkj1l01A1prqsJV0ERRY2tzkY1fA4MQ,64
43
43
  agenta/client/backend/evaluators/client.py,sha256=fdfb0ZFLP-kI5jXr6F3O-wKWvWBGUXhqRXIoetyN-zQ,40405
44
44
  agenta/client/backend/observability/__init__.py,sha256=9mUnTDeA1TxYvkj1l01A1prqsJV0ERRY2tzkY1fA4MQ,64
@@ -49,7 +49,7 @@ agenta/client/backend/observability_v_1/types/__init__.py,sha256=vHpFg4KBBFowe8E
49
49
  agenta/client/backend/observability_v_1/types/format.py,sha256=U-b6HwkOirqvyU7WWDfXyDkYlxBV90lRe1YKds4qg_Q,157
50
50
  agenta/client/backend/observability_v_1/types/query_traces_response.py,sha256=0-4nNfKLnciOR7E1859HupWqcwunJe53OLgXRlxxeb8,452
51
51
  agenta/client/backend/testsets/__init__.py,sha256=9mUnTDeA1TxYvkj1l01A1prqsJV0ERRY2tzkY1fA4MQ,64
52
- agenta/client/backend/testsets/client.py,sha256=awjS8DjX08FnEgr6LtMHroK9ysMkLqKAZHh2_1-rldE,35201
52
+ agenta/client/backend/testsets/client.py,sha256=nmH7xcA4ByXTNHr8m24HbYGKmCdHrFOzlXRGV2QO7L0,34343
53
53
  agenta/client/backend/types/__init__.py,sha256=fjXpRS1ZZAJPTRYybJcuAMJ9JnkmmvDbghY3GGLYm34,7521
54
54
  agenta/client/backend/types/agenta_node_dto.py,sha256=DLZltD_ueVOfdiSZ1u2i3mu1C3kshxhcggQFFfybBdY,1747
55
55
  agenta/client/backend/types/agenta_node_dto_nodes_value.py,sha256=ifG7dBYLphFoCgQ70ivvDXkTSlxX8w5x_9S-Glh8FlI,180
@@ -174,42 +174,41 @@ agenta/docker/docker-assets/lambda_function.py,sha256=h4UZSSfqwpfsCgERv6frqwm_4J
174
174
  agenta/docker/docker-assets/main.py,sha256=7MI-21n81U7N7A0GxebNi0cmGWtJKcR2sPB6FcH2QfA,251
175
175
  agenta/docker/docker_utils.py,sha256=kO1q2_IR0fEAo4M-2Pt_v-zC7GxxnkLogjKFhU869Ps,3555
176
176
  agenta/sdk/__init__.py,sha256=Rz5ZqSbz5wIl-v4Jf4kkaTy6ofCYg5CcybyfgeAgaP8,1948
177
- agenta/sdk/agenta_init.py,sha256=YjJjwBUci77KTP27lZTPJMVvjmskng4CqbfQVbcMBJQ,10967
177
+ agenta/sdk/agenta_init.py,sha256=vH7FOY7XshKqHfAV7P54Owb-7E0cuxuMMCRobd1PT1U,10870
178
178
  agenta/sdk/assets.py,sha256=Zv4i8MVUSB3jMODQon1mzJtYxuntmrCNjLGk8f-2fls,2856
179
179
  agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
180
180
  agenta/sdk/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
181
181
  agenta/sdk/context/routing.py,sha256=ycUgmJZyWhL4bHjKtUSAsTlt_0Fujr_6OpoaEH1lAN0,683
182
182
  agenta/sdk/context/tracing.py,sha256=UmmW15UFFsvxS0myS6aD9wBk5iNepNlQi4tEQ_ejfYM,96
183
183
  agenta/sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
184
- agenta/sdk/decorators/routing.py,sha256=PAZ0fw8sQf5PQ_QYBWCxpqnGN9mjaydADw5MjqMchfI,37244
184
+ agenta/sdk/decorators/routing.py,sha256=zOkjs9TH7jF0DCvCjV-F9uzUPRDiHRakgS_vkpXBch4,36579
185
185
  agenta/sdk/decorators/tracing.py,sha256=vL5e6TVX6TQwO0t9raZwnzXHV3vElVT0pHS1vD-vzEo,8523
186
186
  agenta/sdk/litellm/__init__.py,sha256=Bpz1gfHQc0MN1yolWcjifLWznv6GjHggvRGQSpxpihM,37
187
- agenta/sdk/litellm/litellm.py,sha256=bzVm-388BleZ2QH_JWpfZ2fB_7-HuoSqdvLo4EDPcEM,8788
187
+ agenta/sdk/litellm/litellm.py,sha256=97eDU9MUTW6Wv2e7QYhCWLrRYwhaRqG6LVcedp3qNrk,7186
188
188
  agenta/sdk/managers/__init__.py,sha256=SN-LRwG0pRRDV3u2Q4JiiSTigN3-mYpzGNM35RzT4mc,238
189
189
  agenta/sdk/managers/config.py,sha256=AuFfHYOkmilDdcAJt2nlw_WlA3ho4Htjf29FKTZGElM,11716
190
190
  agenta/sdk/managers/deployment.py,sha256=SEokjZeh6n7HRKZ92Y0WncdG49hIFx-Z3B3HAl2kmUg,1174
191
191
  agenta/sdk/managers/shared.py,sha256=e53jckQq5PIMpjdxADOonUj7o8aGfzmSvdeH5f43rGs,21497
192
192
  agenta/sdk/managers/variant.py,sha256=A5ga3mq3b0weUTXa9HO72MGaspthGcu1uK9K5OnP738,4172
193
193
  agenta/sdk/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
194
- agenta/sdk/middleware/auth.py,sha256=EGoj45mLe2YpHbNSX6nCzxsIC2-B-S3CdlRF3DBju3I,4093
194
+ agenta/sdk/middleware/auth.py,sha256=H_UwEq5QioSkHZ3ipCtE3lrl7mxs5h9ULQvZHEtV8d4,4103
195
195
  agenta/sdk/middleware/cache.py,sha256=C_LEzFbulbCBIKtcut2T4qJzh90q4369WCsApDg3Vm0,902
196
196
  agenta/sdk/router.py,sha256=mOguvtOwl2wmyAgOuWTsf98pQwpNiUILKIo67W_hR3A,119
197
197
  agenta/sdk/tracing/__init__.py,sha256=rQNe5-zT5Kt7_CDhq-lnUIi1EYTBVzVf_MbfcIxVD98,41
198
198
  agenta/sdk/tracing/attributes.py,sha256=zh8JQZSeYCLBeIRSopKJx6QQ-WEgw08Cr64DS_WOcT8,3833
199
- agenta/sdk/tracing/context.py,sha256=PSJdhcaOXSMAuGUBySpLKPKyx8duF3TJzhUEk2ufqPc,777
199
+ agenta/sdk/tracing/context.py,sha256=IpNENDGRrXWjs-vti5XheqwybQs0QdD-ii4aK0enNrM,803
200
200
  agenta/sdk/tracing/conventions.py,sha256=JBtznBXZ3aRkGKkLl7cPwdMNh3w1G-H2Ta2YrAxbr38,950
201
201
  agenta/sdk/tracing/exporters.py,sha256=YvTke0RaxeOLqWOuhC5EFzYwFY39kcoBtDLfcyla3j4,1604
202
- agenta/sdk/tracing/inline.py,sha256=M4apMWajHQBgTQFb8ZF_wgqwboLnAOUiZnHPVL3ixFA,31197
203
- agenta/sdk/tracing/processors.py,sha256=tjoz_uXm_2yD1Ozvz_CnYnsG82R6vmnYpjMhx2ztALs,3117
202
+ agenta/sdk/tracing/inline.py,sha256=ncIvMKWpy1o-5l3i7YThj_pE3Oq6xvQfwyUfGsfUxzc,31405
203
+ agenta/sdk/tracing/processors.py,sha256=tPf3Hx1TmnWSljvX28kYFOFrp4ImIXhlwAaR39sf5qU,2979
204
204
  agenta/sdk/tracing/spans.py,sha256=nqUOjjirBxB8Eacv8Qj4Ra_6rknGi3lbJdNyKmk5ODQ,3707
205
- agenta/sdk/tracing/tracing.py,sha256=HYuGp5fQozLKWXLXonfCT8pqb7x1gwzzbZk87mfhu3Y,6983
205
+ agenta/sdk/tracing/tracing.py,sha256=RUSnQIWwfOFwhWbiyJfgC0wYtvcV1PusXTwNslV5WZo,6912
206
206
  agenta/sdk/types.py,sha256=_lGsGSEaZJrUT4cVcT3zSpgEqex2jFaPtfpFeUEetbc,7247
207
207
  agenta/sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
208
208
  agenta/sdk/utils/costs.py,sha256=i8C7ud__pThLS55XkN4YW8czXtGeXr2mx7jjcOFeiXg,5955
209
- agenta/sdk/utils/debug.py,sha256=DxiCAeXxxrcEZT2CjlNA6BMvujGP4nzQ-rfb-_mLMck,2114
210
- agenta/sdk/utils/exceptions.py,sha256=AU0csJtuzswjkr8O8K-PmuOEr0vRNymKPZVRnRR_0Ts,1646
209
+ agenta/sdk/utils/exceptions.py,sha256=UPO5aqNkpxevE7I_gW6O2B0FbtqqwgQobp5b6RQy_Ik,2132
211
210
  agenta/sdk/utils/globals.py,sha256=2HhyzWn55BbYNCZ3rT8dAxk1GGXuGQPbtq_THjaHbBw,372
212
- agenta/sdk/utils/logging.py,sha256=FKzAO5eHjR_qvpEnc4tKXUA6WftmwdwYwuJK6CbSc84,379
211
+ agenta/sdk/utils/logging.py,sha256=eFzEFuYpggfIhEKv09JZRqcDzkmZ482a_E2G-X0FK7Y,473
213
212
  agenta/sdk/utils/preinit.py,sha256=YlJL7RLfel0R7DFp-jK7OV-z4ZIQJM0oupYlk7g8b5o,1278
214
213
  agenta/sdk/utils/singleton.py,sha256=17Ph7LGnnV8HkPjImruKita2ni03Ari5jr0jqm__4sc,312
215
214
  agenta/templates/compose_email/README.md,sha256=ss7vZPpI1Hg0VmYtFliwq_r5LnqbCy_S5OQDXg8UoIA,308
@@ -227,7 +226,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
227
226
  agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
228
227
  agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
229
228
  agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
230
- agenta-0.27.7a2.dist-info/METADATA,sha256=f2CT_p3gHpLMIdNZVYH3GSWEPU2x1wf_ocqohombbOw,31619
231
- agenta-0.27.7a2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
232
- agenta-0.27.7a2.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
233
- agenta-0.27.7a2.dist-info/RECORD,,
229
+ agenta-0.27.8a2.dist-info/METADATA,sha256=fwGIpk-muffeEzl-HQyz1O3m6_bpaa0OvRR8FcmItVU,31619
230
+ agenta-0.27.8a2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
231
+ agenta-0.27.8a2.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
232
+ agenta-0.27.8a2.dist-info/RECORD,,
agenta/sdk/utils/debug.py DELETED
@@ -1,68 +0,0 @@
1
- from inspect import iscoroutinefunction
2
- from functools import wraps
3
-
4
- from agenta.sdk.utils.logging import log
5
-
6
- DEBUG = False
7
- SHIFT = 7
8
-
9
-
10
- def debug(shift=1, req=False, res=False, chars=[">", "<"]):
11
- def log_decorator(f):
12
- is_async = iscoroutinefunction(f)
13
-
14
- @wraps(f)
15
- async def async_log_wrapper(*args, **kwargs):
16
- if DEBUG:
17
- log.debug(
18
- " ".join(
19
- [
20
- chars[0] * shift + " " * (SHIFT - shift),
21
- f.__name__ + " ()",
22
- str(args) if req else "",
23
- str(kwargs) if req else "",
24
- ]
25
- )
26
- )
27
- result = await f(*args, **kwargs)
28
- if DEBUG:
29
- log.debug(
30
- " ".join(
31
- [
32
- chars[1] * shift + " " * (SHIFT - shift),
33
- f.__name__ + " <-",
34
- str(result) if res else "",
35
- ]
36
- )
37
- )
38
- return result
39
-
40
- @wraps(f)
41
- def log_wrapper(*args, **kwargs):
42
- if DEBUG:
43
- log.debug(
44
- " ".join(
45
- [
46
- chars[0] * shift + " " * (SHIFT - shift),
47
- f.__name__ + " ()",
48
- str(args) if req else "",
49
- str(kwargs) if req else "",
50
- ]
51
- )
52
- )
53
- result = f(*args, **kwargs)
54
- if DEBUG:
55
- log.debug(
56
- " ".join(
57
- [
58
- chars[1] * shift + " " * (SHIFT - shift),
59
- f.__name__ + " <-",
60
- str(result) if res else "",
61
- ]
62
- )
63
- )
64
- return result
65
-
66
- return async_log_wrapper if is_async else log_wrapper
67
-
68
- return log_decorator