beamlit 0.0.33rc44__py3-none-any.whl → 0.0.33rc46__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- beamlit/agents/decorator.py +28 -18
- beamlit/common/__init__.py +2 -0
- beamlit/common/slugify.py +2 -0
- beamlit/deploy/deploy.py +1 -3
- beamlit/functions/decorator.py +2 -58
- {beamlit-0.0.33rc44.dist-info → beamlit-0.0.33rc46.dist-info}/METADATA +1 -1
- {beamlit-0.0.33rc44.dist-info → beamlit-0.0.33rc46.dist-info}/RECORD +8 -7
- {beamlit-0.0.33rc44.dist-info → beamlit-0.0.33rc46.dist-info}/WHEEL +0 -0
beamlit/agents/decorator.py
CHANGED
@@ -12,7 +12,8 @@ from langgraph.prebuilt import create_react_agent
|
|
12
12
|
|
13
13
|
from beamlit.api.models import get_model
|
14
14
|
from beamlit.authentication import new_client
|
15
|
-
from beamlit.common.settings import init
|
15
|
+
from beamlit.common.settings import init, get_settings
|
16
|
+
from beamlit.common import slugify
|
16
17
|
from beamlit.errors import UnexpectedStatus
|
17
18
|
from beamlit.functions.mcp.mcp import MCPClient, MCPToolkit
|
18
19
|
from beamlit.functions.remote.remote import RemoteToolkit
|
@@ -22,9 +23,10 @@ from .chain import ChainToolkit
|
|
22
23
|
from .chat import get_chat_model
|
23
24
|
|
24
25
|
|
25
|
-
def get_functions(dir="src/functions", from_decorator="function", remote_functions_empty=True):
|
26
|
+
def get_functions(client, dir="src/functions", from_decorator="function", remote_functions_empty=True):
|
26
27
|
functions = []
|
27
28
|
logger = getLogger(__name__)
|
29
|
+
settings = get_settings()
|
28
30
|
|
29
31
|
# Walk through all Python files in functions directory and subdirectories
|
30
32
|
if not os.path.exists(dir):
|
@@ -73,8 +75,9 @@ def get_functions(dir="src/functions", from_decorator="function", remote_functio
|
|
73
75
|
keyword.value, ast.Constant
|
74
76
|
):
|
75
77
|
is_kit = keyword.value.value
|
76
|
-
if is_kit:
|
78
|
+
if is_kit and not settings.remote:
|
77
79
|
kit_functions = get_functions(
|
80
|
+
client,
|
78
81
|
dir=os.path.join(root),
|
79
82
|
from_decorator="kit",
|
80
83
|
remote_functions_empty=remote_functions_empty,
|
@@ -84,23 +87,28 @@ def get_functions(dir="src/functions", from_decorator="function", remote_functio
|
|
84
87
|
# Get the decorated function
|
85
88
|
if not is_kit and hasattr(module, func_name):
|
86
89
|
func = getattr(module, func_name)
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
description=func.__doc__,
|
92
|
-
func=func,
|
93
|
-
coroutine=func,
|
94
|
-
)
|
95
|
-
)
|
90
|
+
if settings.remote:
|
91
|
+
toolkit = RemoteToolkit(client, slugify(func.__name__))
|
92
|
+
toolkit.initialize()
|
93
|
+
functions.extend(toolkit.get_tools())
|
96
94
|
else:
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
if asyncio.iscoroutinefunction(func):
|
96
|
+
functions.append(
|
97
|
+
Tool(
|
98
|
+
name=func.__name__,
|
99
|
+
description=func.__doc__,
|
100
|
+
func=func,
|
101
|
+
coroutine=func,
|
102
|
+
)
|
103
|
+
)
|
104
|
+
else:
|
105
|
+
functions.append(
|
106
|
+
Tool(
|
107
|
+
name=func.__name__,
|
108
|
+
description=func.__doc__,
|
109
|
+
func=func,
|
110
|
+
)
|
102
111
|
)
|
103
|
-
)
|
104
112
|
except Exception as e:
|
105
113
|
logger.warning(f"Error processing {file_path}: {e!s}")
|
106
114
|
return functions
|
@@ -139,9 +147,11 @@ def agent(
|
|
139
147
|
|
140
148
|
# Initialize functions array to store decorated functions
|
141
149
|
functions = get_functions(
|
150
|
+
client,
|
142
151
|
dir=settings.agent.functions_directory,
|
143
152
|
remote_functions_empty=not remote_functions,
|
144
153
|
)
|
154
|
+
|
145
155
|
settings.agent.functions = functions
|
146
156
|
|
147
157
|
if agent is not None:
|
beamlit/common/__init__.py
CHANGED
@@ -3,6 +3,7 @@ from .logger import init as init_logger
|
|
3
3
|
from .secrets import Secret
|
4
4
|
from .settings import Settings, get_settings, init, init_agent
|
5
5
|
from .utils import copy_folder
|
6
|
+
from .slugify import slugify
|
6
7
|
|
7
8
|
__all__ = [
|
8
9
|
"Secret",
|
@@ -13,4 +14,5 @@ __all__ = [
|
|
13
14
|
"copy_folder",
|
14
15
|
"init_logger",
|
15
16
|
"HTTPError",
|
17
|
+
"slugify"
|
16
18
|
]
|
beamlit/deploy/deploy.py
CHANGED
@@ -16,7 +16,7 @@ from beamlit.models import (
|
|
16
16
|
FunctionSpec,
|
17
17
|
Runtime,
|
18
18
|
)
|
19
|
-
|
19
|
+
from beamlit.common import slugify
|
20
20
|
from .format import arg_to_dict, format_agent_chain, format_parameters
|
21
21
|
from .parser import Resource, get_description, get_parameters, get_resources
|
22
22
|
|
@@ -24,8 +24,6 @@ sys.path.insert(0, os.getcwd())
|
|
24
24
|
sys.path.insert(0, os.path.join(os.getcwd(), "src"))
|
25
25
|
|
26
26
|
random_id = str(uuid.uuid4())[:8]
|
27
|
-
def slugify(name: str) -> str:
|
28
|
-
return name.lower().replace(" ", "-").replace("_", "-")
|
29
27
|
|
30
28
|
def get_runtime_image(type: str, name: str) -> str:
|
31
29
|
settings = get_settings()
|
beamlit/functions/decorator.py
CHANGED
@@ -1,64 +1,17 @@
|
|
1
1
|
"""Decorators for creating function tools with Beamlit and LangChain integration."""
|
2
2
|
|
3
|
+
import functools
|
3
4
|
import json
|
4
5
|
from collections.abc import Callable
|
5
6
|
from logging import getLogger
|
6
|
-
import functools
|
7
7
|
|
8
8
|
from fastapi import Request
|
9
|
-
from langchain_core.tools import create_schema_from_function
|
10
9
|
|
11
|
-
from beamlit.authentication import new_client
|
12
10
|
from beamlit.common.settings import get_settings
|
13
11
|
from beamlit.models import Function, FunctionKit
|
14
|
-
from beamlit.run import RunClient
|
15
12
|
|
16
13
|
logger = getLogger(__name__)
|
17
14
|
|
18
|
-
|
19
|
-
def get_remote_function(func: Callable, function: Function):
|
20
|
-
settings = get_settings()
|
21
|
-
name = (function and function.metadata and function.metadata.name) or func.__name__
|
22
|
-
|
23
|
-
def _partial(*args, **kwargs):
|
24
|
-
# Get function signature parameters
|
25
|
-
try:
|
26
|
-
client = new_client()
|
27
|
-
run_client = RunClient(client)
|
28
|
-
logger.debug(
|
29
|
-
f"Calling remote function: NAME={name}"
|
30
|
-
f" PARAMS={kwargs} ENVIRONMENT={settings.environment}"
|
31
|
-
)
|
32
|
-
response = run_client.run(
|
33
|
-
resource_type="function",
|
34
|
-
resource_name=name,
|
35
|
-
environment=settings.environment,
|
36
|
-
method="POST",
|
37
|
-
headers={"Content-Type": "application/json"},
|
38
|
-
data=json.dumps(kwargs),
|
39
|
-
)
|
40
|
-
content = response.text
|
41
|
-
if response.status_code >= 400:
|
42
|
-
content = f"{response.status_code}:{response.text}"
|
43
|
-
logger.error(f"Error calling remote function: {content}")
|
44
|
-
return f"Error calling remote function: {content}"
|
45
|
-
logger.debug(
|
46
|
-
f"Response from remote function: NAME={name}"
|
47
|
-
f" RESPONSE={content} ENVIRONMENT={settings.environment}"
|
48
|
-
)
|
49
|
-
if response.headers.get("content-type") == "application/json":
|
50
|
-
return response.json()
|
51
|
-
return content
|
52
|
-
except Exception as e:
|
53
|
-
logger.error(f"Error calling function {name}: {e}")
|
54
|
-
raise e
|
55
|
-
|
56
|
-
remote_func = _partial
|
57
|
-
remote_func.__name__ = func.__name__
|
58
|
-
remote_func.__doc__ = func.__doc__
|
59
|
-
return remote_func
|
60
|
-
|
61
|
-
|
62
15
|
def kit(bl_kit: FunctionKit = None, **kwargs: dict) -> Callable:
|
63
16
|
"""Create function tools with Beamlit and LangChain integration."""
|
64
17
|
|
@@ -83,16 +36,7 @@ def function(*args, function: Function | dict = None, kit=False, **kwargs: dict)
|
|
83
36
|
def wrapper(func: Callable) -> Callable:
|
84
37
|
if function and not func.__doc__ and function.spec and function.spec.description:
|
85
38
|
func.__doc__ = function.spec.description
|
86
|
-
|
87
|
-
remote_func = get_remote_function(func, function)
|
88
|
-
if not kwargs.get("args_schema"):
|
89
|
-
kwargs["args_schema"] = create_schema_from_function(
|
90
|
-
func.__name__,
|
91
|
-
func,
|
92
|
-
parse_docstring=func.__doc__,
|
93
|
-
)
|
94
|
-
return remote_func
|
95
|
-
|
39
|
+
|
96
40
|
@functools.wraps(func)
|
97
41
|
async def wrapped(*args, **kwargs):
|
98
42
|
if isinstance(args[0], Request):
|
@@ -7,7 +7,7 @@ beamlit/types.py,sha256=E1hhDh_zXfsSQ0NCt9-uw90_Mr5iIlsdfnfvxv5HarU,1005
|
|
7
7
|
beamlit/agents/__init__.py,sha256=nf1iwQwGtCG6nDqyVhxfWoqR6dv6X3bvSpCeqkTCFaM,101
|
8
8
|
beamlit/agents/chain.py,sha256=vfCjiFHuu02uTTGicxMlFzjyICQkIjpXrBGs-7uJEsg,2826
|
9
9
|
beamlit/agents/chat.py,sha256=gVyv4FGBdQTDhdutX8l64OUNa6Fdqaw4eCfEDRH0IPQ,3558
|
10
|
-
beamlit/agents/decorator.py,sha256=
|
10
|
+
beamlit/agents/decorator.py,sha256=5PnVu7G5a4kyK7P3h6QgHQXudOBhxl6EwK8FpxBRcjE,10297
|
11
11
|
beamlit/api/__init__.py,sha256=zTSiG_ujSjAqWPyc435YXaX9XTlpMjiJWBbV-f-YtdA,45
|
12
12
|
beamlit/api/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
beamlit/api/agents/create_agent.py,sha256=t5Pr62My2EhQlcIY71MrI73-0_q5Djr3a_Ybt9MIiQQ,3587
|
@@ -128,20 +128,21 @@ beamlit/authentication/authentication.py,sha256=ODQCc00RvCOZNaiGG5ctylNnE-JVCuge
|
|
128
128
|
beamlit/authentication/clientcredentials.py,sha256=cxZPPu--CgizwqX0pdfFQ91gJt1EFKwyy-aBB_dXX7I,3990
|
129
129
|
beamlit/authentication/credentials.py,sha256=p_1xenabCbQuRz7BiFk7oTK4uCxAt_zoyku5o-jcKGE,5343
|
130
130
|
beamlit/authentication/device_mode.py,sha256=tmr22gllKOZwBRub_QjF5pYa425x-nE8tQNpZ_EGR6g,3644
|
131
|
-
beamlit/common/__init__.py,sha256=
|
131
|
+
beamlit/common/__init__.py,sha256=4zSon2Pf7mSvTT8931UIb5Qb6xhlETa9lU9u92bkiL4,384
|
132
132
|
beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
|
133
133
|
beamlit/common/generate.py,sha256=LtdCju_QayRS4lZrrb_0VHqWWvTcv4Mbf-iV1TB_Qko,7522
|
134
134
|
beamlit/common/instrumentation.py,sha256=GVYeat7qCcqzDoKSYig3s8ZCC172R9JiQIr3Evv3kik,4293
|
135
135
|
beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
|
136
136
|
beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
|
137
137
|
beamlit/common/settings.py,sha256=_4oCVrJZOMaTZoK2Zzo2DWqtUyBsspuOH3iAJ_nU0tw,5923
|
138
|
+
beamlit/common/slugify.py,sha256=nR29r37IdWS2i44ZC6ZsXRgqKPYmvMGtFQ7BuIQUTlc,90
|
138
139
|
beamlit/common/utils.py,sha256=jouz5igBvT37Xn_e94-foCHyQczVim-UzVcoIF6RWJ4,657
|
139
140
|
beamlit/deploy/__init__.py,sha256=GS7l7Jtm2yKs7iNLKcfjYO-rAhUzggQ3xiYSf3oxLBY,91
|
140
|
-
beamlit/deploy/deploy.py,sha256=
|
141
|
+
beamlit/deploy/deploy.py,sha256=junQAo5zf9vC81cS6_6-0AOy4xRvvXlX710-kUK6hRE,9888
|
141
142
|
beamlit/deploy/format.py,sha256=PJ8kU7Y1pwiS3tqqyvFaag9LO3jju-4ua574163VPk4,1820
|
142
143
|
beamlit/deploy/parser.py,sha256=Ga0poCZkoRnuTw082QnTcNGCBJncoRAnVsn8-1FsaJE,6907
|
143
144
|
beamlit/functions/__init__.py,sha256=_RPG1Bfg54JGdIPnViAU6n9zD7E1cDNsdXi8oYGskzE,138
|
144
|
-
beamlit/functions/decorator.py,sha256=
|
145
|
+
beamlit/functions/decorator.py,sha256=5FnupXre0W-QN3ej5o7MZBRmTkxtwtPKIwmL031Szq4,1703
|
145
146
|
beamlit/functions/github/__init__.py,sha256=gYnUkeegukOfbymdabuuJkScvH-_ZJygX05BoqkPn0o,49
|
146
147
|
beamlit/functions/github/github.py,sha256=FajzLCNkpXcwfgnC0l9rOGT2eSPLCz8-qrMzK9N_ZNc,598
|
147
148
|
beamlit/functions/github/kit/__init__.py,sha256=jBwPqZv6C23_utukohxqXZwrlicNlI7PYPUj0Den7Cw,136
|
@@ -256,6 +257,6 @@ beamlit/serve/app.py,sha256=DXWxQoMeuA5FYvBMyLrP94OEWQbwLf4GZk3I9fkwSPA,3523
|
|
256
257
|
beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
|
257
258
|
beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
|
258
259
|
beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
|
259
|
-
beamlit-0.0.
|
260
|
-
beamlit-0.0.
|
261
|
-
beamlit-0.0.
|
260
|
+
beamlit-0.0.33rc46.dist-info/METADATA,sha256=lu9c9pPcGyUhuyS-y1rgrF7hzdae0LmL5NpOr3BrHSo,2405
|
261
|
+
beamlit-0.0.33rc46.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
262
|
+
beamlit-0.0.33rc46.dist-info/RECORD,,
|
File without changes
|