Skip to content
Open
7 changes: 7 additions & 0 deletions src/tetra_rp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
DataCenter,
GpuGroup,
LiveServerless,
LoadBalancerSlsResource,
PodTemplate,
ResourceManager,
ServerlessResource,
ServerlessEndpoint,
runpod,
NetworkVolume,
)
from .core.resources.load_balancer_sls import LoadBalancerSls, endpoint # noqa: E402


__all__ = [
Expand All @@ -35,9 +38,13 @@
"DataCenter",
"GpuGroup",
"LiveServerless",
"LoadBalancerSlsResource",
"PodTemplate",
"ResourceManager",
"ServerlessResource",
"ServerlessEndpoint",
"runpod",
"NetworkVolume",
"LoadBalancerSls",
"endpoint",
]
54 changes: 43 additions & 11 deletions src/tetra_rp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from functools import wraps
from typing import List, Optional

from .core.resources import ResourceManager, ServerlessResource
from .core.resources import ResourceManager, ServerlessResource, LoadBalancerSlsResource
from .execute_class import create_remote_class
from .core.resources.load_balancer_sls.integration import create_load_balancer_sls_class
from .stubs import stub_resource

log = logging.getLogger(__name__)
Expand All @@ -26,7 +27,7 @@ def remote(

Args:
resource_config (ServerlessResource): Configuration object specifying the serverless resource
to be provisioned or used.
to be provisioned or used. Set resource_config.type="LB" for LoadBalancerSls mode.
dependencies (List[str], optional): A list of pip package names to be installed in the remote
environment before executing the function. Defaults to None.
system_dependencies (List[str], optional): A list of system packages to be installed in the remote
Expand All @@ -43,6 +44,7 @@ def remote(

Example:
```python
# Traditional serverless execution
@remote(
resource_config=my_resource_config,
dependencies=["numpy", "pandas"],
Expand All @@ -52,23 +54,53 @@ def remote(
async def my_function(data):
# Function logic here
pass

# LoadBalancerSls execution (Load Balancer mode)
@remote(
resource_config=my_resource_config,
type="LB",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the separate type attr if we're already detecting resources as load balancer sls resources?

dependencies=["torch", "transformers"]
)
class MLModel:
@endpoint(methods=['POST'])
def predict(self, data):
return result
```
"""

def decorator(func_or_class):
if inspect.isclass(func_or_class):
# Handle class decoration
return create_remote_class(
func_or_class,
resource_config,
dependencies,
system_dependencies,
accelerate_downloads,
hf_models_to_cache,
extra,
)
if isinstance(resource_config, LoadBalancerSlsResource):
# Use LoadBalancerSls (Load Balancer) mode
log.info(
f"Using LoadBalancerSls mode for class {func_or_class.__name__}"
)
return create_load_balancer_sls_class(
func_or_class,
resource_config,
dependencies,
system_dependencies,
extra,
)
else:
# Use traditional serverless execution
return create_remote_class(
func_or_class,
resource_config,
dependencies,
system_dependencies,
accelerate_downloads,
hf_models_to_cache,
extra,
)
else:
# Handle function decoration (unchanged)
if isinstance(resource_config, LoadBalancerSlsResource):
raise ValueError(
"LoadBalancerSlsResource can only be used with classes, not functions"
)

@wraps(func_or_class)
async def wrapper(*args, **kwargs):
resource_manager = ResourceManager()
Expand Down
2 changes: 2 additions & 0 deletions src/tetra_rp/core/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .cpu import CpuInstanceType
from .gpu import GpuGroup, GpuType, GpuTypeDetail
from .resource_manager import ResourceManager
from .load_balancer_sls_resource import LoadBalancerSlsResource
from .live_serverless import LiveServerless, CpuLiveServerless
from .serverless import (
ServerlessResource,
Expand All @@ -29,6 +30,7 @@
"GpuTypeDetail",
"JobOutput",
"LiveServerless",
"LoadBalancerSlsResource",
"ResourceManager",
"ServerlessResource",
"ServerlessEndpoint",
Expand Down
26 changes: 26 additions & 0 deletions src/tetra_rp/core/resources/load_balancer_sls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
LoadBalancerSls Package

This package provides LoadBalancerSls functionality for dual-capability remote execution,
supporting both HTTP endpoints and remote execution through a unified interface.
"""

from .client import LoadBalancerSls
from .endpoint import endpoint
from .exceptions import (
LoadBalancerSlsError,
LoadBalancerSlsConnectionError,
LoadBalancerSlsAuthenticationError,
LoadBalancerSlsExecutionError,
LoadBalancerSlsConfigurationError,
)

__all__ = [
"LoadBalancerSls",
"endpoint",
"LoadBalancerSlsError",
"LoadBalancerSlsConnectionError",
"LoadBalancerSlsAuthenticationError",
"LoadBalancerSlsExecutionError",
"LoadBalancerSlsConfigurationError",
]
Loading
Loading