|
1 | 1 | # Ship serverless code as you write it. No builds, no deploys -- just run. |
2 | 2 | from typing import Any, ClassVar |
3 | 3 |
|
| 4 | +# Ship serverless code as you write it. No builds, no deploys — just run. |
4 | 5 | from pydantic import model_validator |
5 | 6 |
|
6 | 7 | from .constants import ( |
7 | | - DEFAULT_PYTHON_VERSION, |
| 8 | + GPU_BASE_IMAGE_PYTHON_VERSION, |
8 | 9 | get_image_name, |
| 10 | + local_python_version, |
9 | 11 | ) |
10 | 12 | from .injection import build_injection_cmd |
11 | 13 | from .load_balancer_sls_resource import ( |
@@ -77,46 +79,58 @@ def _configure_existing_template(self) -> None: |
77 | 79 | class LiveServerless(LiveServerlessMixin, ServerlessEndpoint): |
78 | 80 | """GPU-only live serverless endpoint.""" |
79 | 81 |
|
80 | | - _image_type: ClassVar[str] = "gpu" |
81 | | -
|
82 | 82 | @model_validator(mode="before") |
83 | 83 | @classmethod |
84 | 84 | def set_live_serverless_template(cls, data: dict): |
85 | 85 | """Default to the GPU Flash runtime image when none is supplied.""" |
86 | 86 | return _apply_default_live_image(data, "gpu") |
| 87 | + """Set default GPU image for Live Serverless.""" |
| 88 | + if "imageName" not in data: |
| 89 | + python_version = data.get("python_version") or GPU_BASE_IMAGE_PYTHON_VERSION |
| 90 | + data["imageName"] = get_image_name("gpu", python_version) |
| 91 | + return data |
87 | 92 |
|
88 | 93 |
|
89 | 94 | class CpuLiveServerless(LiveServerlessMixin, CpuServerlessEndpoint): |
90 | 95 | """CPU-only live serverless endpoint with automatic disk sizing.""" |
91 | 96 |
|
92 | | - _image_type: ClassVar[str] = "cpu" |
93 | | -
|
94 | 97 | @model_validator(mode="before") |
95 | 98 | @classmethod |
96 | 99 | def set_live_serverless_template(cls, data: dict): |
97 | 100 | """Default to the CPU Flash runtime image when none is supplied.""" |
98 | 101 | return _apply_default_live_image(data, "cpu") |
| 102 | + """Set default CPU image for Live Serverless.""" |
| 103 | + if "imageName" not in data: |
| 104 | + python_version = data.get("python_version") or local_python_version() |
| 105 | + data["imageName"] = get_image_name("cpu", python_version) |
| 106 | + return data |
99 | 107 |
|
100 | 108 |
|
101 | 109 | class LiveLoadBalancer(LiveServerlessMixin, LoadBalancerSlsResource): |
102 | 110 | """Live load-balanced endpoint.""" |
103 | 111 |
|
104 | | - _image_type: ClassVar[str] = "lb" |
105 | | -
|
106 | 112 | @model_validator(mode="before") |
107 | 113 | @classmethod |
108 | 114 | def set_live_lb_template(cls, data: dict): |
109 | 115 | """Default to the LB Flash runtime image when none is supplied.""" |
110 | 116 | return _apply_default_live_image(data, "lb") |
| 117 | + """Set default image for Live Load-Balanced endpoint.""" |
| 118 | + if "imageName" not in data: |
| 119 | + python_version = data.get("python_version") or GPU_BASE_IMAGE_PYTHON_VERSION |
| 120 | + data["imageName"] = get_image_name("lb", python_version) |
| 121 | + return data |
111 | 122 |
|
112 | 123 |
|
113 | 124 | class CpuLiveLoadBalancer(LiveServerlessMixin, CpuLoadBalancerSlsResource): |
114 | 125 | """CPU-only live load-balanced endpoint.""" |
115 | 126 |
|
116 | | - _image_type: ClassVar[str] = "lb-cpu" |
117 | | -
|
118 | 127 | @model_validator(mode="before") |
119 | 128 | @classmethod |
120 | 129 | def set_live_cpu_lb_template(cls, data: dict): |
121 | 130 | """Default to the CPU LB Flash runtime image when none is supplied.""" |
122 | 131 | return _apply_default_live_image(data, "lb-cpu") |
| 132 | + """Set default CPU image for Live Load-Balanced endpoint.""" |
| 133 | + if "imageName" not in data: |
| 134 | + python_version = data.get("python_version") or local_python_version() |
| 135 | + data["imageName"] = get_image_name("lb-cpu", python_version) |
| 136 | + return data |
0 commit comments