beamlit 0.0.24rc20__py3-none-any.whl → 0.0.24rc21__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- beamlit/agents/chat.py +37 -11
- beamlit/agents/decorator.py +97 -65
- beamlit/api/agents/create_agent.py +9 -14
- beamlit/api/agents/delete_agent.py +22 -1
- beamlit/api/agents/delete_agent_history.py +2 -6
- beamlit/api/agents/get_agent.py +22 -1
- beamlit/api/agents/get_agent_environment_logs.py +11 -11
- beamlit/api/agents/get_agent_history.py +2 -6
- beamlit/api/agents/get_agent_metrics.py +22 -1
- beamlit/api/agents/list_agent_history.py +11 -11
- beamlit/api/agents/list_agents.py +36 -4
- beamlit/api/agents/put_agent_history.py +2 -6
- beamlit/api/agents/update_agent.py +9 -14
- beamlit/api/functions/create_function.py +9 -14
- beamlit/api/functions/delete_function.py +22 -1
- beamlit/api/functions/get_function.py +22 -1
- beamlit/api/functions/get_function_environment_logs.py +11 -11
- beamlit/api/functions/get_function_metrics.py +22 -1
- beamlit/api/functions/list_functions.py +36 -4
- beamlit/api/functions/update_function.py +9 -14
- beamlit/api/history/get_agents_history.py +12 -12
- beamlit/api/history/list_agents_history.py +12 -12
- beamlit/api/integrations/get_integration_connection.py +16 -12
- beamlit/api/integrations/get_integration_connection_model.py +8 -1
- beamlit/api/integrations/get_integration_model.py +8 -1
- beamlit/api/locations/list_locations.py +12 -12
- beamlit/api/models/create_model.py +13 -14
- beamlit/api/models/delete_model.py +22 -1
- beamlit/api/models/get_model.py +22 -1
- beamlit/api/models/get_model_environment_logs.py +11 -11
- beamlit/api/models/get_model_metrics.py +38 -13
- beamlit/api/models/list_models.py +36 -4
- beamlit/api/models/update_model.py +13 -14
- beamlit/api/privateclusters/__init__.py +0 -0
- beamlit/api/{agents/get_agent_deployment_metrics.py → privateclusters/create_private_cluster.py} +28 -55
- beamlit/api/{functions/list_function_deployments.py → privateclusters/delete_private_cluster.py} +38 -37
- beamlit/api/{agents/get_agent_deployment.py → privateclusters/get_private_cluster.py} +40 -44
- beamlit/api/privateclusters/get_private_cluster_health.py +97 -0
- beamlit/api/{agents/list_agent_deployments.py → privateclusters/list_private_clusters.py} +30 -45
- beamlit/api/{models/list_model_deployments.py → privateclusters/update_private_cluster.py} +38 -45
- beamlit/api/privateclusters/update_private_cluster_health.py +97 -0
- beamlit/authentication/device_mode.py +3 -9
- beamlit/common/generate.py +47 -34
- beamlit/common/settings.py +29 -27
- beamlit/deploy/deploy.py +101 -342
- beamlit/deploy/format.py +70 -0
- beamlit/deploy/parser.py +175 -0
- beamlit/functions/decorator.py +8 -11
- beamlit/models/__init__.py +64 -78
- beamlit/models/acl.py +4 -22
- beamlit/models/agent.py +34 -95
- beamlit/models/agent_history.py +7 -5
- beamlit/models/agent_history_event.py +11 -9
- beamlit/models/agent_metadata.py +5 -3
- beamlit/models/agent_spec.py +54 -45
- beamlit/models/api_key.py +14 -14
- beamlit/models/configuration.py +11 -0
- beamlit/models/core_spec.py +45 -32
- beamlit/models/{model_deployment_metrics_query_per_second_per_region_per_code.py → core_spec_configurations.py} +22 -22
- beamlit/models/environment.py +33 -105
- beamlit/models/environment_metadata.py +146 -0
- beamlit/models/environment_spec.py +8 -6
- beamlit/models/function.py +34 -95
- beamlit/models/function_metadata.py +5 -3
- beamlit/models/function_spec.py +53 -40
- beamlit/models/integration_connection.py +31 -137
- beamlit/models/integration_connection_spec.py +6 -4
- beamlit/models/metadata.py +5 -3
- beamlit/models/metadata_labels.py +4 -2
- beamlit/models/model.py +33 -94
- beamlit/models/model_metadata.py +5 -3
- beamlit/models/{function_provider_ref.py → model_private_cluster.py} +23 -14
- beamlit/models/model_provider.py +27 -43
- beamlit/models/model_spec.py +45 -32
- beamlit/models/owner_fields.py +4 -2
- beamlit/models/pending_invitation.py +14 -14
- beamlit/models/pod_template_spec.py +4 -2
- beamlit/models/policy.py +33 -159
- beamlit/models/policy_spec.py +24 -28
- beamlit/models/private_cluster.py +183 -0
- beamlit/models/{model_provider_ref.py → private_location.py} +7 -16
- beamlit/models/resource_deployment_metrics.py +0 -108
- beamlit/models/resource_environment_metrics.py +143 -71
- beamlit/models/{resource_deployment_metrics_inference_per_region.py → resource_environment_metrics_inference_per_region.py} +5 -5
- beamlit/models/resource_environment_metrics_inference_per_second_per_region.py +9 -11
- beamlit/models/{resource_deployment_metrics_query_per_region_per_code.py → resource_environment_metrics_query_per_region_per_code.py} +5 -5
- beamlit/models/resource_environment_metrics_query_per_second_per_region_per_code.py +5 -3
- beamlit/models/resource_log.py +4 -2
- beamlit/models/runtime.py +20 -2
- beamlit/models/serverless_config.py +28 -21
- beamlit/models/spec_configuration.py +7 -5
- beamlit/models/store_agent.py +14 -14
- beamlit/models/store_function.py +14 -14
- beamlit/models/time_fields.py +4 -2
- beamlit/models/websocket_channel.py +4 -2
- beamlit/models/workspace.py +23 -14
- beamlit/run.py +0 -1
- beamlit/serve/app.py +1 -0
- beamlit/serve/middlewares/accesslog.py +3 -1
- {beamlit-0.0.24rc20.dist-info → beamlit-0.0.24rc21.dist-info}/METADATA +1 -1
- beamlit-0.0.24rc21.dist-info/RECORD +243 -0
- beamlit/api/agents/delete_agent_deployment.py +0 -163
- beamlit/api/agents/delete_agent_deployment_history.py +0 -172
- beamlit/api/agents/get_agent_deployment_history.py +0 -172
- beamlit/api/agents/get_agent_deployment_logs.py +0 -164
- beamlit/api/agents/list_agent_deployment_history.py +0 -164
- beamlit/api/agents/put_agent_deployment.py +0 -185
- beamlit/api/agents/put_agent_deployment_history.py +0 -198
- beamlit/api/functions/delete_function_deployment.py +0 -163
- beamlit/api/functions/get_function_deployment.py +0 -163
- beamlit/api/functions/get_function_deployment_logs.py +0 -164
- beamlit/api/functions/get_function_deployment_metrics.py +0 -159
- beamlit/api/functions/put_function_deployment.py +0 -185
- beamlit/api/models/delete_model_deployment.py +0 -171
- beamlit/api/models/get_model_deployment.py +0 -171
- beamlit/api/models/get_model_deployment_logs.py +0 -168
- beamlit/api/models/get_model_deployment_metrics.py +0 -163
- beamlit/api/models/put_model_deployment.py +0 -193
- beamlit/models/agent_configuration.py +0 -70
- beamlit/models/agent_deployment.py +0 -340
- beamlit/models/agent_deployment_configuration.py +0 -45
- beamlit/models/agent_deployment_configuration_type_0.py +0 -43
- beamlit/models/agent_deployment_history.py +0 -185
- beamlit/models/agent_deployment_history_event.py +0 -133
- beamlit/models/agent_deployment_pod_template.py +0 -45
- beamlit/models/agent_deployment_pod_template_type_0.py +0 -43
- beamlit/models/agent_with_deployments.py +0 -176
- beamlit/models/authentication_provider_model.py +0 -144
- beamlit/models/authentication_provider_organization.py +0 -88
- beamlit/models/deployment_configuration.py +0 -70
- beamlit/models/deployment_configurations.py +0 -58
- beamlit/models/deployment_serverless_config.py +0 -131
- beamlit/models/deployment_serverless_config_type_0.py +0 -220
- beamlit/models/function_configuration.py +0 -70
- beamlit/models/function_deployment.py +0 -340
- beamlit/models/function_deployment_configuration.py +0 -45
- beamlit/models/function_deployment_configuration_type_0.py +0 -43
- beamlit/models/function_deployment_pod_template.py +0 -45
- beamlit/models/function_deployment_pod_template_type_0.py +0 -43
- beamlit/models/function_with_deployments.py +0 -176
- beamlit/models/integration.py +0 -198
- beamlit/models/integration_config.py +0 -45
- beamlit/models/integration_secret.py +0 -61
- beamlit/models/labels_type_0.py +0 -45
- beamlit/models/location.py +0 -122
- beamlit/models/model_deployment.py +0 -296
- beamlit/models/model_deployment_log.py +0 -70
- beamlit/models/model_deployment_metrics.py +0 -172
- beamlit/models/model_deployment_metrics_inference_per_second_per_region.py +0 -77
- beamlit/models/model_deployment_pod_template.py +0 -45
- beamlit/models/model_deployment_pod_template_type_0.py +0 -43
- beamlit/models/model_metrics.py +0 -96
- beamlit/models/model_with_deployments.py +0 -176
- beamlit/models/resource_deployment_log.py +0 -70
- beamlit/models/resource_deployment_metrics_inference_per_region_type_0.py +0 -79
- beamlit/models/resource_deployment_metrics_inference_per_second_per_region_type_0.py +0 -79
- beamlit/models/resource_deployment_metrics_query_per_region_per_code_type_0.py +0 -73
- beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code_type_0.py +0 -73
- beamlit/models/runtime_readiness_probe_type_0.py +0 -43
- beamlit/models/runtime_type_0.py +0 -111
- beamlit/models/runtime_type_0_readiness_probe.py +0 -43
- beamlit/models/runtime_type_0_readiness_probe_type_0.py +0 -43
- beamlit/models/runtime_type_0_resources.py +0 -59
- beamlit/models/standard_fields_dynamo_db.py +0 -88
- beamlit/models/store_agent_configuration.py +0 -97
- beamlit/models/store_agent_labels_type_0.py +0 -43
- beamlit/models/store_function_configuration.py +0 -97
- beamlit/models/store_function_labels_type_0.py +0 -43
- beamlit-0.0.24rc20.dist-info/RECORD +0 -303
- {beamlit-0.0.24rc20.dist-info → beamlit-0.0.24rc21.dist-info}/WHEEL +0 -0
beamlit/common/generate.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
from typing import Tuple
|
2
2
|
|
3
3
|
from beamlit.common.settings import Settings, get_settings
|
4
|
-
from beamlit.models
|
5
|
-
from beamlit.models.function_deployment import FunctionDeployment
|
4
|
+
from beamlit.models import Agent, Function, FunctionMetadata, FunctionSpec
|
6
5
|
from beamlit.models.function_kit import FunctionKit
|
7
6
|
|
8
7
|
|
@@ -10,55 +9,67 @@ def get_titles_name(name: str) -> str:
|
|
10
9
|
return name.title().replace("-", "").replace("_", "")
|
11
10
|
|
12
11
|
|
13
|
-
def generate_kit_function_code(
|
12
|
+
def generate_kit_function_code(
|
13
|
+
settings: Settings, function: Function, kit: FunctionKit
|
14
|
+
) -> Tuple[str, str]:
|
14
15
|
export_code = ""
|
15
16
|
code = ""
|
16
17
|
for kit in kit:
|
17
|
-
fn =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
fn = Function(
|
19
|
+
metadata=FunctionMetadata(
|
20
|
+
name=kit.name,
|
21
|
+
workspace=settings.workspace,
|
22
|
+
environment=settings.environment,
|
23
|
+
),
|
24
|
+
spec=FunctionSpec(
|
25
|
+
parameters=kit.parameters,
|
26
|
+
description=kit.description,
|
27
|
+
),
|
28
|
+
)
|
29
|
+
new_code, export = generate_function_code(
|
30
|
+
settings, fn, force_name_in_endpoint=function.metadata.name, kit=True
|
22
31
|
)
|
23
|
-
new_code, export = generate_function_code(settings, fn, force_name_in_endpoint=function.function, kit=True)
|
24
32
|
code += new_code
|
25
33
|
export_code += export
|
26
34
|
return code, export_code
|
27
35
|
|
28
36
|
|
29
37
|
def generate_function_code(
|
30
|
-
settings: Settings,
|
38
|
+
settings: Settings,
|
39
|
+
function: Function,
|
40
|
+
force_name_in_endpoint: str = "",
|
41
|
+
kit: bool = False,
|
31
42
|
) -> Tuple[str, str]:
|
32
|
-
name = get_titles_name(function.
|
33
|
-
if function.parameters and len(function.parameters) > 0:
|
34
|
-
args_list = ", ".join(f"{param.name}: str" for param in function.parameters)
|
43
|
+
name = get_titles_name(function.metadata.name)
|
44
|
+
if function.spec.parameters and len(function.spec.parameters) > 0:
|
45
|
+
args_list = ", ".join(f"{param.name}: str" for param in function.spec.parameters)
|
35
46
|
args_list += ", "
|
36
47
|
else:
|
37
48
|
args_list = ""
|
38
49
|
args_schema = ""
|
39
|
-
if function.parameters:
|
40
|
-
for param in function.parameters:
|
50
|
+
if function.spec.parameters:
|
51
|
+
for param in function.spec.parameters:
|
41
52
|
args_schema += f'{param.name}: str = Field(description="""{param.description}""")\n '
|
42
53
|
if len(args_schema) == 0:
|
43
54
|
args_schema = "pass"
|
44
55
|
|
45
56
|
# TODO: add return direct in function configuration
|
46
57
|
return_direct = False
|
47
|
-
endpoint_name = force_name_in_endpoint or function.
|
58
|
+
endpoint_name = force_name_in_endpoint or function.metadata.name
|
48
59
|
body = "{}"
|
49
|
-
if function.parameters:
|
50
|
-
body = f'{", ".join(f'"{param.name}": {param.name}' for param in function.parameters)}'
|
60
|
+
if function.spec.parameters:
|
61
|
+
body = f'{", ".join(f'"{param.name}": {param.name}' for param in function.spec.parameters)}'
|
51
62
|
if kit is True:
|
52
63
|
has_name = False
|
53
|
-
if function.parameters:
|
54
|
-
for param in function.parameters:
|
64
|
+
if function.spec.parameters:
|
65
|
+
for param in function.spec.parameters:
|
55
66
|
if param.name == "name":
|
56
67
|
has_name = True
|
57
68
|
break
|
58
69
|
if not has_name:
|
59
70
|
if len(body) > 0:
|
60
71
|
body += ", "
|
61
|
-
body += f'"name": "{function.
|
72
|
+
body += f'"name": "{function.metadata.name}"'
|
62
73
|
return (
|
63
74
|
f'''
|
64
75
|
|
@@ -66,8 +77,8 @@ class Beamlit{name}Input(BaseModel):
|
|
66
77
|
{args_schema}
|
67
78
|
|
68
79
|
class Beamlit{name}(BaseTool):
|
69
|
-
name: str = "beamlit_{function.
|
70
|
-
description: str = """{function.description}"""
|
80
|
+
name: str = "beamlit_{function.metadata.name.replace("-", "_")}"
|
81
|
+
description: str = """{function.spec.description}"""
|
71
82
|
args_schema: Type[BaseModel] = Beamlit{name}Input
|
72
83
|
|
73
84
|
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
@@ -84,22 +95,22 @@ class Beamlit{name}(BaseTool):
|
|
84
95
|
except Exception as e:
|
85
96
|
return repr(e), {{}}
|
86
97
|
''',
|
87
|
-
f"Beamlit{get_titles_name(function.
|
98
|
+
f"Beamlit{get_titles_name(function.metadata.name)},",
|
88
99
|
)
|
89
100
|
|
90
101
|
|
91
|
-
def generate_chain_code(settings: Settings, agent:
|
92
|
-
name = get_titles_name(agent.
|
102
|
+
def generate_chain_code(settings: Settings, agent: Agent) -> Tuple[str, str]:
|
103
|
+
name = get_titles_name(agent.metadata.name)
|
93
104
|
# TODO: add return direct in agent configuration
|
94
105
|
return_direct = False
|
95
106
|
return (
|
96
107
|
f'''
|
97
108
|
class BeamlitChain{name}Input(BaseModel):
|
98
|
-
input: str = Field(description='{agent.description}')
|
109
|
+
input: str = Field(description='{agent.spec.description}')
|
99
110
|
|
100
111
|
class BeamlitChain{name}(BaseTool):
|
101
|
-
name: str = "beamlit_chain_{agent.
|
102
|
-
description: str = """{agent.description}"""
|
112
|
+
name: str = "beamlit_chain_{agent.metadata.name.replace("-", "_")}"
|
113
|
+
description: str = """{agent.spec.description}"""
|
103
114
|
args_schema: Type[BaseModel] = BeamlitChain{name}Input
|
104
115
|
|
105
116
|
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
@@ -112,10 +123,10 @@ class BeamlitChain{name}(BaseTool):
|
|
112
123
|
) -> Tuple[Union[List[Dict[str, str]], str], Dict]:
|
113
124
|
try:
|
114
125
|
params = self.metadata.get("params", {{}})
|
115
|
-
response = run_client.run("agent", "{agent.
|
126
|
+
response = run_client.run("agent", "{agent.metadata.name}", settings.environment, "POST", json={{"input": input}})
|
116
127
|
if response.status_code >= 400:
|
117
|
-
logger.error(f"Failed to run tool {agent.
|
118
|
-
raise Exception(f"Failed to run tool {agent.
|
128
|
+
logger.error(f"Failed to run tool {agent.metadata.name}, {{response.status_code}}::{{response.text}}")
|
129
|
+
raise Exception(f"Failed to run tool {agent.metadata.name}, {{response.status_code}}::{{response.text}}")
|
119
130
|
if response.headers.get("Content-Type") == "application/json":
|
120
131
|
return response.json(), {{}}
|
121
132
|
else:
|
@@ -157,8 +168,10 @@ run_client = RunClient(client=client)
|
|
157
168
|
code = imports
|
158
169
|
if settings.agent.functions and len(settings.agent.functions) > 0:
|
159
170
|
for function_config in settings.agent.functions:
|
160
|
-
if function_config.kit and len(function_config.kit) > 0:
|
161
|
-
new_code, export = generate_kit_function_code(
|
171
|
+
if function_config.spec.kit and len(function_config.spec.kit) > 0:
|
172
|
+
new_code, export = generate_kit_function_code(
|
173
|
+
settings, function_config, function_config.spec.kit
|
174
|
+
)
|
162
175
|
code += new_code
|
163
176
|
export_code += export
|
164
177
|
else:
|
beamlit/common/settings.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
import os
|
2
2
|
from logging import getLogger
|
3
|
-
from typing import
|
3
|
+
from typing import Tuple, Type, Union
|
4
4
|
|
5
|
-
from beamlit.api.
|
6
|
-
from beamlit.api.
|
5
|
+
from beamlit.api.agents import get_agent
|
6
|
+
from beamlit.api.functions import get_function
|
7
|
+
from beamlit.api.models import get_model
|
7
8
|
from beamlit.client import AuthenticatedClient
|
8
9
|
from beamlit.common.logger import init as init_logger
|
9
|
-
from beamlit.models
|
10
|
-
from beamlit.models.function_deployment import FunctionDeployment
|
11
|
-
from beamlit.models.model_deployment import ModelDeployment
|
10
|
+
from beamlit.models import Agent, Function, Model
|
12
11
|
from beamlit.types import UNSET, Unset
|
13
12
|
from langchain_core.language_models.chat_models import BaseChatModel
|
14
13
|
from langgraph.graph.graph import CompiledGraph
|
@@ -26,9 +25,9 @@ def get_settings():
|
|
26
25
|
|
27
26
|
class SettingsAgent(BaseSettings):
|
28
27
|
agent: Union[None, CompiledGraph, BaseChatModel] = None
|
29
|
-
chain: Union[Unset,
|
30
|
-
model: Union[Unset,
|
31
|
-
functions: Union[Unset,
|
28
|
+
chain: Union[Unset, list[Agent]] = UNSET
|
29
|
+
model: Union[Unset, Model] = UNSET
|
30
|
+
functions: Union[Unset, list[Function]] = UNSET
|
32
31
|
functions_directory: str = Field(default="src/functions")
|
33
32
|
chat_model: Union[None, BaseChatModel] = None
|
34
33
|
module: str = Field(default="main.main")
|
@@ -106,26 +105,29 @@ def init_agent(
|
|
106
105
|
name = settings.name
|
107
106
|
env = settings.environment
|
108
107
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
108
|
+
agent = get_agent.sync(name, environment=env, client=client)
|
109
|
+
if not agent:
|
110
|
+
raise ValueError(f"Agent {name} not found")
|
111
|
+
functions: list[Function] = []
|
112
|
+
agents_chain: list[Agent] = []
|
113
|
+
if agent.spec.functions:
|
114
|
+
for function in agent.spec.functions:
|
115
|
+
function = get_function.sync(function, environment=env, client=client)
|
116
|
+
if function:
|
117
|
+
functions.append(function)
|
118
|
+
settings.agent.functions = functions
|
119
|
+
|
120
|
+
if agent.spec.agent_chain:
|
121
|
+
for chain in agent.spec.agent_chain:
|
120
122
|
if chain.enabled:
|
121
|
-
|
123
|
+
agent_chain = get_agent.sync(chain.name, environment=env, client=client)
|
122
124
|
if chain.description:
|
123
|
-
|
124
|
-
|
125
|
-
settings.agent.chain =
|
126
|
-
if
|
127
|
-
|
128
|
-
settings.agent.model =
|
125
|
+
agent_chain.spec.description = chain.description
|
126
|
+
agents_chain.append(agent_chain)
|
127
|
+
settings.agent.chain = agents_chain
|
128
|
+
if agent.spec.model:
|
129
|
+
model = get_model.sync(agent.spec.model, environment=env, client=client)
|
130
|
+
settings.agent.model = model
|
129
131
|
|
130
132
|
content_generate = generate(destination, dry_run=True)
|
131
133
|
compared_content = None
|