beamlit 0.0.29rc32__py3-none-any.whl → 0.0.30__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
+ from .error import HTTPError
1
2
  from .logger import init as init_logger
2
3
  from .secrets import Secret
3
- from .settings import Settings, get_settings, init_agent
4
+ from .settings import Settings, get_settings, init, init_agent
4
5
  from .utils import copy_folder
5
6
 
6
7
  __all__ = [
@@ -8,6 +9,8 @@ __all__ = [
8
9
  "Settings",
9
10
  "get_settings",
10
11
  "init_agent",
12
+ "init",
11
13
  "copy_folder",
12
14
  "init_logger",
15
+ "HTTPError",
13
16
  ]
@@ -0,0 +1,9 @@
1
+ class HTTPError(Exception):
2
+ def __init__(self, status_code: int, message: str):
3
+ self.status_code = status_code
4
+ self.message = message
5
+ super().__init__(self.message)
6
+
7
+ def __str__(self):
8
+ return f"{self.status_code} {self.message}"
9
+
@@ -42,7 +42,7 @@ class SettingsServer(BaseSettings):
42
42
  module: str = Field(default="main.main")
43
43
  port: int = Field(default=80)
44
44
  host: str = Field(default="0.0.0.0")
45
-
45
+ directory: str = Field(default="src")
46
46
 
47
47
  class Settings(BaseSettings):
48
48
  model_config = SettingsConfigDict(
beamlit/deploy/deploy.py CHANGED
@@ -174,15 +174,15 @@ def dockerfile(
174
174
  Returns:
175
175
  str: Dockerfile content
176
176
  """
177
+ settings = get_settings()
177
178
  if type == "agent":
178
179
  module = f"{resource.module.__file__.split('/')[-1].replace('.py', '')}.{resource.module.__name__}"
179
180
  else:
180
- module = f"functions.{resource.module.__name__}.{resource.func.__name__}"
181
+ module = f"functions.{resource.module.__file__.split('/')[-1].replace('.py', '')}.{resource.module.__name__}"
181
182
  cmd = ["bl", "serve", "--port", "80", "--module", module]
182
183
  if type == "agent":
183
184
  cmd.append("--remote")
184
185
  cmd_str = ",".join([f'"{c}"' for c in cmd])
185
-
186
186
  return f"""
187
187
  FROM python:3.12-slim
188
188
 
@@ -201,7 +201,7 @@ RUN uv sync --no-cache
201
201
 
202
202
  COPY README.m[d] /beamlit/README.md
203
203
  COPY LICENS[E] /beamlit/LICENSE
204
- COPY src /beamlit/src
204
+ COPY {settings.server.directory} /beamlit/src
205
205
 
206
206
  ENV PATH="/beamlit/.venv/bin:$PATH"
207
207
 
@@ -226,11 +226,11 @@ def generate_beamlit_deployment(directory: str):
226
226
  logger.info(f"Importing server module: {settings.server.module}")
227
227
  functions: list[tuple[Resource, Function]] = []
228
228
  agents: list[tuple[Resource, Agent]] = []
229
- for resource in get_resources("agent"):
229
+ for resource in get_resources("agent", settings.server.directory):
230
230
  agent = get_beamlit_deployment_from_resource(resource)
231
231
  if agent:
232
232
  agents.append((resource, agent))
233
- for resource in get_resources("function"):
233
+ for resource in get_resources("function", settings.server.directory):
234
234
  function = get_beamlit_deployment_from_resource(resource)
235
235
  if function:
236
236
  functions.append((resource, function))
@@ -251,6 +251,10 @@ def generate_beamlit_deployment(directory: str):
251
251
  with open(os.path.join(agent_dir, f"Dockerfile"), "w") as f:
252
252
  content = dockerfile("agent", resource, agent)
253
253
  f.write(content)
254
+ # write destination docker
255
+ with open(os.path.join(agent_dir, f"destination.txt"), "w") as f:
256
+ content = agent.spec.runtime.image
257
+ f.write(content)
254
258
  for resource, function in functions:
255
259
  # write deployment file
256
260
  function_dir = os.path.join(functions_dir, function.metadata.name)
@@ -262,3 +266,7 @@ def generate_beamlit_deployment(directory: str):
262
266
  with open(os.path.join(function_dir, f"Dockerfile"), "w") as f:
263
267
  content = dockerfile("function", resource, function)
264
268
  f.write(content)
269
+ # write destination docker
270
+ with open(os.path.join(function_dir, f"destination.txt"), "w") as f:
271
+ content = function.spec.runtime.image
272
+ f.write(content)
beamlit/deploy/parser.py CHANGED
@@ -7,6 +7,7 @@ from typing import Callable, Literal
7
7
 
8
8
  from beamlit.models import StoreFunctionParameter
9
9
 
10
+
10
11
  @dataclass
11
12
  class Resource:
12
13
  type: Literal["agent", "function"]
@@ -16,7 +17,7 @@ class Resource:
16
17
  func: Callable
17
18
 
18
19
 
19
- def get_resources(from_decorator, dir="src") -> list[Resource]:
20
+ def get_resources(from_decorator, dir) -> list[Resource]:
20
21
  """
21
22
  Scans through Python files in a directory to find functions decorated with a specific decorator.
22
23
 
beamlit/run.py CHANGED
@@ -3,7 +3,7 @@ from typing import Any
3
3
 
4
4
  import requests
5
5
  from beamlit.client import AuthenticatedClient
6
- from beamlit.common.settings import get_settings
6
+ from beamlit.common import HTTPError, get_settings
7
7
 
8
8
 
9
9
  class RunClient:
@@ -45,4 +45,6 @@ class RunClient:
45
45
  kwargs["json"] = json
46
46
 
47
47
  response = client.request(method, url, **kwargs)
48
+ if response.status_code >= 400:
49
+ raise HTTPError(response.status_code, response.text)
48
50
  return response
beamlit/serve/app.py CHANGED
@@ -7,13 +7,10 @@ from logging import getLogger
7
7
  from uuid import uuid4
8
8
 
9
9
  from asgi_correlation_id import CorrelationIdMiddleware
10
- from beamlit.common.settings import get_settings, init
11
- from beamlit.common.instrumentation import (
12
- get_metrics_exporter,
13
- get_resource_attributes,
14
- get_span_exporter,
15
- instrument_app,
16
- )
10
+ from beamlit.common import HTTPError, get_settings, init
11
+ from beamlit.common.instrumentation import (get_metrics_exporter,
12
+ get_resource_attributes,
13
+ get_span_exporter, instrument_app)
17
14
  from fastapi import FastAPI, Request, Response
18
15
  from fastapi.responses import JSONResponse
19
16
  from traceloop.sdk import Traceloop
@@ -90,10 +87,17 @@ async def root(request: Request):
90
87
  content = {"error": str(e)}
91
88
  if settings.environment == "development":
92
89
  content["traceback"] = str(traceback.format_exc())
93
- logger.error(f"{content}")
90
+ logger.error(str(traceback.format_exc()))
94
91
  return JSONResponse(status_code=400, content=content)
92
+ except HTTPError as e:
93
+ content = {"error": e.message, "status_code": e.status_code}
94
+ if settings.environment == "development":
95
+ content["traceback"] = str(traceback.format_exc())
96
+ logger.error(f"{e.status_code} {str(traceback.format_exc())}")
97
+ return JSONResponse(status_code=e.status_code, content=content)
95
98
  except Exception as e:
96
99
  content = {"error": f"Internal server error, {e}"}
97
100
  if settings.environment == "development":
98
101
  content["traceback"] = str(traceback.format_exc())
102
+ logger.error(str(traceback.format_exc()))
99
103
  return JSONResponse(status_code=500, content=content)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.29rc32
3
+ Version: 0.0.30
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -2,7 +2,7 @@ beamlit/__init__.py,sha256=545gFC-wLLwUktWcOAjUWe_Glha40tBetRTOYSfHnbI,164
2
2
  beamlit/client.py,sha256=PnR6ybZk5dLIJPnDKAf2epHOeQC_7yL0fG4muvphHjA,12695
3
3
  beamlit/errors.py,sha256=gO8GBmKqmSNgAg-E5oT-oOyxztvp7V_6XG7OUTT15q0,546
4
4
  beamlit/py.typed,sha256=8ZJUsxZiuOy1oJeVhsTWQhTG_6pTVHVXk5hJL79ebTk,25
5
- beamlit/run.py,sha256=RLwMv5f_S8lw7Wq7O6DvEcOl0nGYh769qjGl_SmR9Z0,1338
5
+ beamlit/run.py,sha256=BCVQXdtIzJedxqGSWttYlJphO5ru7VNDYrUAQmCNq_c,1445
6
6
  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=HzBs3nI4xaH86I_r-M-HGGp6roXsJxMx-qXl_GrJaY0,2831
@@ -128,17 +128,18 @@ beamlit/authentication/authentication.py,sha256=8R-3WdQSykNjCbebAW2p8Glvw5nlAmSE
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=yDoMJDKj-xjTGl7U1YI59KpWxiOV65HSiUulgO8xdTA,277
131
+ beamlit/common/__init__.py,sha256=vj4_boIBVitMsaQR8BqBqE2eupOIh6MWBAYlYyCCH98,341
132
+ beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
132
133
  beamlit/common/generate.py,sha256=LtdCju_QayRS4lZrrb_0VHqWWvTcv4Mbf-iV1TB_Qko,7522
133
134
  beamlit/common/instrumentation.py,sha256=MsBDfFcMYqGDiHHj4j5hLHE4EWxZExkhmCeFS3SKzJY,3181
134
135
  beamlit/common/logger.py,sha256=VFRbaZh93n8ZGugeeYKe88IP2nI3g2JNa7XN4j8wVJE,1116
135
136
  beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
136
- beamlit/common/settings.py,sha256=bxgQxMV5ncNqDGcWS_Wj3nzOF8FgAmC6alMP2fOdEDU,5895
137
+ beamlit/common/settings.py,sha256=2V06qodZHwPBqRDdpPyZhdCO7HeMjWr2rkEePOgmHqE,5936
137
138
  beamlit/common/utils.py,sha256=jouz5igBvT37Xn_e94-foCHyQczVim-UzVcoIF6RWJ4,657
138
139
  beamlit/deploy/__init__.py,sha256=GS7l7Jtm2yKs7iNLKcfjYO-rAhUzggQ3xiYSf3oxLBY,91
139
- beamlit/deploy/deploy.py,sha256=on1i93SdECKrLVRMm3V2BRW5JeolPPq1dJHa4Evp0ns,9188
140
+ beamlit/deploy/deploy.py,sha256=AbQxSVGAPbwBn4wKPiMEF5GjtGa8q4u3DBuhnYdz4GI,9706
140
141
  beamlit/deploy/format.py,sha256=78tOoeNPJ8969AhQTeFlIwZgQ3un8gmTSMmrYbRQSds,1818
141
- beamlit/deploy/parser.py,sha256=uT-bezLX6yjyxr1ogm1GXIT_MeREqHDUBlKiyav5qg0,6912
142
+ beamlit/deploy/parser.py,sha256=Ga0poCZkoRnuTw082QnTcNGCBJncoRAnVsn8-1FsaJE,6907
142
143
  beamlit/functions/__init__.py,sha256=_RPG1Bfg54JGdIPnViAU6n9zD7E1cDNsdXi8oYGskzE,138
143
144
  beamlit/functions/decorator.py,sha256=NsdIWs55Yhn-TUO855DIE2AarV-euXtl7Qt5c2W3AUo,3239
144
145
  beamlit/functions/github/__init__.py,sha256=gYnUkeegukOfbymdabuuJkScvH-_ZJygX05BoqkPn0o,49
@@ -251,10 +252,10 @@ beamlit/models/websocket_channel.py,sha256=jg3vN7yS_oOIwGtndtIUr1LsyEA58RXLXahqS
251
252
  beamlit/models/workspace.py,sha256=l__bIpbA4oJvxXo7UbEoCcqkvu9MiNt5aXXpZ3bgwHg,4309
252
253
  beamlit/models/workspace_labels.py,sha256=WbnUY6eCTkUNdY7hhhSF-KQCl8fWFfkCf7hzCTiNp4A,1246
253
254
  beamlit/models/workspace_user.py,sha256=70CcifQWYbeWG7TDui4pblTzUe5sVK0AS19vNCzKE8g,3423
254
- beamlit/serve/app.py,sha256=OpwPjRdyHZK6J-ziPwhiRDGGa2mvCrFVcBFE6alJVOM,3071
255
+ beamlit/serve/app.py,sha256=k9THiOqcPs4lcQQhZaucLcboXCR_5AKP9AFCMNRbdPI,3559
255
256
  beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
256
257
  beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
257
258
  beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
258
- beamlit-0.0.29rc32.dist-info/METADATA,sha256=SX1BoOg-Mqw3GzEHwX9bdwJPkkQ01jE1AHgRdGKXjvY,2405
259
- beamlit-0.0.29rc32.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
260
- beamlit-0.0.29rc32.dist-info/RECORD,,
259
+ beamlit-0.0.30.dist-info/METADATA,sha256=UNYwevCSKK872KofAvX_-dHOIuFA_9LcrmF4lgT4mFg,2401
260
+ beamlit-0.0.30.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
261
+ beamlit-0.0.30.dist-info/RECORD,,