truss 0.11.8rc3__py3-none-any.whl → 0.11.8rc5__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.

Potentially problematic release.


This version of truss might be problematic. Click here for more details.

@@ -2,12 +2,13 @@ import asyncio
2
2
  import logging
3
3
  import logging.config
4
4
  import re
5
+ import traceback
5
6
  from pathlib import Path
6
7
  from typing import Dict
7
8
 
8
9
  import httpx
9
10
  from endpoints import control_app
10
- from fastapi import FastAPI
11
+ from fastapi import FastAPI, Request
11
12
  from fastapi.responses import JSONResponse
12
13
  from helpers.errors import ModelLoadFailed, PatchApplicatonError
13
14
  from helpers.inference_server_controller import InferenceServerController
@@ -16,6 +17,41 @@ from helpers.inference_server_starter import async_inference_server_startup_flow
16
17
  from helpers.truss_patch.model_container_patch_applier import ModelContainerPatchApplier
17
18
  from shared import log_config
18
19
  from starlette.datastructures import State
20
+ from starlette.middleware.base import BaseHTTPMiddleware
21
+
22
+ SANITIZED_EXCEPTION_FRAMES = 2
23
+
24
+
25
+ class SanitizedException(Exception):
26
+ def __init__(self, original_error: Exception, num_frames: int):
27
+ self.original_error = original_error
28
+ tb_lines = traceback.format_tb(original_error.__traceback__)
29
+ if tb_lines and num_frames > 0:
30
+ # NB(nikhil): Take the last num_frames, join them, and strip extra whitespace
31
+ selected_frames = tb_lines[-num_frames:]
32
+ self.concise_msg = "".join(selected_frames).rstrip()
33
+ else:
34
+ self.concise_msg = f"{type(original_error).__name__}: {original_error}"
35
+
36
+ def __str__(self):
37
+ return self.concise_msg
38
+
39
+ def __repr__(self):
40
+ return self.concise_msg
41
+
42
+
43
+ # NB(nikhil): SanitizedExceptionMiddleware runs on every request and cleans up the verbose stack traces
44
+ # that are very noisy for users.
45
+ class SanitizedExceptionMiddleware(BaseHTTPMiddleware):
46
+ def __init__(self, app, num_frames: int):
47
+ super().__init__(app)
48
+ self.num_frames = num_frames
49
+
50
+ async def dispatch(self, request: Request, call_next):
51
+ try:
52
+ return await call_next(request)
53
+ except Exception as error:
54
+ raise SanitizedException(error, self.num_frames) from error
19
55
 
20
56
 
21
57
  async def handle_patch_error(_, exc):
@@ -90,6 +126,9 @@ def create_app(base_config: Dict):
90
126
  )
91
127
  app.state = app_state
92
128
  app.include_router(control_app)
129
+ app.add_middleware(
130
+ SanitizedExceptionMiddleware, num_frames=SANITIZED_EXCEPTION_FRAMES
131
+ )
93
132
 
94
133
  @app.on_event("shutdown")
95
134
  def on_shutdown():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: truss
3
- Version: 0.11.8rc3
3
+ Version: 0.11.8rc5
4
4
  Summary: A seamless bridge from model development to model delivery
5
5
  Project-URL: Repository, https://github.com/basetenlabs/truss
6
6
  Project-URL: Homepage, https://truss.baseten.co
@@ -73,7 +73,7 @@ truss/templates/copy_cache_files.Dockerfile.jinja,sha256=Os5zFdYLZ_AfCRGq4RcpVTO
73
73
  truss/templates/docker_server_requirements.txt,sha256=PyhOPKAmKW1N2vLvTfLMwsEtuGpoRrbWuNo7tT6v2Mc,18
74
74
  truss/templates/server.Dockerfile.jinja,sha256=CUYnF_hgxPGq2re7__0UPWlwzOHMoFkxp6NVKi3U16s,7071
75
75
  truss/templates/control/requirements.txt,sha256=nqqNmlTwFeV8sV4fqwItwzzd_egADBP_e-cEopXBJ4k,358
76
- truss/templates/control/control/application.py,sha256=jYeta6hWe1SkfLL3W4IDmdYjg3ZuKqI_UagWYs5RB_E,3793
76
+ truss/templates/control/control/application.py,sha256=_FmSgIetffVpwUYVeMM6rH9pGjjHhALTdtR2RegVyJY,5226
77
77
  truss/templates/control/control/endpoints.py,sha256=VQ1lvZjFvR091yRkiFdvXw1Q7PiNGXT9rJwY7_sX6yg,11828
78
78
  truss/templates/control/control/server.py,sha256=R4Y219i1dcz0kkksN8obLoX-YXWGo9iW1igindyG50c,3128
79
79
  truss/templates/control/control/helpers/context_managers.py,sha256=W6dyFgLBhPa5meqrOb3w_phMtKfaJI-GhwUfpiycDc8,413
@@ -368,8 +368,8 @@ truss_train/deployment.py,sha256=lWWANSuzBWu2M4oK4qD7n-oVR1JKdmw2Pn5BJQHg-Ck,307
368
368
  truss_train/loader.py,sha256=0o66EjBaHc2YY4syxxHVR4ordJWs13lNXnKjKq2wq0U,1630
369
369
  truss_train/public_api.py,sha256=9N_NstiUlmBuLUwH_fNG_1x7OhGCytZLNvqKXBlStrM,1220
370
370
  truss_train/restore_from_checkpoint.py,sha256=8hdPm-WSgkt74HDPjvCjZMBpvA9MwtoYsxVjOoa7BaM,1176
371
- truss-0.11.8rc3.dist-info/METADATA,sha256=ziFdl3TpygMkpZIMoHXADHO9gSIBCXaVeGdXelt46U0,6680
372
- truss-0.11.8rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
- truss-0.11.8rc3.dist-info/entry_points.txt,sha256=-MwKfHHQHQ6j0HqIgvxrz3CehCmczDLTD-OsRHnjjuU,130
374
- truss-0.11.8rc3.dist-info/licenses/LICENSE,sha256=FTqGzu85i-uw1Gi8E_o0oD60bH9yQ_XIGtZbA1QUYiw,1064
375
- truss-0.11.8rc3.dist-info/RECORD,,
371
+ truss-0.11.8rc5.dist-info/METADATA,sha256=NIv6jZ6bWqB41Kqdf9SjNWko0fOVcsqc8-FsW9GIPBU,6680
372
+ truss-0.11.8rc5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
+ truss-0.11.8rc5.dist-info/entry_points.txt,sha256=-MwKfHHQHQ6j0HqIgvxrz3CehCmczDLTD-OsRHnjjuU,130
374
+ truss-0.11.8rc5.dist-info/licenses/LICENSE,sha256=FTqGzu85i-uw1Gi8E_o0oD60bH9yQ_XIGtZbA1QUYiw,1064
375
+ truss-0.11.8rc5.dist-info/RECORD,,