agenta 0.32.0a1__py3-none-any.whl → 0.33.0a1__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.

Files changed (31) hide show
  1. agenta/client/backend/__init__.py +4 -8
  2. agenta/client/backend/apps/client.py +68 -68
  3. agenta/client/backend/bases/client.py +10 -10
  4. agenta/client/backend/client.py +96 -88
  5. agenta/client/backend/containers/client.py +70 -28
  6. agenta/client/backend/environments/client.py +8 -8
  7. agenta/client/backend/evaluations/client.py +46 -46
  8. agenta/client/backend/evaluators/client.py +32 -32
  9. agenta/client/backend/human_evaluations/__init__.py +1 -0
  10. agenta/client/backend/human_evaluations/client.py +1696 -0
  11. agenta/client/backend/testsets/client.py +28 -28
  12. agenta/client/backend/types/__init__.py +3 -7
  13. agenta/client/backend/types/{evaluation_scenario_score_update.py → delete_evaluation.py} +3 -3
  14. agenta/client/backend/variants/client.py +54 -42
  15. agenta/sdk/decorators/routing.py +32 -10
  16. agenta/sdk/decorators/tracing.py +16 -4
  17. agenta/sdk/litellm/litellm.py +44 -8
  18. agenta/sdk/litellm/mockllm.py +2 -2
  19. agenta/sdk/litellm/mocks/__init__.py +9 -3
  20. agenta/sdk/middleware/auth.py +5 -1
  21. agenta/sdk/middleware/config.py +10 -2
  22. agenta/sdk/tracing/exporters.py +0 -1
  23. agenta/sdk/tracing/inline.py +26 -30
  24. agenta/sdk/types.py +12 -9
  25. {agenta-0.32.0a1.dist-info → agenta-0.33.0a1.dist-info}/METADATA +9 -11
  26. {agenta-0.32.0a1.dist-info → agenta-0.33.0a1.dist-info}/RECORD +28 -29
  27. agenta/client/backend/types/human_evaluation_scenario_update.py +0 -30
  28. agenta/client/backend/types/human_evaluation_update.py +0 -22
  29. agenta/client/backend/types/new_human_evaluation.py +0 -27
  30. {agenta-0.32.0a1.dist-info → agenta-0.33.0a1.dist-info}/WHEEL +0 -0
  31. {agenta-0.32.0a1.dist-info → agenta-0.33.0a1.dist-info}/entry_points.txt +0 -0
@@ -31,15 +31,15 @@ class TestsetsClient:
31
31
  request_options: typing.Optional[RequestOptions] = None,
32
32
  ) -> TestSetSimpleResponse:
33
33
  """
34
- Uploads a CSV or JSON file and saves its data to MongoDB.
34
+ Uploads a CSV or JSON file and saves its data to Postgres.
35
35
 
36
36
  Args:
37
37
  upload_type : Either a json or csv file.
38
- file (UploadFile): The CSV or JSON file to upload.
39
- testset_name (Optional): the name of the testset if provided.
38
+ file (UploadFile): The CSV or JSON file to upload.
39
+ testset_name (Optional): the name of the testset if provided.
40
40
 
41
41
  Returns:
42
- dict: The result of the upload process.
42
+ dict: The result of the upload process.
43
43
 
44
44
  Parameters
45
45
  ----------
@@ -113,14 +113,14 @@ class TestsetsClient:
113
113
  request_options: typing.Optional[RequestOptions] = None,
114
114
  ) -> TestSetSimpleResponse:
115
115
  """
116
- Import JSON testset data from an endpoint and save it to MongoDB.
116
+ Import JSON testset data from an endpoint and save it to Postgres.
117
117
 
118
118
  Args:
119
- endpoint (str): An endpoint URL to import data from.
120
- testset_name (str): the name of the testset if provided.
119
+ endpoint (str): An endpoint URL to import data from.
120
+ testset_name (str): the name of the testset if provided.
121
121
 
122
122
  Returns:
123
- dict: The result of the import process.
123
+ dict: The result of the import process.
124
124
 
125
125
  Parameters
126
126
  ----------
@@ -241,7 +241,7 @@ class TestsetsClient:
241
241
  request_options: typing.Optional[RequestOptions] = None,
242
242
  ) -> TestSetSimpleResponse:
243
243
  """
244
- Create a testset with given name, save the testset to MongoDB.
244
+ Create a testset with given name, save the testset to Postgres.
245
245
 
246
246
  Args:
247
247
  name (str): name of the test set.
@@ -395,7 +395,7 @@ class TestsetsClient:
395
395
  request_options: typing.Optional[RequestOptions] = None,
396
396
  ) -> TestSetSimpleResponse:
397
397
  """
398
- Create a testset with given name, save the testset to MongoDB.
398
+ Create a testset with given name, save the testset to Postgres.
399
399
 
400
400
  Args:
401
401
  name (str): name of the test set.
@@ -475,13 +475,13 @@ class TestsetsClient:
475
475
  request_options: typing.Optional[RequestOptions] = None,
476
476
  ) -> typing.Optional[typing.Any]:
477
477
  """
478
- Fetch a specific testset in a MongoDB collection using its \_id.
478
+ Fetch a specific testset in a MongoDB collection using its _id.
479
479
 
480
480
  Args:
481
- testset_id (str): The \_id of the testset to fetch.
481
+ testset_id (str): The _id of the testset to fetch.
482
482
 
483
483
  Returns:
484
- The requested testset if found, else an HTTPException.
484
+ The requested testset if found, else an HTTPException.
485
485
 
486
486
  Parameters
487
487
  ----------
@@ -545,7 +545,7 @@ class TestsetsClient:
545
545
  request_options: typing.Optional[RequestOptions] = None,
546
546
  ) -> typing.Optional[typing.Any]:
547
547
  """
548
- Update a testset with given id, update the testset in MongoDB.
548
+ Update a testset with given id, update the testset in Postgres.
549
549
 
550
550
  Args:
551
551
  testset_id (str): id of the test set to be updated.
@@ -632,15 +632,15 @@ class AsyncTestsetsClient:
632
632
  request_options: typing.Optional[RequestOptions] = None,
633
633
  ) -> TestSetSimpleResponse:
634
634
  """
635
- Uploads a CSV or JSON file and saves its data to MongoDB.
635
+ Uploads a CSV or JSON file and saves its data to Postgres.
636
636
 
637
637
  Args:
638
638
  upload_type : Either a json or csv file.
639
- file (UploadFile): The CSV or JSON file to upload.
640
- testset_name (Optional): the name of the testset if provided.
639
+ file (UploadFile): The CSV or JSON file to upload.
640
+ testset_name (Optional): the name of the testset if provided.
641
641
 
642
642
  Returns:
643
- dict: The result of the upload process.
643
+ dict: The result of the upload process.
644
644
 
645
645
  Parameters
646
646
  ----------
@@ -722,14 +722,14 @@ class AsyncTestsetsClient:
722
722
  request_options: typing.Optional[RequestOptions] = None,
723
723
  ) -> TestSetSimpleResponse:
724
724
  """
725
- Import JSON testset data from an endpoint and save it to MongoDB.
725
+ Import JSON testset data from an endpoint and save it to Postgres.
726
726
 
727
727
  Args:
728
- endpoint (str): An endpoint URL to import data from.
729
- testset_name (str): the name of the testset if provided.
728
+ endpoint (str): An endpoint URL to import data from.
729
+ testset_name (str): the name of the testset if provided.
730
730
 
731
731
  Returns:
732
- dict: The result of the import process.
732
+ dict: The result of the import process.
733
733
 
734
734
  Parameters
735
735
  ----------
@@ -866,7 +866,7 @@ class AsyncTestsetsClient:
866
866
  request_options: typing.Optional[RequestOptions] = None,
867
867
  ) -> TestSetSimpleResponse:
868
868
  """
869
- Create a testset with given name, save the testset to MongoDB.
869
+ Create a testset with given name, save the testset to Postgres.
870
870
 
871
871
  Args:
872
872
  name (str): name of the test set.
@@ -1036,7 +1036,7 @@ class AsyncTestsetsClient:
1036
1036
  request_options: typing.Optional[RequestOptions] = None,
1037
1037
  ) -> TestSetSimpleResponse:
1038
1038
  """
1039
- Create a testset with given name, save the testset to MongoDB.
1039
+ Create a testset with given name, save the testset to Postgres.
1040
1040
 
1041
1041
  Args:
1042
1042
  name (str): name of the test set.
@@ -1124,13 +1124,13 @@ class AsyncTestsetsClient:
1124
1124
  request_options: typing.Optional[RequestOptions] = None,
1125
1125
  ) -> typing.Optional[typing.Any]:
1126
1126
  """
1127
- Fetch a specific testset in a MongoDB collection using its \_id.
1127
+ Fetch a specific testset in a MongoDB collection using its _id.
1128
1128
 
1129
1129
  Args:
1130
- testset_id (str): The \_id of the testset to fetch.
1130
+ testset_id (str): The _id of the testset to fetch.
1131
1131
 
1132
1132
  Returns:
1133
- The requested testset if found, else an HTTPException.
1133
+ The requested testset if found, else an HTTPException.
1134
1134
 
1135
1135
  Parameters
1136
1136
  ----------
@@ -1202,7 +1202,7 @@ class AsyncTestsetsClient:
1202
1202
  request_options: typing.Optional[RequestOptions] = None,
1203
1203
  ) -> typing.Optional[typing.Any]:
1204
1204
  """
1205
- Update a testset with given id, update the testset in MongoDB.
1205
+ Update a testset with given id, update the testset in Postgres.
1206
1206
 
1207
1207
  Args:
1208
1208
  testset_id (str): id of the test set to be updated.
@@ -24,6 +24,7 @@ from .correct_answer import CorrectAnswer
24
24
  from .create_app_output import CreateAppOutput
25
25
  from .create_span import CreateSpan
26
26
  from .create_trace_response import CreateTraceResponse
27
+ from .delete_evaluation import DeleteEvaluation
27
28
  from .docker_env_vars import DockerEnvVars
28
29
  from .environment_output import EnvironmentOutput
29
30
  from .environment_output_extended import EnvironmentOutputExtended
@@ -34,7 +35,6 @@ from .evaluation_scenario import EvaluationScenario
34
35
  from .evaluation_scenario_input import EvaluationScenarioInput
35
36
  from .evaluation_scenario_output import EvaluationScenarioOutput
36
37
  from .evaluation_scenario_result import EvaluationScenarioResult
37
- from .evaluation_scenario_score_update import EvaluationScenarioScoreUpdate
38
38
  from .evaluation_status_enum import EvaluationStatusEnum
39
39
  from .evaluation_type import EvaluationType
40
40
  from .evaluator import Evaluator
@@ -49,8 +49,6 @@ from .human_evaluation import HumanEvaluation
49
49
  from .human_evaluation_scenario import HumanEvaluationScenario
50
50
  from .human_evaluation_scenario_input import HumanEvaluationScenarioInput
51
51
  from .human_evaluation_scenario_output import HumanEvaluationScenarioOutput
52
- from .human_evaluation_scenario_update import HumanEvaluationScenarioUpdate
53
- from .human_evaluation_update import HumanEvaluationUpdate
54
52
  from .image import Image
55
53
  from .invite_request import InviteRequest
56
54
  from .legacy_analytics_response import LegacyAnalyticsResponse
@@ -61,10 +59,10 @@ from .list_api_keys_response import ListApiKeysResponse
61
59
  from .llm_run_rate_limit import LlmRunRateLimit
62
60
  from .llm_tokens import LlmTokens
63
61
  from .metrics_dto import MetricsDto
64
- from .new_human_evaluation import NewHumanEvaluation
65
62
  from .new_testset import NewTestset
66
63
  from .node_dto import NodeDto
67
64
  from .node_type import NodeType
65
+
68
66
  from .o_tel_context_dto import OTelContextDto
69
67
  from .o_tel_event_dto import OTelEventDto
70
68
  from .o_tel_extra_dto import OTelExtraDto
@@ -144,6 +142,7 @@ __all__ = [
144
142
  "CreateAppOutput",
145
143
  "CreateSpan",
146
144
  "CreateTraceResponse",
145
+ "DeleteEvaluation",
147
146
  "DockerEnvVars",
148
147
  "EnvironmentOutput",
149
148
  "EnvironmentOutputExtended",
@@ -154,7 +153,6 @@ __all__ = [
154
153
  "EvaluationScenarioInput",
155
154
  "EvaluationScenarioOutput",
156
155
  "EvaluationScenarioResult",
157
- "EvaluationScenarioScoreUpdate",
158
156
  "EvaluationStatusEnum",
159
157
  "EvaluationType",
160
158
  "Evaluator",
@@ -169,8 +167,6 @@ __all__ = [
169
167
  "HumanEvaluationScenario",
170
168
  "HumanEvaluationScenarioInput",
171
169
  "HumanEvaluationScenarioOutput",
172
- "HumanEvaluationScenarioUpdate",
173
- "HumanEvaluationUpdate",
174
170
  "Image",
175
171
  "InviteRequest",
176
172
  "LegacyAnalyticsResponse",
@@ -1,13 +1,13 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
3
  from ..core.pydantic_utilities import UniversalBaseModel
4
- from ..core.pydantic_utilities import IS_PYDANTIC_V2
5
4
  import typing
5
+ from ..core.pydantic_utilities import IS_PYDANTIC_V2
6
6
  import pydantic
7
7
 
8
8
 
9
- class EvaluationScenarioScoreUpdate(UniversalBaseModel):
10
- score: float
9
+ class DeleteEvaluation(UniversalBaseModel):
10
+ evaluations_ids: typing.List[str]
11
11
 
12
12
  if IS_PYDANTIC_V2:
13
13
  model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
@@ -46,14 +46,14 @@ class VariantsClient:
46
46
  Same as POST /config
47
47
 
48
48
  Args:
49
- payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
50
- stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
49
+ payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
50
+ stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
51
51
 
52
52
  Raises:
53
- HTTPException: Raised if the variant could not be added or accessed.
53
+ HTTPException: Raised if the variant could not be added or accessed.
54
54
 
55
55
  Returns:
56
- Union[AppVariantResponse, Any]: New variant details or exception.
56
+ Union[AppVariantResponse, Any]: New variant details or exception.
57
57
 
58
58
  Parameters
59
59
  ----------
@@ -199,16 +199,16 @@ class VariantsClient:
199
199
  Start a variant of an app.
200
200
 
201
201
  Args:
202
- variant_id (str): The ID of the variant to start.
203
- action (VariantAction): The action to perform on the variant (start).
204
- env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
205
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
202
+ variant_id (str): The ID of the variant to start.
203
+ action (VariantAction): The action to perform on the variant (start).
204
+ env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
205
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
206
206
 
207
207
  Returns:
208
- URI: The URL of the started variant.
208
+ URI: The URL of the started variant.
209
209
 
210
210
  Raises:
211
- HTTPException: If the app container cannot be started.
211
+ HTTPException: If the app container cannot be started.
212
212
 
213
213
  Parameters
214
214
  ----------
@@ -293,10 +293,16 @@ class VariantsClient:
293
293
  In the case it's the last variant using the image, stop the container and remove the image.
294
294
 
295
295
  Arguments:
296
- app_variant -- AppVariant to remove
296
+
297
+
298
+
299
+ app_variant -- AppVariant to remove
297
300
 
298
301
  Raises:
299
- HTTPException: If there is a problem removing the app variant
302
+
303
+
304
+
305
+ HTTPException: If there is a problem removing the app variant
300
306
 
301
307
  Parameters
302
308
  ----------
@@ -362,15 +368,15 @@ class VariantsClient:
362
368
  Updates the parameters for an app variant.
363
369
 
364
370
  Args:
365
- variant_id (str): The ID of the app variant to update.
366
- payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
367
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
371
+ variant_id (str): The ID of the app variant to update.
372
+ payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
373
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
368
374
 
369
375
  Raises:
370
- HTTPException: If there is an error while trying to update the app variant.
376
+ HTTPException: If there is an error while trying to update the app variant.
371
377
 
372
378
  Returns:
373
- JSONResponse: A JSON response containing the updated app variant parameters.
379
+ JSONResponse: A JSON response containing the updated app variant parameters.
374
380
 
375
381
  Parameters
376
382
  ----------
@@ -450,14 +456,14 @@ class VariantsClient:
450
456
  Updates the image used in an app variant.
451
457
 
452
458
  Args:
453
- variant_id (str): The ID of the app variant to update.
454
- image (Image): The image information to update.
459
+ variant_id (str): The ID of the app variant to update.
460
+ image (Image): The image information to update.
455
461
 
456
462
  Raises:
457
- HTTPException: If an error occurs while trying to update the app variant.
463
+ HTTPException: If an error occurs while trying to update the app variant.
458
464
 
459
465
  Returns:
460
- JSONResponse: A JSON response indicating whether the update was successful or not.
466
+ JSONResponse: A JSON response indicating whether the update was successful or not.
461
467
 
462
468
  Parameters
463
469
  ----------
@@ -1371,14 +1377,14 @@ class AsyncVariantsClient:
1371
1377
  Same as POST /config
1372
1378
 
1373
1379
  Args:
1374
- payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
1375
- stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
1380
+ payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
1381
+ stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
1376
1382
 
1377
1383
  Raises:
1378
- HTTPException: Raised if the variant could not be added or accessed.
1384
+ HTTPException: Raised if the variant could not be added or accessed.
1379
1385
 
1380
1386
  Returns:
1381
- Union[AppVariantResponse, Any]: New variant details or exception.
1387
+ Union[AppVariantResponse, Any]: New variant details or exception.
1382
1388
 
1383
1389
  Parameters
1384
1390
  ----------
@@ -1540,16 +1546,16 @@ class AsyncVariantsClient:
1540
1546
  Start a variant of an app.
1541
1547
 
1542
1548
  Args:
1543
- variant_id (str): The ID of the variant to start.
1544
- action (VariantAction): The action to perform on the variant (start).
1545
- env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
1546
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
1549
+ variant_id (str): The ID of the variant to start.
1550
+ action (VariantAction): The action to perform on the variant (start).
1551
+ env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
1552
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
1547
1553
 
1548
1554
  Returns:
1549
- URI: The URL of the started variant.
1555
+ URI: The URL of the started variant.
1550
1556
 
1551
1557
  Raises:
1552
- HTTPException: If the app container cannot be started.
1558
+ HTTPException: If the app container cannot be started.
1553
1559
 
1554
1560
  Parameters
1555
1561
  ----------
@@ -1642,10 +1648,16 @@ class AsyncVariantsClient:
1642
1648
  In the case it's the last variant using the image, stop the container and remove the image.
1643
1649
 
1644
1650
  Arguments:
1645
- app_variant -- AppVariant to remove
1651
+
1652
+
1653
+
1654
+ app_variant -- AppVariant to remove
1646
1655
 
1647
1656
  Raises:
1648
- HTTPException: If there is a problem removing the app variant
1657
+
1658
+
1659
+
1660
+ HTTPException: If there is a problem removing the app variant
1649
1661
 
1650
1662
  Parameters
1651
1663
  ----------
@@ -1719,15 +1731,15 @@ class AsyncVariantsClient:
1719
1731
  Updates the parameters for an app variant.
1720
1732
 
1721
1733
  Args:
1722
- variant_id (str): The ID of the app variant to update.
1723
- payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
1724
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
1734
+ variant_id (str): The ID of the app variant to update.
1735
+ payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
1736
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
1725
1737
 
1726
1738
  Raises:
1727
- HTTPException: If there is an error while trying to update the app variant.
1739
+ HTTPException: If there is an error while trying to update the app variant.
1728
1740
 
1729
1741
  Returns:
1730
- JSONResponse: A JSON response containing the updated app variant parameters.
1742
+ JSONResponse: A JSON response containing the updated app variant parameters.
1731
1743
 
1732
1744
  Parameters
1733
1745
  ----------
@@ -1815,14 +1827,14 @@ class AsyncVariantsClient:
1815
1827
  Updates the image used in an app variant.
1816
1828
 
1817
1829
  Args:
1818
- variant_id (str): The ID of the app variant to update.
1819
- image (Image): The image information to update.
1830
+ variant_id (str): The ID of the app variant to update.
1831
+ image (Image): The image information to update.
1820
1832
 
1821
1833
  Raises:
1822
- HTTPException: If an error occurs while trying to update the app variant.
1834
+ HTTPException: If an error occurs while trying to update the app variant.
1823
1835
 
1824
1836
  Returns:
1825
- JSONResponse: A JSON response indicating whether the update was successful or not.
1837
+ JSONResponse: A JSON response indicating whether the update was successful or not.
1826
1838
 
1827
1839
  Parameters
1828
1840
  ----------
@@ -142,8 +142,8 @@ class entrypoint:
142
142
  app.add_middleware(InlineMiddleware)
143
143
  app.add_middleware(VaultMiddleware)
144
144
  app.add_middleware(ConfigMiddleware)
145
- app.add_middleware(OTelMiddleware)
146
145
  app.add_middleware(AuthMiddleware)
146
+ app.add_middleware(OTelMiddleware)
147
147
  app.add_middleware(CORSMiddleware)
148
148
  ### ------------------ #
149
149
 
@@ -175,14 +175,22 @@ class entrypoint:
175
175
  self.update_run_wrapper_signature(wrapper=run_wrapper)
176
176
 
177
177
  run_route = f"{entrypoint._run_path}{route_path}"
178
- app.post(run_route, response_model=BaseResponse)(run_wrapper)
178
+ app.post(
179
+ run_route,
180
+ response_model=BaseResponse,
181
+ response_model_exclude_none=True,
182
+ )(run_wrapper)
179
183
 
180
184
  # LEGACY
181
185
  # TODO: Removing this implies breaking changes in :
182
186
  # - calls to /generate_deployed must be replaced with calls to /run
183
187
  if route_path == "":
184
188
  run_route = entrypoint._legacy_generate_deployed_path
185
- app.post(run_route, response_model=BaseResponse)(run_wrapper)
189
+ app.post(
190
+ run_route,
191
+ response_model=BaseResponse,
192
+ response_model_exclude_none=True,
193
+ )(run_wrapper)
186
194
  # LEGACY
187
195
  ### ----------- #
188
196
 
@@ -203,21 +211,33 @@ class entrypoint:
203
211
  self.update_test_wrapper_signature(wrapper=test_wrapper, config_instance=config)
204
212
 
205
213
  test_route = f"{entrypoint._test_path}{route_path}"
206
- app.post(test_route, response_model=BaseResponse)(test_wrapper)
214
+ app.post(
215
+ test_route,
216
+ response_model=BaseResponse,
217
+ response_model_exclude_none=True,
218
+ )(test_wrapper)
207
219
 
208
220
  # LEGACY
209
221
  # TODO: Removing this implies breaking changes in :
210
222
  # - calls to /generate must be replaced with calls to /test
211
223
  if route_path == "":
212
224
  test_route = entrypoint._legacy_generate_path
213
- app.post(test_route, response_model=BaseResponse)(test_wrapper)
225
+ app.post(
226
+ test_route,
227
+ response_model=BaseResponse,
228
+ response_model_exclude_none=True,
229
+ )(test_wrapper)
214
230
  # LEGACY
215
231
 
216
232
  # LEGACY
217
233
  # TODO: Removing this implies no breaking changes
218
234
  if route_path == "":
219
235
  test_route = entrypoint._legacy_playground_run_path
220
- app.post(test_route, response_model=BaseResponse)(test_wrapper)
236
+ app.post(
237
+ test_route,
238
+ response_model=BaseResponse,
239
+ response_model_exclude_none=True,
240
+ )(test_wrapper)
221
241
  # LEGACY
222
242
  ### ------------ #
223
243
 
@@ -369,7 +389,9 @@ class entrypoint:
369
389
  ):
370
390
  display_exception("Application Exception")
371
391
 
372
- status_code = 500
392
+ status_code = (
393
+ getattr(error, "status_code") if hasattr(error, "status_code") else 500
394
+ )
373
395
  stacktrace = format_exception(error, value=error, tb=error.__traceback__) # type: ignore
374
396
 
375
397
  raise HTTPException(
@@ -430,8 +452,8 @@ class entrypoint:
430
452
  link = context.link
431
453
 
432
454
  tree = None
433
- _tree_id = link.get("tree_id") if link else None # in int format
434
- tree_id = str(UUID(int=_tree_id)) if _tree_id else None # in uuid_as_str format
455
+ _tree_id = link.get("tree_id") if link else None # in int format
456
+ tree_id = str(UUID(int=_tree_id)) if _tree_id else None # in uuid_as_str format
435
457
 
436
458
  if _tree_id is not None:
437
459
  if inline:
@@ -560,7 +582,7 @@ class entrypoint:
560
582
  config_class_name = type(config).__name__
561
583
  config_schema = openapi_schema["components"]["schemas"][config_class_name]
562
584
  # Process each field in the config class
563
- for field_name, field in config.__class__.__fields__.items():
585
+ for field_name, field in config.__class__.model_fields.items():
564
586
  # Check if field has Annotated metadata for MultipleChoice
565
587
  if hasattr(field, "metadata") and field.metadata:
566
588
  for meta in field.metadata:
@@ -165,15 +165,27 @@ class instrument: # pylint: disable=invalid-name
165
165
  usage = {"total_tokens": usage}
166
166
 
167
167
  span.set_attributes(
168
- attributes={"total": cost},
168
+ attributes={"total": float(cost) if cost else None},
169
169
  namespace="metrics.unit.costs",
170
170
  )
171
171
  span.set_attributes(
172
172
  attributes=(
173
173
  {
174
- "prompt": usage.get("prompt_tokens", None),
175
- "completion": usage.get("completion_tokens", None),
176
- "total": usage.get("total_tokens", None),
174
+ "prompt": (
175
+ float(usage.get("prompt_tokens"))
176
+ if usage.get("prompt_tokens", None)
177
+ else None
178
+ ),
179
+ "completion": (
180
+ float(usage.get("completion_tokens"))
181
+ if usage.get("completion_tokens", None)
182
+ else None
183
+ ),
184
+ "total": (
185
+ float(usage.get("total_tokens", None))
186
+ if usage.get("total_tokens", None)
187
+ else None
188
+ ),
177
189
  }
178
190
  ),
179
191
  namespace="metrics.unit.tokens",
@@ -154,16 +154,34 @@ def litellm_handler():
154
154
  pass
155
155
 
156
156
  span.set_attributes(
157
- attributes={"total": kwargs.get("response_cost")},
157
+ attributes={
158
+ "total": (
159
+ float(kwargs.get("response_cost"))
160
+ if kwargs.get("response_cost")
161
+ else None
162
+ )
163
+ },
158
164
  namespace="metrics.unit.costs",
159
165
  )
160
166
 
161
167
  span.set_attributes(
162
168
  attributes=(
163
169
  {
164
- "prompt": response_obj.usage.prompt_tokens,
165
- "completion": response_obj.usage.completion_tokens,
166
- "total": response_obj.usage.total_tokens,
170
+ "prompt": (
171
+ float(response_obj.usage.prompt_tokens)
172
+ if response_obj.usage.prompt_tokens
173
+ else None
174
+ ),
175
+ "completion": (
176
+ float(response_obj.usage.completion_tokens)
177
+ if response_obj.usage.completion_tokens
178
+ else None
179
+ ),
180
+ "total": (
181
+ float(response_obj.usage.total_tokens)
182
+ if response_obj.usage.total_tokens
183
+ else None
184
+ ),
167
185
  }
168
186
  ),
169
187
  namespace="metrics.unit.tokens",
@@ -264,16 +282,34 @@ def litellm_handler():
264
282
  pass
265
283
 
266
284
  span.set_attributes(
267
- attributes={"total": kwargs.get("response_cost")},
285
+ attributes={
286
+ "total": (
287
+ float(kwargs.get("response_cost"))
288
+ if kwargs.get("response_cost")
289
+ else None
290
+ )
291
+ },
268
292
  namespace="metrics.unit.costs",
269
293
  )
270
294
 
271
295
  span.set_attributes(
272
296
  attributes=(
273
297
  {
274
- "prompt": response_obj.usage.prompt_tokens,
275
- "completion": response_obj.usage.completion_tokens,
276
- "total": response_obj.usage.total_tokens,
298
+ "prompt": (
299
+ float(response_obj.usage.prompt_tokens)
300
+ if response_obj.usage.prompt_tokens
301
+ else None
302
+ ),
303
+ "completion": (
304
+ float(response_obj.usage.completion_tokens)
305
+ if response_obj.usage.completion_tokens
306
+ else None
307
+ ),
308
+ "total": (
309
+ float(response_obj.usage.total_tokens)
310
+ if response_obj.usage.total_tokens
311
+ else None
312
+ ),
277
313
  }
278
314
  ),
279
315
  namespace="metrics.unit.tokens",
@@ -1,7 +1,7 @@
1
1
  from typing import Optional, Protocol, Any
2
2
 
3
- from agenta.sdk.context.routing import routing_context
4
3
  from agenta.sdk.litellm.mocks import MOCKS
4
+ from agenta.sdk.context.routing import routing_context
5
5
 
6
6
 
7
7
  class LitellmProtocol(Protocol):
@@ -19,7 +19,7 @@ async def acompletion(*args, **kwargs):
19
19
  if mock not in MOCKS:
20
20
  raise ValueError(f"Mock {mock} not found")
21
21
 
22
- return MOCKS[mock]
22
+ return MOCKS[mock](*args, **kwargs)
23
23
 
24
24
  if not litellm:
25
25
  raise ValueError("litellm not found")