agenta 0.14.7a1__py3-none-any.whl → 0.14.8a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of agenta might be problematic. Click here for more details.

agenta/__init__.py CHANGED
@@ -16,7 +16,6 @@ from .sdk.types import (
16
16
  )
17
17
  from .sdk.tracing.decorators import span
18
18
  from .sdk.agenta_init import Config, init, llm_tracing
19
- from .sdk.tracing.callbacks import agenta_litellm_handler
20
19
  from .sdk.utils.helper.openai_cost import calculate_token_usage
21
20
  from .sdk.client import Agenta
22
21
 
@@ -104,12 +104,13 @@ def add_variant(
104
104
  )
105
105
 
106
106
  if variant_name in config["variants"] and not overwrite:
107
- overwrite_question = questionary.confirm(
108
- "This variant already exists. Do you want to overwrite it?"
109
- ).ask()
110
- if not overwrite_question:
111
- click.echo("Operation cancelled.")
112
- sys.exit(0)
107
+ if not overwrite:
108
+ overwrite = questionary.confirm(
109
+ "This variant already exists. Do you want to overwrite it?"
110
+ ).ask()
111
+ if not overwrite:
112
+ click.echo("Operation cancelled.")
113
+ return
113
114
 
114
115
  try:
115
116
  click.echo(
@@ -445,7 +446,6 @@ def remove_variant_cli(variant_name: str, app_folder: str):
445
446
  @click.option(
446
447
  "--overwrite",
447
448
  is_flag=True,
448
- default=False,
449
449
  help="Overwrite the existing variant if it exists",
450
450
  )
451
451
  @click.pass_context
@@ -3,6 +3,7 @@ FROM public.ecr.aws/s2t9a1r1/agentaai/lambda_templates_public:main
3
3
  COPY requirements.txt ${LAMBDA_TASK_ROOT}
4
4
  RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
5
5
  RUN pip install --no-cache-dir --disable-pip-version-check mangum
6
+ RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
6
7
  COPY . ${LAMBDA_TASK_ROOT}
7
8
 
8
9
  CMD [ "lambda_function.handler" ]
@@ -5,6 +5,7 @@ WORKDIR /app
5
5
  COPY . .
6
6
 
7
7
  RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
8
+ RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
8
9
 
9
10
  EXPOSE 80
10
11
 
agenta/sdk/__init__.py CHANGED
@@ -17,7 +17,6 @@ from .types import (
17
17
  )
18
18
  from .tracing.decorators import span
19
19
  from .agenta_init import Config, init, llm_tracing
20
- from .tracing.callbacks import agenta_litellm_handler
21
20
  from .utils.helper.openai_cost import calculate_token_usage
22
21
 
23
22
 
@@ -17,7 +17,6 @@ from fastapi import Body, FastAPI, UploadFile, HTTPException
17
17
 
18
18
  import agenta
19
19
  from .context import save_context
20
- from .tracing.llm_tracing import Tracing
21
20
  from .router import router as router
22
21
  from .types import (
23
22
  Context,
@@ -156,7 +155,10 @@ def entrypoint(func: Callable[..., Any]) -> Callable[..., Any]:
156
155
 
157
156
  if is_main_script(func):
158
157
  handle_terminal_run(
159
- func, func_signature.parameters, config_params, ingestible_files, tracing
158
+ func,
159
+ func_signature.parameters,
160
+ config_params,
161
+ ingestible_files,
160
162
  )
161
163
  return None
162
164
 
@@ -348,7 +350,6 @@ def handle_terminal_run(
348
350
  func_params: Dict[str, Any],
349
351
  config_params: Dict[str, Any],
350
352
  ingestible_files: Dict,
351
- tracing: Tracing,
352
353
  ) -> None:
353
354
  """
354
355
  Parses command line arguments and sets configuration when script is run from the terminal.
@@ -356,8 +357,9 @@ def handle_terminal_run(
356
357
  Args:
357
358
  func_params (dict): A dictionary containing the function parameters and their annotations.
358
359
  config_params (dict): A dictionary containing the configuration parameters.
359
- ingestible_files (dict): A dictionary containing the files that should be ingested.
360
- tracing (Tracing): The tracing object
360
+
361
+ Example:
362
+ handle_terminal_run(func_params=inspect.signature(my_function).parameters, config_params=config.all())
361
363
  """
362
364
 
363
365
  # For required parameters, we add them as arguments
@@ -396,29 +398,13 @@ def handle_terminal_run(
396
398
  )
397
399
  agenta.config.set(**args_config_params)
398
400
 
399
- # Start tracing
400
- tracing.start_parent_span(
401
- name=func.__name__,
402
- inputs=args_func_params,
403
- config=args_config_params,
404
- environment="shell", # type: ignore
405
- )
406
-
407
401
  loop = asyncio.get_event_loop()
408
402
  result = loop.run_until_complete(
409
403
  execute_function(
410
404
  func, **{"params": args_func_params, "config_params": args_config_params}
411
405
  )
412
406
  )
413
-
414
- # End trace recording
415
- tracing.end_recording(
416
- outputs=result.dict(),
417
- span=tracing.active_trace, # type: ignore
418
- )
419
- print(
420
- f"\n========== Result ==========\n\nMessage: {result.message}\nCost: {result.cost}\nToken Usage: {result.usage}"
421
- )
407
+ print(result)
422
408
 
423
409
 
424
410
  def override_schema(openapi_schema: dict, func_name: str, endpoint: str, params: dict):
@@ -1,5 +1,4 @@
1
1
  # Stdlib Imports
2
- from threading import Lock
3
2
  from datetime import datetime, timezone
4
3
  from typing import Optional, Dict, Any, List, Union
5
4
 
@@ -14,43 +13,10 @@ from agenta.client.backend.types.create_span import CreateSpan, SpanKind, SpanSt
14
13
  from bson.objectid import ObjectId
15
14
 
16
15
 
17
- class SingletonMeta(type):
18
- """
19
- Thread-safe implementation of Singleton.
20
- """
21
-
22
- _instances = {}
23
-
24
- # We need the lock mechanism to synchronize threads \
25
- # during the initial access to the Singleton object.
26
- _lock: Lock = Lock()
16
+ class Tracing(object):
17
+ """Agenta llm tracing object.
27
18
 
28
- def __call__(cls, *args, **kwargs):
29
- """
30
- Possible changes to the value of the `__init__` argument do not affect
31
- the returned instance.
32
- """
33
- # Now, imagine that the program has just been launched. Since there's no
34
- # Singleton instance yet, multiple threads can simultaneously pass the
35
- # previous conditional and reach this point almost at the same time. The
36
- # first of them will acquire lock and will proceed further, while the
37
- # rest will wait here.
38
- with cls._lock:
39
- # The first thread to acquire the lock, reaches this conditional,
40
- # goes inside and creates the Singleton instance. Once it leaves the
41
- # lock block, a thread that might have been waiting for the lock
42
- # release may then enter this section. But since the Singleton field
43
- # is already initialized, the thread won't create a new object.
44
- if cls not in cls._instances:
45
- instance = super().__call__(*args, **kwargs)
46
- cls._instances[cls] = instance
47
- return cls._instances[cls]
48
-
49
-
50
- class Tracing(metaclass=SingletonMeta):
51
- """The `Tracing` class is an agent for LLM tracing with specific initialization arguments.
52
-
53
- __init__ args:
19
+ Args:
54
20
  base_url (str): The URL of the backend host
55
21
  api_key (str): The API Key of the backend host
56
22
  tasks_manager (TaskQueue): The tasks manager dedicated to handling asynchronous tasks
@@ -58,6 +24,13 @@ class Tracing(metaclass=SingletonMeta):
58
24
  max_workers (int): The maximum number of workers to run tracing
59
25
  """
60
26
 
27
+ _instance = None
28
+
29
+ def __new__(cls, *args, **kwargs):
30
+ if not cls._instance:
31
+ cls._instance = super().__new__(cls)
32
+ return cls._instance
33
+
61
34
  def __init__(
62
35
  self,
63
36
  base_url: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agenta
3
- Version: 0.14.7a1
3
+ Version: 0.14.8a0
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
@@ -22,7 +22,6 @@ Requires-Dist: fastapi (>=0.96.1)
22
22
  Requires-Dist: httpx (>=0.24,<0.28)
23
23
  Requires-Dist: importlib-metadata (>=6.7.0,<7.0.0)
24
24
  Requires-Dist: ipdb (>=0.13)
25
- Requires-Dist: litellm (>=1.35.33,<2.0.0)
26
25
  Requires-Dist: posthog (>=3.1.0,<4.0.0)
27
26
  Requires-Dist: pydantic (==1.10.13)
28
27
  Requires-Dist: pymongo (>=4.6.3,<5.0.0)
@@ -1,9 +1,9 @@
1
- agenta/__init__.py,sha256=ZJZlhn56j2rjl-QKTuNU6HHlJLVlmd_NcU67VIBvGGI,668
1
+ agenta/__init__.py,sha256=rCZ-mUOGnyKQpfWQFzXIEFX7KBlGC3qFMighdIVJgDc,610
2
2
  agenta/cli/evaluation_commands.py,sha256=fs6492tprPId9p8eGO02Xy-NCBm2RZNJLZWcUxugwd8,474
3
3
  agenta/cli/helper.py,sha256=vRxHyeNaltzNIGrfU2vO0H28_rXDzx9QqIZ_S-W6zL4,6212
4
4
  agenta/cli/main.py,sha256=GgYu6UsrnHbqPV7zPlO14b61IyaDiTIjGMYQS9DlqC4,9551
5
5
  agenta/cli/telemetry.py,sha256=GaFFRsE_NtrcSSJ10r2jhgFs5Sk8gf2C09Ox3gOr3eU,1317
6
- agenta/cli/variant_commands.py,sha256=clqmv-UL2UKjOSVGn1icOXSEJ3EMf43-OphuHNWknCQ,17286
6
+ agenta/cli/variant_commands.py,sha256=NjTXOMaJWyZtwtJiU7Ldl47jTYeC7-vktar1GNO6FVY,17294
7
7
  agenta/cli/variant_configs.py,sha256=PLiuMKadVzs6Gi2uYaT0pZzyULNHDXaTMDWboqpwWdU,1293
8
8
  agenta/client/Readme.md,sha256=zWJ6VMYCG124op5RcqgWBdJdlGkGQ2rPLk9F32rWvqo,2756
9
9
  agenta/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -119,23 +119,22 @@ agenta/client/client.py,sha256=DWOGS9A8u4wu28s9jGOR4eRhf7vo4zT7GyDvrIGu59Y,19648
119
119
  agenta/client/exceptions.py,sha256=cxLjjKvZKlUgBxt4Vn9J_SsezJPPNHvrZxnoq-D6zmw,94
120
120
  agenta/config.py,sha256=Id-Ie1yf9QRP1YPhRYaYSOruRe6RBrsCXkG9rAa-ZtA,732
121
121
  agenta/config.toml,sha256=ptE0P49bwsu3Luyn7OLFmk2buPhj5D-MA-O_ErOGoLg,223
122
- agenta/docker/docker-assets/Dockerfile.cloud.template,sha256=CwJbCTezOYCGowA-Hh19f85YXgynT89CrWxjNxLJJfg,317
123
- agenta/docker/docker-assets/Dockerfile.template,sha256=utZ3Y1E0_EfYz5PkuqvIXv1DEddI1QPCO-d6rbcV4H4,211
122
+ agenta/docker/docker-assets/Dockerfile.cloud.template,sha256=f8VU9fs0mMDISGlo3kAYzF8YyDAKgK9FJQHl4PJwykw,386
123
+ agenta/docker/docker-assets/Dockerfile.template,sha256=jkZM1dOPUyQiO9q4jn_RR34-A76lhv5CHJmP0OJHyoE,280
124
124
  agenta/docker/docker-assets/README.md,sha256=XHxwh2ks_ozrtAU7SLbL3J14SB2holG6buoTxwmMiZM,102
125
125
  agenta/docker/docker-assets/entrypoint.sh,sha256=29XK8VQjQsx4hN2j-4JDy-6kQb5y4LCqZEa7PD4eqCQ,74
126
126
  agenta/docker/docker-assets/lambda_function.py,sha256=h4UZSSfqwpfsCgERv6frqwm_4JrYu9rLz3I-LxCfeEg,83
127
127
  agenta/docker/docker-assets/main.py,sha256=7MI-21n81U7N7A0GxebNi0cmGWtJKcR2sPB6FcH2QfA,251
128
128
  agenta/docker/docker_utils.py,sha256=5uHMCzXkCvIsDdEiwbnnn97KkzsFbBvyMwogCsv_Z5U,3509
129
- agenta/sdk/__init__.py,sha256=3At8FvbuYFoP5IIYs4FZWYQK8l4XlVD1zv4E6QsgQv0,702
130
- agenta/sdk/agenta_decorator.py,sha256=ucoGffoIefsYaxniMfMgsepKDo8jrlVMA7gGoTYyQUc,17805
129
+ agenta/sdk/__init__.py,sha256=jmeLRuXrew02ZruODZYIu4kpw0S8vV6JhMPQWFGtj30,648
130
+ agenta/sdk/agenta_decorator.py,sha256=6vz0G3YCRKRzK8JrQFyy8c2RIXy2kVMwyxTS093_8vQ,17296
131
131
  agenta/sdk/agenta_init.py,sha256=wDfStpe8_3ZXRLtikarwDKI_VpA1YW4eIz_3fXq39is,9044
132
132
  agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
133
133
  agenta/sdk/context.py,sha256=q-PxL05-I84puunUAs9LGsffEXcYhDxhQxjuOz2vK90,901
134
134
  agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
135
- agenta/sdk/tracing/callbacks.py,sha256=OePIUSTNG4HqMp9mOx5QtyeHWarG1opv00gg_oVwceE,4525
136
135
  agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
137
136
  agenta/sdk/tracing/decorators.py,sha256=ujtU8gf3GDoHYuLTfEYK_2eIYZ-1oX5dpv02Mf4l_II,1191
138
- agenta/sdk/tracing/llm_tracing.py,sha256=f69FtUIA187gNob8N6IZ-eiF6QQyBVl2JUMJ4Nnnp7M,8671
137
+ agenta/sdk/tracing/llm_tracing.py,sha256=UiotJ56EFA3VPt7LREkcK2w51D9-0T1QNvBy4zNWEdY,7348
139
138
  agenta/sdk/tracing/logger.py,sha256=4zG9c51p8xPdKA5SL8MOgBfkpCnBSuV6JfWiXO0A7oc,473
140
139
  agenta/sdk/tracing/tasks_manager.py,sha256=XVGBEOwmHa6KcCC0PApk0_bZ0Ilk2ESuduNObB1rw2s,3792
141
140
  agenta/sdk/types.py,sha256=Mn0yBlHh_Yr_5oQXUfsYI3V7sJAVWkJgkxEOBDOOMS0,5852
@@ -157,7 +156,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
157
156
  agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
158
157
  agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
159
158
  agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
160
- agenta-0.14.7a1.dist-info/METADATA,sha256=nTeaKtltqrlaVnwP6NNqcDvSQHeulJNunKIbjyOIPEc,26514
161
- agenta-0.14.7a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
162
- agenta-0.14.7a1.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
163
- agenta-0.14.7a1.dist-info/RECORD,,
159
+ agenta-0.14.8a0.dist-info/METADATA,sha256=8JAABiw4ylsIaAW7IFN7LnmksheoUpS0Egdzaa911zU,26472
160
+ agenta-0.14.8a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
161
+ agenta-0.14.8a0.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
162
+ agenta-0.14.8a0.dist-info/RECORD,,
@@ -1,129 +0,0 @@
1
- # Own Imports
2
- from agenta.sdk import llm_tracing
3
-
4
- # Third Party Imports
5
- from litellm.utils import ModelResponse
6
- from litellm.integrations.custom_logger import CustomLogger as LitellmCustomLogger
7
-
8
-
9
- class AgentaLiteLLMHandler(LitellmCustomLogger):
10
- """This handler is responsible for logging certain events when using litellm to call LLMs.
11
-
12
- Args:
13
- LitellmCustomLogger (object): custom logger that allows us to override the events to capture.
14
- """
15
-
16
- @property
17
- def _trace(self):
18
- return llm_tracing()
19
-
20
- def log_pre_api_call(self, model, messages, kwargs):
21
- self._trace.start_span(
22
- name="pre_api_call",
23
- input=(
24
- {"messages": messages}
25
- if isinstance(messages, list)
26
- else {"inputs": messages}
27
- ),
28
- spankind=(
29
- "llm"
30
- if kwargs.get("call_type") in ["completion", "acompletion"]
31
- else (
32
- "embedding"
33
- if kwargs.get("call_type") in ["embedding", "aembedding"]
34
- else "unset"
35
- )
36
- ),
37
- )
38
- self._trace.set_span_attribute(
39
- "model_config",
40
- {
41
- "model": kwargs.get("model"),
42
- "temperature": kwargs["optional_params"]["temperature"],
43
- },
44
- )
45
-
46
- def log_stream_event(self, kwargs, response_obj, start_time, end_time):
47
- self._trace.update_span_status(span=self._trace.active_span, value="OK")
48
- self._trace.end_span(
49
- outputs={
50
- "message": kwargs("complete_streaming_response"),
51
- "usage": kwargs.get("usage"),
52
- "cost": kwargs.get("response_cost"),
53
- },
54
- span=self._trace.active_span,
55
- )
56
-
57
- def log_success_event(
58
- self, kwargs, response_obj: ModelResponse, start_time, end_time
59
- ):
60
- self._trace.update_span_status(span=self._trace.active_span, value="OK")
61
- self._trace.end_span(
62
- outputs={
63
- "message": kwargs["message"],
64
- "usage": kwargs.get("usage"),
65
- "cost": kwargs.get("response_cost"),
66
- },
67
- span=self._trace.active_span,
68
- )
69
-
70
- def log_failure_event(
71
- self, kwargs, response_obj: ModelResponse, start_time, end_time
72
- ):
73
- self._trace.update_span_status(span=self._trace.active_span, value="ERROR")
74
- self._trace.set_span_attribute(
75
- attributes={
76
- "traceback_exception": kwargs["traceback_exception"],
77
- "call_end_time": kwargs["end_time"],
78
- },
79
- )
80
- self._trace.end_span(
81
- outputs={
82
- "message": kwargs["exception"],
83
- "usage": kwargs.get("usage"),
84
- "cost": kwargs.get("response_cost"),
85
- },
86
- span=self._trace.active_span,
87
- )
88
-
89
- async def async_log_stream_event(self, kwargs, response_obj, start_time, end_time):
90
- self._trace.update_span_status(span=self._trace.active_span, value="OK")
91
- self._trace.end_span(
92
- outputs={
93
- "message": kwargs("complete_streaming_response"),
94
- "usage": kwargs.get("usage"),
95
- "cost": kwargs.get("response_cost"),
96
- },
97
- span=self._trace.active_span,
98
- )
99
-
100
- async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
101
- self._trace.update_span_status(span=self._trace.active_span, value="OK")
102
- self._trace.end_span(
103
- outputs={
104
- "message": kwargs["message"],
105
- "usage": kwargs.get("usage"),
106
- "cost": kwargs.get("response_cost"),
107
- },
108
- span=self._trace.active_span,
109
- )
110
-
111
- async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time):
112
- self._trace.update_span_status(span=self._trace.active_span, value="ERROR")
113
- self._trace.set_span_attribute(
114
- attributes={
115
- "traceback_exception": kwargs["traceback_exception"],
116
- "call_end_time": kwargs["end_time"],
117
- },
118
- )
119
- self._trace.end_span(
120
- outputs={
121
- "message": kwargs["exception"],
122
- "usage": kwargs.get("usage"),
123
- "cost": kwargs.get("response_cost"),
124
- },
125
- span=self._trace.active_span,
126
- )
127
-
128
-
129
- agenta_litellm_handler = AgentaLiteLLMHandler()