agenta 0.20.0a4__tar.gz → 0.20.0a7__tar.gz

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 (166) hide show
  1. {agenta-0.20.0a4 → agenta-0.20.0a7}/PKG-INFO +1 -1
  2. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/span.py +2 -0
  3. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/decorators/llm_entrypoint.py +22 -21
  4. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/decorators/tracing.py +30 -20
  5. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/callbacks.py +28 -80
  6. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/llm_tracing.py +24 -0
  7. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/types.py +2 -2
  8. {agenta-0.20.0a4 → agenta-0.20.0a7}/pyproject.toml +1 -1
  9. {agenta-0.20.0a4 → agenta-0.20.0a7}/README.md +0 -0
  10. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/__init__.py +0 -0
  11. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/evaluation_commands.py +0 -0
  12. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/helper.py +0 -0
  13. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/main.py +0 -0
  14. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/telemetry.py +0 -0
  15. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/variant_commands.py +0 -0
  16. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/cli/variant_configs.py +0 -0
  17. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/Readme.md +0 -0
  18. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/__init__.py +0 -0
  19. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/api.py +0 -0
  20. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/api_models.py +0 -0
  21. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/__init__.py +0 -0
  22. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/client.py +0 -0
  23. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/__init__.py +0 -0
  24. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/api_error.py +0 -0
  25. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/client_wrapper.py +0 -0
  26. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/datetime_utils.py +0 -0
  27. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/jsonable_encoder.py +0 -0
  28. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/core/remove_none_from_dict.py +0 -0
  29. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/errors/__init__.py +0 -0
  30. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/errors/unprocessable_entity_error.py +0 -0
  31. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/__init__.py +0 -0
  32. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/apps/__init__.py +0 -0
  33. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/apps/client.py +0 -0
  34. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/bases/__init__.py +0 -0
  35. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/bases/client.py +0 -0
  36. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/configs/__init__.py +0 -0
  37. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/configs/client.py +0 -0
  38. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/containers/__init__.py +0 -0
  39. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/containers/client.py +0 -0
  40. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/containers/types/__init__.py +0 -0
  41. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/containers/types/container_templates_response.py +0 -0
  42. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/environments/__init__.py +0 -0
  43. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/environments/client.py +0 -0
  44. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/evaluations/__init__.py +0 -0
  45. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/evaluations/client.py +0 -0
  46. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/evaluators/__init__.py +0 -0
  47. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/evaluators/client.py +0 -0
  48. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/observability/__init__.py +0 -0
  49. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/observability/client.py +0 -0
  50. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/testsets/__init__.py +0 -0
  51. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/testsets/client.py +0 -0
  52. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/variants/__init__.py +0 -0
  53. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/variants/client.py +0 -0
  54. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/variants/types/__init__.py +0 -0
  55. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/resources/variants/types/add_variant_from_base_and_config_response.py +0 -0
  56. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/__init__.py +0 -0
  57. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/aggregated_result.py +0 -0
  58. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/aggregated_result_evaluator_config.py +0 -0
  59. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/app.py +0 -0
  60. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/app_variant_response.py +0 -0
  61. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/app_variant_revision.py +0 -0
  62. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/base_output.py +0 -0
  63. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/body_import_testset.py +0 -0
  64. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/config_db.py +0 -0
  65. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/create_app_output.py +0 -0
  66. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/create_span.py +0 -0
  67. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/create_trace_response.py +0 -0
  68. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/docker_env_vars.py +0 -0
  69. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/environment_output.py +0 -0
  70. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/environment_output_extended.py +0 -0
  71. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/environment_revision.py +0 -0
  72. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/error.py +0 -0
  73. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation.py +0 -0
  74. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_scenario.py +0 -0
  75. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_scenario_input.py +0 -0
  76. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_scenario_output.py +0 -0
  77. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_scenario_result.py +0 -0
  78. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_scenario_score_update.py +0 -0
  79. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_status_enum.py +0 -0
  80. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_type.py +0 -0
  81. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluation_webhook.py +0 -0
  82. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluator.py +0 -0
  83. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/evaluator_config.py +0 -0
  84. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/feedback.py +0 -0
  85. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/get_config_response.py +0 -0
  86. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/http_validation_error.py +0 -0
  87. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation.py +0 -0
  88. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation_scenario.py +0 -0
  89. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation_scenario_input.py +0 -0
  90. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation_scenario_output.py +0 -0
  91. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation_scenario_update.py +0 -0
  92. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/human_evaluation_update.py +0 -0
  93. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/image.py +0 -0
  94. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/invite_request.py +0 -0
  95. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/list_api_keys_response.py +0 -0
  96. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/llm_run_rate_limit.py +0 -0
  97. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/llm_tokens.py +0 -0
  98. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/new_human_evaluation.py +0 -0
  99. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/new_testset.py +0 -0
  100. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/organization.py +0 -0
  101. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/organization_output.py +0 -0
  102. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/permission.py +0 -0
  103. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/result.py +0 -0
  104. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/score.py +0 -0
  105. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/simple_evaluation_output.py +0 -0
  106. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/span_detail.py +0 -0
  107. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/span_kind.py +0 -0
  108. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/span_status_code.py +0 -0
  109. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/span_variant.py +0 -0
  110. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/template.py +0 -0
  111. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/template_image_info.py +0 -0
  112. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/test_set_output_response.py +0 -0
  113. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/test_set_simple_response.py +0 -0
  114. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/trace_detail.py +0 -0
  115. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/uri.py +0 -0
  116. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/validation_error.py +0 -0
  117. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/validation_error_loc_item.py +0 -0
  118. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/variant_action.py +0 -0
  119. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/variant_action_enum.py +0 -0
  120. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/with_pagination.py +0 -0
  121. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/workspace_member_response.py +0 -0
  122. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/workspace_permission.py +0 -0
  123. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/workspace_response.py +0 -0
  124. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/workspace_role.py +0 -0
  125. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/backend/types/workspace_role_response.py +0 -0
  126. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/client.py +0 -0
  127. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/client/exceptions.py +0 -0
  128. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/config.py +0 -0
  129. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/config.toml +0 -0
  130. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/Dockerfile.cloud.template +0 -0
  131. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/Dockerfile.template +0 -0
  132. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/README.md +0 -0
  133. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/entrypoint.sh +0 -0
  134. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/lambda_function.py +0 -0
  135. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker-assets/main.py +0 -0
  136. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/docker/docker_utils.py +0 -0
  137. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/__init__.py +0 -0
  138. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/agenta_init.py +0 -0
  139. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/client.py +0 -0
  140. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/context.py +0 -0
  141. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/decorators/base.py +0 -0
  142. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/router.py +0 -0
  143. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/__init__.py +0 -0
  144. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/context_manager.py +0 -0
  145. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/logger.py +0 -0
  146. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/tasks_manager.py +0 -0
  147. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/tracing/tracing_context.py +0 -0
  148. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/utils/debug.py +0 -0
  149. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/utils/globals.py +0 -0
  150. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/utils/helper/openai_cost.py +0 -0
  151. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/sdk/utils/preinit.py +0 -0
  152. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/compose_email/README.md +0 -0
  153. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/compose_email/app.py +0 -0
  154. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/compose_email/env.example +0 -0
  155. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/compose_email/requirements.txt +0 -0
  156. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/compose_email/template.toml +0 -0
  157. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/extract_data_to_json/README.md +0 -0
  158. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/extract_data_to_json/app.py +0 -0
  159. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/extract_data_to_json/env.example +0 -0
  160. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/extract_data_to_json/requirements.txt +0 -0
  161. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/extract_data_to_json/template.toml +0 -0
  162. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/simple_prompt/README.md +0 -0
  163. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/simple_prompt/app.py +0 -0
  164. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/simple_prompt/env.example +0 -0
  165. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/simple_prompt/requirements.txt +0 -0
  166. {agenta-0.20.0a4 → agenta-0.20.0a7}/agenta/templates/simple_prompt/template.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agenta
3
- Version: 0.20.0a4
3
+ Version: 0.20.0a7
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
@@ -26,7 +26,9 @@ class Span(pydantic.BaseModel):
26
26
  spankind: str
27
27
  status: SpanStatusCode
28
28
  metadata: typing.Dict[str, typing.Any]
29
+ trace_id: str
29
30
  user_id: typing.Optional[str]
31
+ content: typing.Dict[str, typing.Any]
30
32
  children: typing.Optional[typing.List[Span]]
31
33
 
32
34
  def json(self, **kwargs: typing.Any) -> str:
@@ -12,6 +12,7 @@ import functools
12
12
  from pathlib import Path
13
13
  from tempfile import NamedTemporaryFile
14
14
  from typing import Any, Callable, Dict, Optional, Tuple, List
15
+ from importlib.metadata import version
15
16
 
16
17
  from fastapi.middleware.cors import CORSMiddleware
17
18
  from fastapi import Body, FastAPI, UploadFile, HTTPException
@@ -119,6 +120,8 @@ class entrypoint(BaseDecorator):
119
120
  routes = list()
120
121
 
121
122
  def __init__(self, func: Callable[..., Any], route_path=""):
123
+ print(f"Using Agenta Python SDK version {version("agenta")}")
124
+
122
125
  DEFAULT_PATH = "generate"
123
126
  PLAYGROUND_PATH = "/playground"
124
127
  RUN_PATH = "/run"
@@ -233,9 +236,6 @@ class entrypoint(BaseDecorator):
233
236
  params=route["params"],
234
237
  )
235
238
  ### ---------------------- #
236
-
237
- print(entrypoint.routes)
238
-
239
239
  if self.is_main_script(func) and route_path == "":
240
240
  self.handle_terminal_run(
241
241
  func,
@@ -293,6 +293,8 @@ 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
+ print(f"Using Agenta Python SDK version {version("agenta")}")
297
+
296
298
  WAIT_FOR_SPANS = True
297
299
  TIMEOUT = 10
298
300
  TIMESTEP = 0.01
@@ -331,32 +333,31 @@ class entrypoint(BaseDecorator):
331
333
  if isinstance(result, Context):
332
334
  save_context(result)
333
335
 
334
- DEFAULT_KEY = "message"
336
+ data = result
335
337
 
336
- if isinstance(result, Dict):
338
+ # PATCH : if result is not a dict, make it a dict
339
+ if not isinstance(result, dict):
337
340
  data = result
338
-
339
- # EVENTUALLY THIS PATCH SHOULD BE REMOVED
340
- # PATCH: if message in result then only keep message key/value
341
- # DEFAULT_KEY = "message"
342
-
343
- if "message" in result.keys():
344
- data = {DEFAULT_KEY: result["message"]}
345
- # END OF PATCH
346
-
347
- elif isinstance(result, str):
348
- data = {DEFAULT_KEY: result}
349
- elif isinstance(result, int) or isinstance(result, float):
350
- data = {DEFAULT_KEY: str(result)}
341
+ else:
342
+ # PATCH : if result is a legacy dict, clean it up
343
+ if (
344
+ "message" in result.keys()
345
+ and "cost" in result.keys()
346
+ and "usage" in result.keys()
347
+ ):
348
+ data = {"message": result["message"]}
349
+ # END OF PATH
351
350
 
352
351
  if data is None:
353
- warning = (
352
+ data = (
354
353
  "Function executed successfully, but did return None. \n Are you sure you did not forget to return a value?",
355
354
  )
356
355
 
357
- data = {"message": warning}
356
+ response = BaseResponse(data=data, trace=trace)
357
+
358
+ logging.debug(response)
358
359
 
359
- return BaseResponse(data=data, trace=trace)
360
+ return response
360
361
 
361
362
  except Exception as e:
362
363
  self.handle_exception(e)
@@ -65,19 +65,24 @@ class instrument(BaseDecorator):
65
65
  ):
66
66
  result = await func(*args, **kwargs)
67
67
 
68
- outputs = result
68
+ TRACE_DEFAULT_KEY = "__default__"
69
69
 
70
- # EVENTUALLY THIS PATCH SHOULD BE REMOVED
71
- # PATCH : if result is not a dict, make it a dict, in span
72
- DEFAULT_KEY = "message"
70
+ outputs = result
73
71
 
72
+ # PATCH : if result is not a dict, make it a dict
74
73
  if not isinstance(result, dict):
75
- value = result
76
-
77
- if result.__class__.__module__ != "__builtin__":
78
- value = repr(value)
79
-
80
- outputs = {DEFAULT_KEY: result}
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 = {"message": result["message"]}
83
+
84
+ ag.tracing.store_cost(result["cost"])
85
+ ag.tracing.store_usage(result["usage"])
81
86
  # END OF PATH
82
87
 
83
88
  ag.tracing.store_outputs(outputs)
@@ -97,19 +102,24 @@ class instrument(BaseDecorator):
97
102
  ):
98
103
  result = func(*args, **kwargs)
99
104
 
100
- outputs = result
105
+ TRACE_DEFAULT_KEY = "__default__"
101
106
 
102
- # EVENTUALLY THIS PATCH SHOULD BE REMOVED
103
- # PATCH : if result is not a dict, make it a dict, in span
104
- DEFAULT_KEY = "message"
107
+ outputs = result
105
108
 
109
+ # PATCH : if result is not a dict, make it a dict
106
110
  if not isinstance(result, dict):
107
- value = result
108
-
109
- if result.__class__.__module__ != "__builtin__":
110
- value = repr(value)
111
-
112
- outputs = {DEFAULT_KEY: result}
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"])
113
123
  # END OF PATH
114
124
 
115
125
  ag.tracing.store_outputs(outputs)
@@ -59,51 +59,30 @@ def litellm_handler():
59
59
  )
60
60
 
61
61
  @debug()
62
- def log_stream_event(self, kwargs, response_obj, start_time, end_time):
62
+ def log_stream_event(self, kwargs, res: ModelResponse, start_time, end_time):
63
63
  ag.tracing.set_status(status="OK", span_id=self.span.id)
64
+ ag.tracing.store_cost(kwargs.get("response_cost"))
65
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
64
66
  ag.tracing.store_outputs(
65
- outputs={
66
- "message": kwargs.get(
67
- "complete_streaming_response"
68
- ), # the complete streamed response (only set if `completion(..stream=True)`)
69
- "usage": (
70
- response_obj.usage.dict()
71
- if hasattr(response_obj, "usage")
72
- else None
73
- ), # litellm calculates usage
74
- "cost": kwargs.get(
75
- "response_cost"
76
- ), # litellm calculates response cost
77
- },
67
+ # the complete streamed response (only set if `completion(..stream=True)`
68
+ outputs={"message": kwargs.get("complete_streaming_response")},
78
69
  span_id=self.span.id,
79
70
  )
80
71
  ag.tracing.close_span(span_id=self.span.id)
81
72
 
82
73
  @debug()
83
- def log_success_event(
84
- self, kwargs, response_obj: ModelResponse, start_time, end_time
85
- ):
74
+ def log_success_event(self, kwargs, res: ModelResponse, start_time, end_time):
86
75
  ag.tracing.set_status(status="OK", span_id=self.span.id)
76
+ ag.tracing.store_cost(kwargs.get("response_cost"))
77
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
87
78
  ag.tracing.store_outputs(
88
- outputs={
89
- "message": response_obj.choices[0].message.content,
90
- "usage": (
91
- response_obj.usage.dict()
92
- if hasattr(response_obj, "usage")
93
- else None
94
- ), # litellm calculates usage
95
- "cost": kwargs.get(
96
- "response_cost"
97
- ), # litellm calculates response cost
98
- },
79
+ outputs={"message": res.choices[0].message.content},
99
80
  span_id=self.span.id,
100
81
  )
101
82
  ag.tracing.close_span(span_id=self.span.id)
102
83
 
103
84
  @debug()
104
- def log_failure_event(
105
- self, kwargs, response_obj: ModelResponse, start_time, end_time
106
- ):
85
+ def log_failure_event(self, kwargs, res: ModelResponse, start_time, end_time):
107
86
  ag.tracing.set_status(status="ERROR", span_id=self.span.id)
108
87
  ag.tracing.set_attributes(
109
88
  {
@@ -116,69 +95,45 @@ def litellm_handler():
116
95
  },
117
96
  span_id=self.span.id,
118
97
  )
98
+ ag.tracing.store_cost(kwargs.get("response_cost"))
99
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
119
100
  ag.tracing.store_outputs(
120
- outputs={
121
- "message": repr(kwargs["exception"]), # the Exception raised
122
- "usage": (
123
- response_obj.usage.dict()
124
- if hasattr(response_obj, "usage")
125
- else None
126
- ), # litellm calculates usage
127
- "cost": kwargs.get(
128
- "response_cost"
129
- ), # litellm calculates response cost
130
- },
101
+ # the Exception raised
102
+ outputs={"message": repr(kwargs["exception"])},
131
103
  span_id=self.span.id,
132
104
  )
133
105
  ag.tracing.close_span(span_id=self.span.id)
134
106
 
135
107
  @debug()
136
108
  async def async_log_stream_event(
137
- self, kwargs, response_obj, start_time, end_time
109
+ self, kwargs, res: ModelResponse, start_time, end_time
138
110
  ):
139
111
  ag.tracing.set_status(status="OK", span_id=self.span.id)
112
+ ag.tracing.store_cost(kwargs.get("response_cost"))
113
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
140
114
  ag.tracing.store_outputs(
141
- outputs={
142
- "message": kwargs.get(
143
- "complete_streaming_response"
144
- ), # the complete streamed response (only set if `completion(..stream=True)`)
145
- "usage": (
146
- response_obj.usage.dict()
147
- if hasattr(response_obj, "usage")
148
- else None
149
- ), # litellm calculates usage
150
- "cost": kwargs.get(
151
- "response_cost"
152
- ), # litellm calculates response cost
153
- },
115
+ # the complete streamed response (only set if `completion(..stream=True)`)
116
+ outputs={"message": kwargs.get("complete_streaming_response")},
154
117
  span_id=self.span.id,
155
118
  )
156
119
  ag.tracing.close_span(span_id=self.span.id)
157
120
 
158
121
  @debug()
159
122
  async def async_log_success_event(
160
- self, kwargs, response_obj, start_time, end_time
123
+ self, kwargs, res: ModelResponse, start_time, end_time
161
124
  ):
162
125
  ag.tracing.set_status(status="OK", span_id=self.span.id)
126
+ ag.tracing.store_cost(kwargs.get("response_cost"))
127
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
163
128
  ag.tracing.store_outputs(
164
- outputs={
165
- "message": response_obj.choices[0].message.content,
166
- "usage": (
167
- response_obj.usage.dict()
168
- if hasattr(response_obj, "usage")
169
- else None
170
- ), # litellm calculates usage
171
- "cost": kwargs.get(
172
- "response_cost"
173
- ), # litellm calculates response cost
174
- },
129
+ outputs={"message": res.choices[0].message.content},
175
130
  span_id=self.span.id,
176
131
  )
177
132
  ag.tracing.close_span(span_id=self.span.id)
178
133
 
179
134
  @debug()
180
135
  async def async_log_failure_event(
181
- self, kwargs, response_obj, start_time, end_time
136
+ self, kwargs, res: ModelResponse, start_time, end_time
182
137
  ):
183
138
  ag.tracing.set_status(status="ERROR", span_id=self.span.id)
184
139
  ag.tracing.set_attributes(
@@ -192,18 +147,11 @@ def litellm_handler():
192
147
  },
193
148
  span_id=self.span.id,
194
149
  )
150
+ ag.tracing.store_cost(kwargs.get("response_cost"))
151
+ ag.tracing.store_usage(res.usage.dict() if hasattr(res, "usage") else None)
195
152
  ag.tracing.store_outputs(
196
- outputs={
197
- "message": repr(kwargs["exception"]), # the Exception raised
198
- "usage": (
199
- response_obj.usage.dict()
200
- if hasattr(response_obj, "usage")
201
- else None
202
- ), # litellm calculates usage
203
- "cost": kwargs.get(
204
- "response_cost"
205
- ), # litellm calculates response cost
206
- },
153
+ # the Exception raised
154
+ outputs={"message": repr(kwargs["exception"])},
207
155
  span_id=self.span.id,
208
156
  )
209
157
  ag.tracing.close_span(span_id=self.span.id)
@@ -414,6 +414,30 @@ class Tracing(metaclass=SingletonMeta):
414
414
 
415
415
  span.outputs = outputs
416
416
 
417
+ @debug()
418
+ def store_cost(self, cost: float = 0.0, span_id: Optional[str] = None) -> None:
419
+ """
420
+ ...
421
+ """
422
+ span = self._get_target_span(span_id)
423
+
424
+ logging.info(f"Setting span {span.id} {span.spankind.upper()} cost={cost}")
425
+
426
+ self._update_span_cost(span, cost)
427
+
428
+ @debug()
429
+ def store_usage(self, tokens: dict = {}, span_id: Optional[str] = None) -> None:
430
+ """
431
+ ...
432
+ """
433
+ span = self._get_target_span(span_id)
434
+
435
+ logging.info(
436
+ f"Setting span {span.id} {span.spankind.upper()} tokens={repr(tokens)}"
437
+ )
438
+
439
+ self._update_span_tokens(span, tokens)
440
+
417
441
  @debug()
418
442
  def dump_trace(self):
419
443
  """
@@ -1,5 +1,5 @@
1
1
  import json
2
- from typing import Dict, List, Optional, Any
2
+ from typing import Dict, List, Optional, Any, Union
3
3
 
4
4
  from pydantic import ConfigDict, BaseModel, HttpUrl
5
5
 
@@ -18,7 +18,7 @@ class LLMTokenUsage(BaseModel):
18
18
 
19
19
  class BaseResponse(BaseModel):
20
20
  version: Optional[str] = "2.0"
21
- data: Optional[Dict[str, Any]]
21
+ data: Optional[Union[str, Dict[str, Any]]]
22
22
  trace: Optional[Dict[str, Any]]
23
23
 
24
24
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "agenta"
3
- version = "0.20.0a4"
3
+ version = "0.20.0a7"
4
4
  description = "The SDK for agenta is an open-source LLMOps platform."
5
5
  readme = "README.md"
6
6
  authors = ["Mahmoud Mabrouk <mahmoud@agenta.ai>"]
File without changes
File without changes
File without changes
File without changes
File without changes