truss 0.11.8rc8__py3-none-any.whl → 0.11.8rc10__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,71 +2,36 @@ import asyncio
2
2
  import logging
3
3
  import logging.config
4
4
  import re
5
- import traceback
6
5
  from pathlib import Path
7
- from typing import Awaitable, Callable, Dict
6
+ from typing import Dict
8
7
 
9
8
  import httpx
10
9
  from endpoints import control_app
11
- from fastapi import FastAPI, Request, Response
10
+ from fastapi import FastAPI
12
11
  from fastapi.responses import JSONResponse
12
+ from helpers.errors import ModelLoadFailed, PatchApplicatonError
13
+ from helpers.inference_server_controller import InferenceServerController
14
+ from helpers.inference_server_process_controller import InferenceServerProcessController
15
+ from helpers.inference_server_starter import async_inference_server_startup_flow
16
+ from helpers.truss_patch.model_container_patch_applier import ModelContainerPatchApplier
13
17
  from shared import log_config
14
18
  from starlette.datastructures import State
15
- from starlette.middleware.base import BaseHTTPMiddleware
16
-
17
- from truss.templates.control.control.helpers.errors import (
18
- ModelLoadFailed,
19
- PatchApplicatonError,
20
- )
21
- from truss.templates.control.control.helpers.inference_server_controller import (
22
- InferenceServerController,
23
- )
24
- from truss.templates.control.control.helpers.inference_server_process_controller import (
25
- InferenceServerProcessController,
26
- )
27
- from truss.templates.control.control.helpers.inference_server_starter import (
28
- async_inference_server_startup_flow,
29
- )
30
- from truss.templates.control.control.helpers.truss_patch.model_container_patch_applier import (
31
- ModelContainerPatchApplier,
32
- )
33
-
34
- SANITIZED_EXCEPTION_FRAMES = 2
35
-
36
-
37
- class SanitizedExceptionMiddleware(BaseHTTPMiddleware):
38
- def __init__(self, app, num_frames: int = SANITIZED_EXCEPTION_FRAMES):
39
- super().__init__(app)
40
- self.num_frames = num_frames
41
-
42
- async def dispatch(
43
- self, request: Request, call_next: Callable[[Request], Awaitable[Response]]
44
- ) -> Response:
45
- try:
46
- return await call_next(request)
47
- except Exception as exc:
48
- sanitized_traceback = self._create_sanitized_traceback(exc)
49
- request.app.state.logger.error(sanitized_traceback)
50
-
51
- if isinstance(exc, ModelLoadFailed):
52
- return JSONResponse({"error": str(exc)}, status_code=503)
53
- elif isinstance(exc, PatchApplicatonError):
54
- error_type = _camel_to_snake_case(type(exc).__name__)
55
- return JSONResponse(
56
- {"error": {"type": error_type, "msg": str(exc)}}, status_code=400
57
- )
58
- else:
59
- return JSONResponse(
60
- {"error": {"type": "unknown", "msg": str(exc)}}, status_code=500
61
- )
62
-
63
- def _create_sanitized_traceback(self, error: Exception) -> str:
64
- tb_lines = traceback.format_tb(error.__traceback__)
65
- if tb_lines and self.num_frames > 0:
66
- selected_frames = tb_lines[-self.num_frames :]
67
- return "".join(selected_frames).rstrip()
68
- else:
69
- return f"{type(error).__name__}: {error}"
19
+
20
+
21
+ async def handle_patch_error(_, exc):
22
+ error_type = _camel_to_snake_case(type(exc).__name__)
23
+ return JSONResponse(content={"error": {"type": error_type, "msg": str(exc)}})
24
+
25
+
26
+ async def generic_error_handler(_, exc):
27
+ return JSONResponse(
28
+ content={"error": {"type": "unknown", "msg": f"{type(exc)}: {exc}"}}
29
+ )
30
+
31
+
32
+ async def handle_model_load_failed(_, error):
33
+ # Model load failures should result in 503 status
34
+ return JSONResponse({"error": str(error)}, 503)
70
35
 
71
36
 
72
37
  def create_app(base_config: Dict):
@@ -117,10 +82,14 @@ def create_app(base_config: Dict):
117
82
  app = FastAPI(
118
83
  title="Truss Live Reload Server",
119
84
  on_startup=[start_background_inference_startup],
85
+ exception_handlers={
86
+ PatchApplicatonError: handle_patch_error,
87
+ ModelLoadFailed: handle_model_load_failed,
88
+ Exception: generic_error_handler,
89
+ },
120
90
  )
121
91
  app.state = app_state
122
92
  app.include_router(control_app)
123
- app.add_middleware(SanitizedExceptionMiddleware)
124
93
 
125
94
  @app.on_event("shutdown")
126
95
  def on_shutdown():
@@ -35,6 +35,16 @@ server {
35
35
  proxy_pass http://127.0.0.1:{{server_port}};
36
36
  }
37
37
  # Predict
38
+ location ~ ^(/v1/models/model:predict|/v1/websocket)$ {
39
+ proxy_redirect off;
40
+ proxy_read_timeout 18030s;
41
+ proxy_http_version 1.1;
42
+
43
+ rewrite ^/v1/models/model:predict$ {{server_endpoint}} break;
44
+
45
+ proxy_pass http://127.0.0.1:{{server_port}};
46
+ }
47
+
38
48
  location ~ ^/v1/models/model:predict$ {
39
49
  proxy_redirect off;
40
50
  proxy_read_timeout 18030s;
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: truss
3
- Version: 0.11.8rc8
3
+ Version: 0.11.8rc10
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=bmAMh1hxEPu509O7KRUyp_Vaz92xbzgA6vRHhaNt5ts,4979
76
+ truss/templates/control/control/application.py,sha256=jYeta6hWe1SkfLL3W4IDmdYjg3ZuKqI_UagWYs5RB_E,3793
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
@@ -91,7 +91,7 @@ truss/templates/custom/examples.yaml,sha256=2UcCtEdavImWmiCtj31ckBlAKVOwNMC5AwMI
91
91
  truss/templates/custom/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
92
92
  truss/templates/custom/model/model.py,sha256=J04rLxK09Pwt2F4GoKOLKL-H-CqZUdYIM-PL2CE9PoE,1079
93
93
  truss/templates/custom_python_dx/my_model.py,sha256=NG75mQ6wxzB1BYUemDFZvRLBET-UrzuUK4FuHjqI29U,910
94
- truss/templates/docker_server/proxy.conf.jinja,sha256=Lg-PcZzKflG85exZKHNgW_I6r0mATV8AtOIBaE40-RM,1669
94
+ truss/templates/docker_server/proxy.conf.jinja,sha256=qgo54vFLUVBbuxYjM9GKdXUdpbVOTUCuqq73ip-RfbA,1956
95
95
  truss/templates/docker_server/supervisord.conf.jinja,sha256=dd37fwZE--cutrvOUCqEyJQQQhlp61H2IUs2huKWsSk,1808
96
96
  truss/templates/server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
97
  truss/templates/server/main.py,sha256=kWXrdD8z8IpamyWxc8qcvd5ck9gM1Kz2QH5qHJCnmOQ,222
@@ -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.8rc8.dist-info/METADATA,sha256=sFf-bspU7seibbvhZolfFQxsX-B6dKktsUVY1-InAew,6680
372
- truss-0.11.8rc8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
- truss-0.11.8rc8.dist-info/entry_points.txt,sha256=-MwKfHHQHQ6j0HqIgvxrz3CehCmczDLTD-OsRHnjjuU,130
374
- truss-0.11.8rc8.dist-info/licenses/LICENSE,sha256=FTqGzu85i-uw1Gi8E_o0oD60bH9yQ_XIGtZbA1QUYiw,1064
375
- truss-0.11.8rc8.dist-info/RECORD,,
371
+ truss-0.11.8rc10.dist-info/METADATA,sha256=fosW8ArYEmmBK4-o2StLiEgskSbAslwBX3FTie2gn0E,6681
372
+ truss-0.11.8rc10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
+ truss-0.11.8rc10.dist-info/entry_points.txt,sha256=-MwKfHHQHQ6j0HqIgvxrz3CehCmczDLTD-OsRHnjjuU,130
374
+ truss-0.11.8rc10.dist-info/licenses/LICENSE,sha256=FTqGzu85i-uw1Gi8E_o0oD60bH9yQ_XIGtZbA1QUYiw,1064
375
+ truss-0.11.8rc10.dist-info/RECORD,,