1- # Ship serverless code as you write it. No builds, no deploys -- just run.
2- from typing import ClassVar
3-
1+ # Ship serverless code as you write it. No builds, no deploys — just run.
42from pydantic import model_validator
53
64from .constants import (
7- DEFAULT_PYTHON_VERSION ,
5+ GPU_BASE_IMAGE_PYTHON_VERSION ,
86 get_image_name ,
7+ local_python_version ,
98)
109from .injection import build_injection_cmd
1110from .load_balancer_sls_resource import (
@@ -26,23 +25,6 @@ class LiveServerlessMixin:
2625 runtime, not by the Docker image.
2726 """
2827
29- _image_type : ClassVar [str ] = (
30- "" # override in subclasses: 'gpu', 'cpu', 'lb', 'lb-cpu'
31- )
32-
33- @property
34- def _live_image (self ) -> str :
35- python_version = getattr (self , "python_version" , None ) or DEFAULT_PYTHON_VERSION
36- return get_image_name (self ._image_type , python_version )
37-
38- @property
39- def imageName (self ):
40- return self ._live_image
41-
42- @imageName .setter
43- def imageName (self , value ):
44- pass
45-
4628 def _create_new_template (self ) -> PodTemplate :
4729 """Create template with dockerArgs for process injection."""
4830 template = super ()._create_new_template () # type: ignore[misc]
@@ -59,54 +41,50 @@ def _configure_existing_template(self) -> None:
5941class LiveServerless (LiveServerlessMixin , ServerlessEndpoint ):
6042 """GPU-only live serverless endpoint."""
6143
62- _image_type : ClassVar [str ] = "gpu"
63-
6444 @model_validator (mode = "before" )
6545 @classmethod
6646 def set_live_serverless_template (cls , data : dict ):
6747 """Set default GPU image for Live Serverless."""
68- python_version = data .get ("python_version" ) or DEFAULT_PYTHON_VERSION
69- data ["imageName" ] = get_image_name ("gpu" , python_version )
48+ if "imageName" not in data :
49+ python_version = data .get ("python_version" ) or GPU_BASE_IMAGE_PYTHON_VERSION
50+ data ["imageName" ] = get_image_name ("gpu" , python_version )
7051 return data
7152
7253
7354class CpuLiveServerless (LiveServerlessMixin , CpuServerlessEndpoint ):
7455 """CPU-only live serverless endpoint with automatic disk sizing."""
7556
76- _image_type : ClassVar [str ] = "cpu"
77-
7857 @model_validator (mode = "before" )
7958 @classmethod
8059 def set_live_serverless_template (cls , data : dict ):
8160 """Set default CPU image for Live Serverless."""
82- python_version = data .get ("python_version" ) or DEFAULT_PYTHON_VERSION
83- data ["imageName" ] = get_image_name ("cpu" , python_version )
61+ if "imageName" not in data :
62+ python_version = data .get ("python_version" ) or local_python_version ()
63+ data ["imageName" ] = get_image_name ("cpu" , python_version )
8464 return data
8565
8666
8767class LiveLoadBalancer (LiveServerlessMixin , LoadBalancerSlsResource ):
8868 """Live load-balanced endpoint."""
8969
90- _image_type : ClassVar [str ] = "lb"
91-
9270 @model_validator (mode = "before" )
9371 @classmethod
9472 def set_live_lb_template (cls , data : dict ):
9573 """Set default image for Live Load-Balanced endpoint."""
96- python_version = data .get ("python_version" ) or DEFAULT_PYTHON_VERSION
97- data ["imageName" ] = get_image_name ("lb" , python_version )
74+ if "imageName" not in data :
75+ python_version = data .get ("python_version" ) or GPU_BASE_IMAGE_PYTHON_VERSION
76+ data ["imageName" ] = get_image_name ("lb" , python_version )
9877 return data
9978
10079
10180class CpuLiveLoadBalancer (LiveServerlessMixin , CpuLoadBalancerSlsResource ):
10281 """CPU-only live load-balanced endpoint."""
10382
104- _image_type : ClassVar [str ] = "lb-cpu"
105-
10683 @model_validator (mode = "before" )
10784 @classmethod
10885 def set_live_cpu_lb_template (cls , data : dict ):
10986 """Set default CPU image for Live Load-Balanced endpoint."""
110- python_version = data .get ("python_version" ) or DEFAULT_PYTHON_VERSION
111- data ["imageName" ] = get_image_name ("lb-cpu" , python_version )
87+ if "imageName" not in data :
88+ python_version = data .get ("python_version" ) or local_python_version ()
89+ data ["imageName" ] = get_image_name ("lb-cpu" , python_version )
11290 return data
0 commit comments