agenta 0.6.2__tar.gz → 0.6.4__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.
- {agenta-0.6.2 → agenta-0.6.4}/PKG-INFO +1 -1
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/agenta_decorator.py +55 -19
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/agenta_init.py +4 -0
- {agenta-0.6.2 → agenta-0.6.4}/pyproject.toml +1 -1
- {agenta-0.6.2 → agenta-0.6.4}/README.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/__init__.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/cli/helper.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/cli/main.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/cli/telemetry.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/cli/variant_commands.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/cli/variant_configs.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/client/Readme.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/client/__init__.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/client/api_models.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/client/client.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/config.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/config.toml +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/Dockerfile.cloud.template +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/Dockerfile.template +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/README.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/entrypoint.sh +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/lambda_function.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker-assets/main.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/docker/docker_utils.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/__init__.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/context.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/router.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/types.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/utils/globals.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/sdk/utils/preinit.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/compose_email/README.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/compose_email/app.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/compose_email/env.example +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/compose_email/requirements.txt +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/compose_email/template.toml +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/extract_data_to_json/README.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/extract_data_to_json/app.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/extract_data_to_json/env.example +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/extract_data_to_json/requirements.txt +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/extract_data_to_json/template.toml +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/simple_prompt/README.md +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/simple_prompt/app.py +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/simple_prompt/env.example +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/simple_prompt/requirements.txt +0 -0
- {agenta-0.6.2 → agenta-0.6.4}/agenta/templates/simple_prompt/template.toml +0 -0
|
@@ -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:
|
|
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,
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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):
|
|
@@ -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:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|