beamlit 0.0.34rc59__py3-none-any.whl → 0.0.34rc61__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.
@@ -125,7 +125,7 @@ def instrument_app(app: FastAPI):
125
125
  meter = metrics.get_meter(__name__)
126
126
 
127
127
  if not isinstance(_logs.get_logger_provider(), LoggerProvider):
128
- logger_provider = LoggerProvider()
128
+ logger_provider = LoggerProvider(resource=resource)
129
129
  set_logger_provider(logger_provider)
130
130
  logger_provider.add_log_record_processor(
131
131
  BatchLogRecordProcessor(get_log_exporter())
beamlit/deploy/deploy.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import ast
2
2
  import json
3
3
  import os
4
+ import shutil
4
5
  import sys
5
- import uuid
6
+ from pathlib import Path
7
+ import yaml
6
8
  from logging import getLogger
7
9
  from typing import Literal
8
10
 
@@ -15,26 +17,17 @@ from beamlit.models import (
15
17
  Flavor,
16
18
  Function,
17
19
  FunctionSpec,
18
- Runtime,
20
+ MetadataLabels,
19
21
  )
20
-
21
- from .format import arg_to_dict, format_agent_chain, format_parameters
22
+ from beamlit.api.agents import get_agent
23
+ from beamlit.authentication import new_client
24
+ from beamlit.client import AuthenticatedClient
25
+ from .format import arg_to_dict
22
26
  from .parser import Resource, get_description, get_parameters, get_resources
23
27
 
24
28
  sys.path.insert(0, os.getcwd())
25
29
  sys.path.insert(0, os.path.join(os.getcwd(), "src"))
26
30
 
27
- random_id = str(uuid.uuid4())[:8]
28
-
29
- def get_runtime_image(type: str, name: str) -> str:
30
- settings = get_settings()
31
- registry_url = settings.registry_url.replace("https://", "").replace("http://", "")
32
- image = f"{registry_url}/{settings.workspace}/{type}s/{name}"
33
- # Generate a random ID to ensure unique image tags
34
- image = f"{image}:{random_id}"
35
- return image
36
-
37
-
38
31
  def set_default_values(resource: Resource, deployment: Agent | Function):
39
32
  settings = get_settings()
40
33
  deployment.metadata.workspace = settings.workspace
@@ -45,10 +38,6 @@ def set_default_values(resource: Resource, deployment: Agent | Function):
45
38
  deployment.metadata.display_name = deployment.metadata.name
46
39
  if not deployment.spec.description:
47
40
  deployment.spec.description = get_description(None, resource)
48
- if not deployment.spec.runtime:
49
- deployment.spec.runtime = Runtime()
50
- if not deployment.spec.runtime.image:
51
- deployment.spec.runtime.image = get_runtime_image(resource.type, deployment.metadata.name)
52
41
  return deployment
53
42
 
54
43
  def get_beamlit_deployment_from_resource(
@@ -105,7 +94,7 @@ def get_flavors(flavors: list[Flavor]) -> str:
105
94
  return json.dumps([flavor.to_dict() for flavor in flavors])
106
95
 
107
96
  def get_agent_yaml(
108
- agent: Agent, functions: list[tuple[Resource, Function]], settings: Settings
97
+ agent: Agent, functions: list[tuple[Resource, Function]], settings: Settings, client: AuthenticatedClient
109
98
  ) -> str:
110
99
  """
111
100
  Generates YAML configuration for an agent deployment.
@@ -118,30 +107,24 @@ def get_agent_yaml(
118
107
  Returns:
119
108
  str: YAML configuration string
120
109
  """
110
+ try:
111
+ agent_response = get_agent.sync(agent.metadata.name, client=client)
112
+ agent.spec.repository = agent_response.spec.repository
113
+ except Exception as e:
114
+ pass
115
+ agent.spec.functions = [slugify(function.metadata.name) for (_, function) in functions]
116
+ agent.metadata.labels = agent.metadata.labels and MetadataLabels.from_dict(agent.metadata.labels) or MetadataLabels()
117
+ agent.metadata.labels["x-beamlit-auto-generated"] = "true"
118
+ agent_yaml = yaml.dump(agent.to_dict())
121
119
  template = f"""
122
120
  apiVersion: beamlit.com/v1alpha1
123
121
  kind: Agent
124
- metadata:
125
- name: {slugify(agent.metadata.name)}
126
- displayName: {agent.metadata.display_name or agent.metadata.name}
127
- environment: {settings.environment}
128
- workspace: {settings.workspace}
129
- labels:
130
- x-beamlit-auto-generated: "true"
131
- spec:
132
- enabled: true
133
- policies: [{", ".join(agent.spec.policies or [])}]
134
- functions: [{", ".join([f"{slugify(function.metadata.name)}" for (_, function) in functions])}]
135
- agentChain: {format_agent_chain(agent.spec.agent_chain)}
136
- model: {agent.spec.model}
122
+ {agent_yaml}
137
123
  """
138
- if agent.spec.description:
139
- template += f""" description: |
140
- {agent.spec.description}"""
141
124
  return template
142
125
 
143
126
 
144
- def get_function_yaml(function: Function, settings: Settings) -> str:
127
+ def get_function_yaml(function: Function, settings: Settings, client: AuthenticatedClient) -> str:
145
128
  """
146
129
  Generates YAML configuration for a function deployment.
147
130
 
@@ -152,21 +135,13 @@ def get_function_yaml(function: Function, settings: Settings) -> str:
152
135
  Returns:
153
136
  str: YAML configuration string
154
137
  """
138
+ function.metadata.labels = function.metadata.labels and MetadataLabels.from_dict(function.metadata.labels) or MetadataLabels()
139
+ function.metadata.labels["x-beamlit-auto-generated"] = "true"
140
+ function_yaml = yaml.dump(function.to_dict())
155
141
  return f"""
156
142
  apiVersion: beamlit.com/v1alpha1
157
143
  kind: Function
158
- metadata:
159
- name: {slugify(function.metadata.name)}
160
- displayName: {function.metadata.display_name or function.metadata.name}
161
- environment: {settings.environment}
162
- labels:
163
- x-beamlit-auto-generated: "true"
164
- spec:
165
- enabled: true
166
- policies: [{", ".join(function.spec.policies or [])}]
167
- description: |
168
- {function.spec.description}
169
- parameters: {format_parameters(function.spec.parameters)}
144
+ {function_yaml}
170
145
  """
171
146
 
172
147
 
@@ -220,6 +195,35 @@ ENV PATH="/beamlit/.venv/bin:$PATH"
220
195
  ENTRYPOINT [{cmd_str}]
221
196
  """
222
197
 
198
+ def clean_auto_generated(
199
+ directory: str,
200
+ type: Literal["agent", "function"],
201
+ deployments: list[tuple[Resource, Agent | Function]]
202
+ ):
203
+ """
204
+ Cleans up auto-generated deployments of a specific type.
205
+
206
+ Args:
207
+ directory (str): Base directory containing deployments
208
+ type (str): Type of deployment ("agent" or "function")
209
+ deployments (list[tuple[Resource, Agent | Function]]): List of deployment resources and configurations
210
+ """
211
+
212
+ deploy_dir = Path(directory) / f"{type}s"
213
+ deploy_names = [d.metadata.name for (_, d) in deployments]
214
+
215
+ if deploy_dir.exists():
216
+ for item_dir in deploy_dir.iterdir():
217
+ if item_dir.is_dir() and item_dir.name not in deploy_names:
218
+ yaml_file = item_dir / f"{type}.yaml"
219
+ if yaml_file.exists():
220
+ with open(yaml_file) as f:
221
+ try:
222
+ content = yaml.safe_load(f)
223
+ if content.get("metadata", {}).get("labels", {}).get("x-beamlit-auto-generated") == "true":
224
+ shutil.rmtree(item_dir)
225
+ except yaml.YAMLError:
226
+ continue
223
227
 
224
228
  def generate_beamlit_deployment(directory: str):
225
229
  """
@@ -234,6 +238,7 @@ def generate_beamlit_deployment(directory: str):
234
238
  - Directory structure for agents and functions
235
239
  """
236
240
  settings = init()
241
+ client = new_client()
237
242
  logger = getLogger(__name__)
238
243
  logger.info(f"Importing server module: {settings.server.module}")
239
244
  functions: list[tuple[Resource, Function]] = []
@@ -257,28 +262,23 @@ def generate_beamlit_deployment(directory: str):
257
262
  agent_dir = os.path.join(agents_dir, agent.metadata.name)
258
263
  os.makedirs(agent_dir, exist_ok=True)
259
264
  with open(os.path.join(agent_dir, "agent.yaml"), "w") as f:
260
- content = get_agent_yaml(agent, functions, settings)
265
+ content = get_agent_yaml(agent, functions, settings, client)
261
266
  f.write(content)
262
267
  # write dockerfile for build
263
268
  with open(os.path.join(agent_dir, "Dockerfile"), "w") as f:
264
269
  content = dockerfile("agent", resource, agent)
265
270
  f.write(content)
266
- # write destination docker
267
- with open(os.path.join(agent_dir, "destination.txt"), "w") as f:
268
- content = agent.spec.runtime.image
269
- f.write(content)
270
271
  for resource, function in functions:
271
272
  # write deployment file
272
273
  function_dir = os.path.join(functions_dir, function.metadata.name)
273
274
  os.makedirs(function_dir, exist_ok=True)
274
275
  with open(os.path.join(function_dir, "function.yaml"), "w") as f:
275
- content = get_function_yaml(function, settings)
276
+ content = get_function_yaml(function, settings, client)
276
277
  f.write(content)
277
278
  # write dockerfile for build
278
279
  with open(os.path.join(function_dir, "Dockerfile"), "w") as f:
279
280
  content = dockerfile("function", resource, function)
280
281
  f.write(content)
281
- # write destination docker
282
- with open(os.path.join(function_dir, "destination.txt"), "w") as f:
283
- content = function.spec.runtime.image
284
- f.write(content)
282
+
283
+ clean_auto_generated(directory, "agent", agents)
284
+ clean_auto_generated(directory, "function", functions)
beamlit/deploy/format.py CHANGED
@@ -48,6 +48,16 @@ def format_parameters(parameters: list[StoreFunctionParameter]) -> str:
48
48
 
49
49
  return "\n".join(formatted)
50
50
 
51
+ def format_dict(obj: dict) -> str:
52
+ if not obj:
53
+ return "null"
54
+ ret = ""
55
+ for k, v in obj.items():
56
+ if not v:
57
+ ret += f"{k}: null\n"
58
+ else:
59
+ ret += f"{k}: {v}\n"
60
+ return ret
51
61
 
52
62
  def format_agent_chain(agentChain: list[AgentChain]) -> str:
53
63
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.34rc59
3
+ Version: 0.0.34rc61
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -130,15 +130,15 @@ beamlit/authentication/credentials.py,sha256=p_1xenabCbQuRz7BiFk7oTK4uCxAt_zoyku
130
130
  beamlit/authentication/device_mode.py,sha256=tmr22gllKOZwBRub_QjF5pYa425x-nE8tQNpZ_EGR6g,3644
131
131
  beamlit/common/__init__.py,sha256=saX5X3hRCJ9erSlXuSkZ2VGgquvpgdcofAU_9sM4bCE,354
132
132
  beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
133
- beamlit/common/instrumentation.py,sha256=GpM7dfAWXDD7h9X4WnI5k-pE2tBHSN08_KN9NHLRugo,5334
133
+ beamlit/common/instrumentation.py,sha256=8sbYCrkC_2BsdAZ_1cWTw5aRtMUz2xvN2tsG0rovBtA,5351
134
134
  beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
135
135
  beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
136
136
  beamlit/common/settings.py,sha256=b2rvby-ufG3M0AB1ReoWFM-1EzF1LaE-gbokO9HvQDI,3810
137
137
  beamlit/common/slugify.py,sha256=nR29r37IdWS2i44ZC6ZsXRgqKPYmvMGtFQ7BuIQUTlc,90
138
138
  beamlit/common/utils.py,sha256=jouz5igBvT37Xn_e94-foCHyQczVim-UzVcoIF6RWJ4,657
139
139
  beamlit/deploy/__init__.py,sha256=GS7l7Jtm2yKs7iNLKcfjYO-rAhUzggQ3xiYSf3oxLBY,91
140
- beamlit/deploy/deploy.py,sha256=FyDqSYpm_YKG8IapaFhI0EN5m71d7wkWLjfBuitxsOU,9884
141
- beamlit/deploy/format.py,sha256=PJ8kU7Y1pwiS3tqqyvFaag9LO3jju-4ua574163VPk4,1820
140
+ beamlit/deploy/deploy.py,sha256=Uz-AvgEKT6dXpixEPpDBzqtRbv4_JzQ1joZOKYR_s8g,10260
141
+ beamlit/deploy/format.py,sha256=U6UZEFAYLnGJJ7O2YmSdlUUFhnWNGAv6NZ-DW4KTgvI,2049
142
142
  beamlit/deploy/parser.py,sha256=Ga0poCZkoRnuTw082QnTcNGCBJncoRAnVsn8-1FsaJE,6907
143
143
  beamlit/functions/__init__.py,sha256=_RPG1Bfg54JGdIPnViAU6n9zD7E1cDNsdXi8oYGskzE,138
144
144
  beamlit/functions/decorator.py,sha256=ZtSQsPLI70WKwi2jPhA7DaqREQUINpqt9BDVugeV_sg,1714
@@ -262,6 +262,6 @@ beamlit/serve/app.py,sha256=gYQvUK_S7g0Em-idND8HrVDqgg5LlIemheSGlX2Jj8U,3638
262
262
  beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
263
263
  beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
264
264
  beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
265
- beamlit-0.0.34rc59.dist-info/METADATA,sha256=37dnjgnNDVoYdZ5COy4DUM0rov8hjW8KwKfDPXPSOi0,2412
266
- beamlit-0.0.34rc59.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
267
- beamlit-0.0.34rc59.dist-info/RECORD,,
265
+ beamlit-0.0.34rc61.dist-info/METADATA,sha256=vsh5bRkJV61Uqh2qDKLpesr9dElEppuWS9ixSTyBrhU,2412
266
+ beamlit-0.0.34rc61.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
267
+ beamlit-0.0.34rc61.dist-info/RECORD,,