beamlit 0.0.33rc49__py3-none-any.whl → 0.0.34__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.
- beamlit/agents/__init__.py +2 -1
- beamlit/agents/chat.py +16 -4
- beamlit/agents/decorator.py +68 -155
- beamlit/agents/thread.py +14 -0
- beamlit/api/workspaces/workspace_quotas_request.py +97 -0
- beamlit/authentication/clientcredentials.py +5 -3
- beamlit/authentication/device_mode.py +4 -4
- beamlit/common/__init__.py +1 -2
- beamlit/common/instrumentation.py +202 -34
- beamlit/common/settings.py +7 -64
- beamlit/deploy/deploy.py +64 -60
- beamlit/deploy/format.py +10 -0
- beamlit/functions/__init__.py +2 -2
- beamlit/functions/decorator.py +149 -1
- beamlit/functions/github/github.py +0 -1
- beamlit/models/__init__.py +51 -11
- beamlit/models/agent.py +27 -15
- beamlit/models/agent_metadata.py +1 -1
- beamlit/models/agent_render.py +45 -0
- beamlit/models/agent_spec.py +32 -5
- beamlit/models/core_event.py +88 -0
- beamlit/models/core_spec.py +14 -5
- beamlit/models/core_spec_configurations.py +1 -1
- beamlit/models/core_status.py +3 -20
- beamlit/models/environment.py +2 -2
- beamlit/models/environment_metadata.py +1 -1
- beamlit/models/function.py +27 -15
- beamlit/models/function_metadata.py +1 -1
- beamlit/models/function_render.py +45 -0
- beamlit/models/function_spec.py +14 -5
- beamlit/models/histogram_bucket.py +79 -0
- beamlit/models/histogram_stats.py +88 -0
- beamlit/models/increase_and_rate_metric.py +0 -9
- beamlit/models/integration_connection.py +2 -2
- beamlit/models/integration_connection_spec.py +11 -2
- beamlit/models/integration_repository.py +88 -0
- beamlit/models/last_n_requests_metric.py +88 -0
- beamlit/models/latency_metric.py +124 -0
- beamlit/models/metadata.py +1 -1
- beamlit/models/metric.py +18 -9
- beamlit/models/metrics.py +81 -46
- beamlit/models/metrics_models.py +45 -0
- beamlit/models/metrics_request_total_per_code.py +45 -0
- beamlit/models/metrics_rps_per_code.py +45 -0
- beamlit/models/model.py +27 -15
- beamlit/models/model_metadata.py +1 -1
- beamlit/models/model_provider.py +2 -2
- beamlit/models/model_render.py +45 -0
- beamlit/models/model_spec.py +14 -14
- beamlit/models/pending_invitation_accept.py +1 -1
- beamlit/models/pending_invitation_render.py +3 -3
- beamlit/models/policy.py +2 -2
- beamlit/models/provider_config.py +1 -1
- beamlit/models/repository.py +70 -0
- beamlit/models/repository_type_0.py +70 -0
- beamlit/models/request_duration_over_time_metric.py +97 -0
- beamlit/models/request_duration_over_time_metrics.py +74 -0
- beamlit/models/request_total_by_origin_metric.py +103 -0
- beamlit/models/request_total_by_origin_metric_request_total_by_origin.py +45 -0
- beamlit/models/request_total_by_origin_metric_request_total_by_origin_and_code.py +45 -0
- beamlit/models/request_total_metric.py +115 -0
- beamlit/models/request_total_metric_request_total_per_code.py +45 -0
- beamlit/models/request_total_metric_rps_per_code.py +45 -0
- beamlit/models/resource_deployment_metrics.py +6 -4
- beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code.py +1 -1
- beamlit/models/resource_environment_metrics.py +155 -75
- beamlit/models/resource_environment_metrics_request_total_per_code.py +45 -0
- beamlit/models/resource_environment_metrics_rps_per_code.py +45 -0
- beamlit/models/resource_metrics.py +1 -1
- beamlit/models/runtime.py +2 -2
- beamlit/models/store_agent.py +1 -1
- beamlit/models/store_function.py +1 -1
- beamlit/models/token_rate_metric.py +88 -0
- beamlit/models/token_rate_metrics.py +106 -0
- beamlit/models/token_total_metric.py +106 -0
- beamlit/models/workspace.py +17 -8
- beamlit/serve/app.py +9 -13
- {beamlit-0.0.33rc49.dist-info → beamlit-0.0.34.dist-info}/METADATA +21 -3
- {beamlit-0.0.33rc49.dist-info → beamlit-0.0.34.dist-info}/RECORD +80 -52
- beamlit/common/generate.py +0 -196
- {beamlit-0.0.33rc49.dist-info → beamlit-0.0.34.dist-info}/WHEEL +0 -0
beamlit/common/generate.py
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
from typing import Tuple
|
2
|
-
|
3
|
-
from beamlit.common.settings import Settings, get_settings
|
4
|
-
from beamlit.models import Agent, Function, FunctionMetadata, FunctionSpec
|
5
|
-
from beamlit.models.function_kit import FunctionKit
|
6
|
-
|
7
|
-
|
8
|
-
def get_titles_name(name: str) -> str:
|
9
|
-
return name.title().replace("-", "").replace("_", "")
|
10
|
-
|
11
|
-
|
12
|
-
def generate_kit_function_code(
|
13
|
-
settings: Settings, function: Function, kit: FunctionKit
|
14
|
-
) -> Tuple[str, str]:
|
15
|
-
export_code = ""
|
16
|
-
code = ""
|
17
|
-
for kit in kit:
|
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
|
31
|
-
)
|
32
|
-
code += new_code
|
33
|
-
export_code += export
|
34
|
-
return code, export_code
|
35
|
-
|
36
|
-
|
37
|
-
def generate_function_code(
|
38
|
-
settings: Settings,
|
39
|
-
function: Function,
|
40
|
-
force_name_in_endpoint: str = "",
|
41
|
-
kit: bool = False,
|
42
|
-
) -> Tuple[str, str]:
|
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)
|
46
|
-
args_list += ", "
|
47
|
-
else:
|
48
|
-
args_list = ""
|
49
|
-
args_schema = ""
|
50
|
-
if function.spec.parameters:
|
51
|
-
for param in function.spec.parameters:
|
52
|
-
args_schema += f'{param.name}: str = Field(description="""{param.description}""")\n '
|
53
|
-
if len(args_schema) == 0:
|
54
|
-
args_schema = "pass"
|
55
|
-
|
56
|
-
# TODO: add return direct in function configuration
|
57
|
-
return_direct = False
|
58
|
-
endpoint_name = force_name_in_endpoint or function.metadata.name
|
59
|
-
body = "{}"
|
60
|
-
if function.spec.parameters:
|
61
|
-
body = f'{", ".join(f'"{param.name}": {param.name}' for param in function.spec.parameters)}'
|
62
|
-
if kit is True:
|
63
|
-
has_name = False
|
64
|
-
if function.spec.parameters:
|
65
|
-
for param in function.spec.parameters:
|
66
|
-
if param.name == "name":
|
67
|
-
has_name = True
|
68
|
-
break
|
69
|
-
if not has_name:
|
70
|
-
if len(body) > 0:
|
71
|
-
body += ", "
|
72
|
-
body += f'"name": "{function.metadata.name}"'
|
73
|
-
return (
|
74
|
-
f'''
|
75
|
-
|
76
|
-
class Beamlit{name}Input(BaseModel):
|
77
|
-
{args_schema}
|
78
|
-
|
79
|
-
class Beamlit{name}(BaseTool):
|
80
|
-
name: str = "beamlit_{function.metadata.name.replace("-", "_")}"
|
81
|
-
description: str = """{function.spec.description}"""
|
82
|
-
args_schema: Type[BaseModel] = Beamlit{name}Input
|
83
|
-
|
84
|
-
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
85
|
-
return_direct: bool = {return_direct}
|
86
|
-
|
87
|
-
def _run(self, {args_list} run_manager: Optional[CallbackManagerForToolRun] = None) -> Tuple[Union[List[Dict[str, str]], str], Dict]:
|
88
|
-
try:
|
89
|
-
params = self.metadata.get("params", {{}})
|
90
|
-
response = run_client.run("function", "{endpoint_name}", settings.environment, "POST", json={{{body}}})
|
91
|
-
if response.status_code >= 400:
|
92
|
-
logger.error(f"Failed to run function {name}, {{response.status_code}}::{{response.text}}")
|
93
|
-
raise Exception(f"Failed to run function {name}, {{response.status_code}}::{{response.text}}")
|
94
|
-
return response.json(), {{}}
|
95
|
-
except Exception as e:
|
96
|
-
return repr(e), {{}}
|
97
|
-
''',
|
98
|
-
f"Beamlit{get_titles_name(function.metadata.name)},",
|
99
|
-
)
|
100
|
-
|
101
|
-
|
102
|
-
def generate_chain_code(settings: Settings, agent: Agent) -> Tuple[str, str]:
|
103
|
-
name = get_titles_name(agent.metadata.name)
|
104
|
-
# TODO: add return direct in agent configuration
|
105
|
-
return_direct = False
|
106
|
-
return (
|
107
|
-
f'''
|
108
|
-
class BeamlitChain{name}Input(BaseModel):
|
109
|
-
input: str = Field(description='{agent.spec.description}')
|
110
|
-
|
111
|
-
class BeamlitChain{name}(BaseTool):
|
112
|
-
name: str = "beamlit_chain_{agent.metadata.name.replace("-", "_")}"
|
113
|
-
description: str = """{agent.spec.description}"""
|
114
|
-
args_schema: Type[BaseModel] = BeamlitChain{name}Input
|
115
|
-
|
116
|
-
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
117
|
-
return_direct: bool = {return_direct}
|
118
|
-
|
119
|
-
def _run(
|
120
|
-
self,
|
121
|
-
input: str,
|
122
|
-
run_manager: Optional[CallbackManagerForToolRun] = None,
|
123
|
-
) -> Tuple[Union[List[Dict[str, str]], str], Dict]:
|
124
|
-
try:
|
125
|
-
params = self.metadata.get("params", {{}})
|
126
|
-
response = run_client.run("agent", "{agent.metadata.name}", settings.environment, "POST", json={{"input": input}})
|
127
|
-
if response.status_code >= 400:
|
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}}")
|
130
|
-
if response.headers.get("Content-Type") == "application/json":
|
131
|
-
return response.json(), {{}}
|
132
|
-
else:
|
133
|
-
return response.text, {{}}
|
134
|
-
except Exception as e:
|
135
|
-
return repr(e), {{}}
|
136
|
-
''',
|
137
|
-
f"BeamlitChain{name},",
|
138
|
-
)
|
139
|
-
|
140
|
-
|
141
|
-
def generate(destination: str, dry_run: bool = False):
|
142
|
-
imports = """from logging import getLogger
|
143
|
-
from typing import Dict, List, Literal, Optional, Tuple, Type, Union
|
144
|
-
|
145
|
-
from langchain_core.callbacks import CallbackManagerForToolRun
|
146
|
-
from langchain_core.tools import BaseTool
|
147
|
-
from pydantic import BaseModel, Field
|
148
|
-
from beamlit.authentication import (RunClientWithCredentials,
|
149
|
-
load_credentials_from_settings,
|
150
|
-
new_client_with_credentials)
|
151
|
-
from beamlit.common.settings import get_settings
|
152
|
-
from beamlit.run import RunClient
|
153
|
-
|
154
|
-
logger = getLogger(__name__)
|
155
|
-
settings = get_settings()
|
156
|
-
credentials = load_credentials_from_settings(settings)
|
157
|
-
|
158
|
-
client_config = RunClientWithCredentials(
|
159
|
-
credentials=credentials,
|
160
|
-
workspace=settings.workspace,
|
161
|
-
)
|
162
|
-
client = new_client_with_credentials(client_config)
|
163
|
-
run_client = RunClient(client=client)
|
164
|
-
"""
|
165
|
-
settings = get_settings()
|
166
|
-
export_code = "\n\nfunctions = ["
|
167
|
-
export_chain = "\n\nchains = ["
|
168
|
-
code = imports
|
169
|
-
if settings.agent.functions and len(settings.agent.functions) > 0:
|
170
|
-
for function_config in settings.agent.functions:
|
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
|
-
)
|
175
|
-
code += new_code
|
176
|
-
export_code += export
|
177
|
-
else:
|
178
|
-
new_code, export = generate_function_code(settings, function_config)
|
179
|
-
code += new_code
|
180
|
-
export_code += export
|
181
|
-
if settings.agent.chain and len(settings.agent.chain) > 0:
|
182
|
-
for agent in settings.agent.chain:
|
183
|
-
new_code, export = generate_chain_code(settings, agent)
|
184
|
-
code += new_code
|
185
|
-
export_chain += export
|
186
|
-
if settings.agent.functions and len(settings.agent.functions) > 0:
|
187
|
-
export_code = export_code[:-1]
|
188
|
-
export_code += "]"
|
189
|
-
if settings.agent.chain and len(settings.agent.chain) > 0:
|
190
|
-
export_chain = export_chain[:-1]
|
191
|
-
export_chain += "]"
|
192
|
-
content = code + export_code + export_chain
|
193
|
-
if not dry_run:
|
194
|
-
with open(destination, "w") as f:
|
195
|
-
f.write(content)
|
196
|
-
return content
|
File without changes
|