agenta 0.6.2__py3-none-any.whl → 0.6.4__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.

@@ -1,19 +1,19 @@
1
1
  """The code for the Agenta SDK"""
2
- import argparse
3
- import functools
4
- import inspect
5
2
  import os
6
3
  import sys
4
+ import inspect
5
+ import argparse
7
6
  import traceback
7
+ import functools
8
8
  from pathlib import Path
9
9
  from tempfile import NamedTemporaryFile
10
- from typing import Any, Callable, Dict, Optional, Tuple
10
+ from typing import Any, Callable, Dict, Optional, Tuple, List
11
11
 
12
- import agenta
13
12
  from fastapi import Body, FastAPI, UploadFile
14
13
  from fastapi.middleware.cors import CORSMiddleware
15
14
  from fastapi.responses import JSONResponse
16
15
 
16
+ import agenta
17
17
  from .context import save_context
18
18
  from .router import router as router
19
19
  from .types import (
@@ -62,20 +62,21 @@ def entrypoint(func: Callable[..., Any]) -> Callable[..., Any]:
62
62
  Returns:
63
63
  Wrapped function for HTTP POST and terminal.
64
64
  """
65
+
65
66
  endpoint_name = "generate"
66
67
  func_signature = inspect.signature(func)
67
68
  config_params = agenta.config.all()
68
69
  ingestible_files = extract_ingestible_files(func_signature)
69
70
 
70
71
  @functools.wraps(func)
71
- def wrapper(*args, **kwargs) -> Any:
72
+ async def wrapper(*args, **kwargs) -> Any:
72
73
  func_params, api_config_params = split_kwargs(kwargs, config_params)
73
74
  ingest_files(func_params, ingestible_files)
74
75
  agenta.config.set(**api_config_params)
75
- return execute_function(func, *args, **func_params)
76
+ return await execute_function(func, *args, **func_params)
76
77
 
77
78
  @functools.wraps(func)
78
- def wrapper_deployed(*args, **kwargs) -> Any:
79
+ async def wrapper_deployed(*args, **kwargs) -> Any:
79
80
  func_params = {
80
81
  k: v for k, v in kwargs.items() if k not in ["config", "environment"]
81
82
  }
@@ -83,9 +84,9 @@ def entrypoint(func: Callable[..., Any]) -> Callable[..., Any]:
83
84
  agenta.config.pull(environment_name=kwargs["environment"])
84
85
  elif "config" in kwargs and kwargs["config"] is not None:
85
86
  agenta.config.pull(config_name=kwargs["config"])
86
- else: # if no config is specified in the api call, we pull the default config
87
+ else:
87
88
  agenta.config.pull(config_name="default")
88
- return execute_function(func, *args, **func_params)
89
+ return await execute_function(func, *args, **func_params)
89
90
 
90
91
  update_function_signature(wrapper, func_signature, config_params, ingestible_files)
91
92
  route = f"/{endpoint_name}"
@@ -107,9 +108,11 @@ def entrypoint(func: Callable[..., Any]) -> Callable[..., Any]:
107
108
 
108
109
  if is_main_script(func):
109
110
  handle_terminal_run(
110
- func, func_signature.parameters, config_params, ingestible_files
111
+ func,
112
+ func_signature.parameters,
113
+ config_params,
114
+ ingestible_files,
111
115
  )
112
-
113
116
  return None
114
117
 
115
118
 
@@ -117,6 +120,7 @@ def extract_ingestible_files(
117
120
  func_signature: inspect.Signature,
118
121
  ) -> Dict[str, inspect.Parameter]:
119
122
  """Extract parameters annotated as InFile from function signature."""
123
+
120
124
  return {
121
125
  name: param
122
126
  for name, param in func_signature.parameters.items()
@@ -128,6 +132,7 @@ def split_kwargs(
128
132
  kwargs: Dict[str, Any], config_params: Dict[str, Any]
129
133
  ) -> Tuple[Dict[str, Any], Dict[str, Any]]:
130
134
  """Split keyword arguments into function parameters and API configuration parameters."""
135
+
131
136
  func_params = {k: v for k, v in kwargs.items() if k not in config_params}
132
137
  api_config_params = {k: v for k, v in kwargs.items() if k in config_params}
133
138
  return func_params, api_config_params
@@ -137,15 +142,27 @@ def ingest_files(
137
142
  func_params: Dict[str, Any], ingestible_files: Dict[str, inspect.Parameter]
138
143
  ) -> None:
139
144
  """Ingest files specified in function parameters."""
145
+
140
146
  for name in ingestible_files:
141
147
  if name in func_params and func_params[name] is not None:
142
148
  func_params[name] = ingest_file(func_params[name])
143
149
 
144
150
 
145
- def execute_function(func: Callable[..., Any], *args, **func_params) -> Any:
151
+ async def execute_function(func: Callable[..., Any], *args, **func_params) -> Any:
146
152
  """Execute the function and handle any exceptions."""
153
+
147
154
  try:
148
- result = func(*args, **func_params)
155
+ """Note: The following block is for backward compatibility.
156
+ It allows functions to work seamlessly whether they are synchronous or asynchronous.
157
+ For synchronous functions, it calls them directly, while for asynchronous functions,
158
+ it awaits their execution.
159
+ """
160
+ is_coroutine_function = inspect.iscoroutinefunction(func)
161
+ if is_coroutine_function:
162
+ result = await func(*args, **func_params)
163
+ else:
164
+ result = func(*args, **func_params)
165
+
149
166
  if isinstance(result, Context):
150
167
  save_context(result)
151
168
  return result
@@ -155,6 +172,7 @@ def execute_function(func: Callable[..., Any], *args, **func_params) -> Any:
155
172
 
156
173
  def handle_exception(e: Exception) -> JSONResponse:
157
174
  """Handle exceptions and return a JSONResponse."""
175
+
158
176
  traceback_str = traceback.format_exception(e, value=e, tb=e.__traceback__)
159
177
  return JSONResponse(
160
178
  status_code=500,
@@ -162,6 +180,21 @@ def handle_exception(e: Exception) -> JSONResponse:
162
180
  )
163
181
 
164
182
 
183
+ def update_wrapper_signature(wrapper: Callable[..., Any], updated_params: List):
184
+ """
185
+ Updates the signature of a wrapper function with a new list of parameters.
186
+
187
+ Args:
188
+ wrapper (callable): A callable object, such as a function or a method, that requires a signature update.
189
+ updated_params (List[inspect.Parameter]): A list of `inspect.Parameter` objects representing the updated parameters
190
+ for the wrapper function.
191
+ """
192
+
193
+ wrapper_signature = inspect.signature(wrapper)
194
+ wrapper_signature = wrapper_signature.replace(parameters=updated_params)
195
+ wrapper.__signature__ = wrapper_signature
196
+
197
+
165
198
  def update_function_signature(
166
199
  wrapper: Callable[..., Any],
167
200
  func_signature: inspect.Signature,
@@ -169,10 +202,11 @@ def update_function_signature(
169
202
  ingestible_files: Dict[str, inspect.Parameter],
170
203
  ) -> None:
171
204
  """Update the function signature to include new parameters."""
205
+
172
206
  updated_params = []
173
207
  add_config_params_to_parser(updated_params, config_params)
174
208
  add_func_params_to_parser(updated_params, func_signature, ingestible_files)
175
- wrapper.__signature__ = func_signature.replace(parameters=updated_params)
209
+ update_wrapper_signature(wrapper, updated_params)
176
210
 
177
211
 
178
212
  def update_deployed_function_signature(
@@ -195,7 +229,7 @@ def update_deployed_function_signature(
195
229
  annotation=str,
196
230
  )
197
231
  )
198
- wrapper.__signature__ = func_signature.replace(parameters=updated_params)
232
+ update_wrapper_signature(wrapper, updated_params)
199
233
 
200
234
 
201
235
  def add_config_params_to_parser(
@@ -271,13 +305,15 @@ def handle_terminal_run(
271
305
  Example:
272
306
  handle_terminal_run(func_params=inspect.signature(my_function).parameters, config_params=config.all())
273
307
  """
274
- parser = argparse.ArgumentParser()
308
+
275
309
  # For required parameters, we add them as arguments
310
+ parser = argparse.ArgumentParser()
276
311
  for name, param in func_params.items():
277
312
  if name in ingestible_files:
278
313
  parser.add_argument(name, type=str)
279
314
  else:
280
315
  parser.add_argument(name, type=param.annotation)
316
+
281
317
  for name, param in config_params.items():
282
318
  if type(param) is MultipleChoiceParam:
283
319
  parser.add_argument(
@@ -295,7 +331,8 @@ def handle_terminal_run(
295
331
 
296
332
  args = parser.parse_args()
297
333
 
298
- # split the arg list into the arg in the app_param and the arge from the sig.parameter
334
+ # split the arg list into the arg in the app_param and
335
+ # the args from the sig.parameter
299
336
  args_config_params = {k: v for k, v in vars(args).items() if k in config_params}
300
337
  args_func_params = {k: v for k, v in vars(args).items() if k not in config_params}
301
338
  for name in ingestible_files:
@@ -304,7 +341,6 @@ def handle_terminal_run(
304
341
  file_path=args_func_params[name],
305
342
  )
306
343
  agenta.config.set(**args_config_params)
307
- # print(func(**args_func_params))
308
344
 
309
345
 
310
346
  def override_schema(openapi_schema: dict, func_name: str, endpoint: str, params: dict):
agenta/sdk/agenta_init.py CHANGED
@@ -83,6 +83,10 @@ class Config:
83
83
  else:
84
84
  self.persist = True
85
85
 
86
+ def register_default(self, overwrite=True, **kwargs):
87
+ """alias for default"""
88
+ return self.default(overwrite=overwrite, **kwargs)
89
+
86
90
  def default(self, overwrite=True, **kwargs):
87
91
  """Saves the default parameters to the app_name and base_name in case they are not already saved.
88
92
  Args:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agenta
3
- Version: 0.6.2
3
+ Version: 0.6.4
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
@@ -18,8 +18,8 @@ agenta/docker/docker-assets/lambda_function.py,sha256=h4UZSSfqwpfsCgERv6frqwm_4J
18
18
  agenta/docker/docker-assets/main.py,sha256=BbmbFByRQ8MzL8402pJryEF34t6ba1i_JrMtWMAQDQ4,327
19
19
  agenta/docker/docker_utils.py,sha256=oK51dmJLUXcR0iEi3knDqt5BZxF3somqWHVOpTQ8rOI,5681
20
20
  agenta/sdk/__init__.py,sha256=3SJtuSWXyOXqzEA5_aPCYMKFKchA9sIO_fZSVOsd1Q4,488
21
- agenta/sdk/agenta_decorator.py,sha256=RVZUBSQEn1aZr7W7SwmipdpM0BQps2XR8xYBNC__WkM,13597
22
- agenta/sdk/agenta_init.py,sha256=3-0WRpRSveWUcLhosTuym-YKV9gKVNrOTxGjSa6SxyI,7152
21
+ agenta/sdk/agenta_decorator.py,sha256=NW2OdRyqpHxVcZbcSuMaDturEssGtUAjbUOdpFfD10A,14638
22
+ agenta/sdk/agenta_init.py,sha256=Ks-uzbNoKbe7SHjrU2bgf_j4HTMQbPvSMFofirhyEkY,7302
23
23
  agenta/sdk/context.py,sha256=q-PxL05-I84puunUAs9LGsffEXcYhDxhQxjuOz2vK90,901
24
24
  agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
25
25
  agenta/sdk/types.py,sha256=K8F7AuDeljy1-mJhQrTuR2fgWzZdaCNZ2BlZ3oXWTKg,4022
@@ -40,7 +40,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
40
40
  agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
41
41
  agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
42
42
  agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
43
- agenta-0.6.2.dist-info/METADATA,sha256=gfN4XvpkyMq78w3wP6gUzYUHulu1FP3NYHZdbXG9vvE,10093
44
- agenta-0.6.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
45
- agenta-0.6.2.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
46
- agenta-0.6.2.dist-info/RECORD,,
43
+ agenta-0.6.4.dist-info/METADATA,sha256=aL84UTan8IXI7slRoKhLGYh3ieuoCVkbcbnF-lGsjmA,10093
44
+ agenta-0.6.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
45
+ agenta-0.6.4.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
46
+ agenta-0.6.4.dist-info/RECORD,,
File without changes