gmicloud 0.1.4__py3-none-any.whl → 0.1.6__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.
- gmicloud/__init__.py +12 -1
- gmicloud/_internal/_client/_artifact_client.py +126 -56
- gmicloud/_internal/_client/_http_client.py +5 -1
- gmicloud/_internal/_client/_iam_client.py +107 -42
- gmicloud/_internal/_client/_task_client.py +75 -30
- gmicloud/_internal/_enums.py +13 -0
- gmicloud/_internal/_manager/_artifact_manager.py +100 -5
- gmicloud/_internal/_manager/_iam_manager.py +36 -0
- gmicloud/_internal/_manager/_task_manager.py +88 -12
- gmicloud/_internal/_models.py +121 -12
- gmicloud/client.py +194 -69
- gmicloud/tests/test_artifacts.py +14 -15
- gmicloud/tests/test_tasks.py +1 -1
- gmicloud-0.1.6.dist-info/METADATA +147 -0
- gmicloud-0.1.6.dist-info/RECORD +27 -0
- {gmicloud-0.1.4.dist-info → gmicloud-0.1.6.dist-info}/WHEEL +1 -1
- gmicloud-0.1.4.dist-info/METADATA +0 -250
- gmicloud-0.1.4.dist-info/RECORD +0 -26
- {gmicloud-0.1.4.dist-info → gmicloud-0.1.6.dist-info}/top_level.txt +0 -0
    
        gmicloud/_internal/_models.py
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 | 
            -
            from typing import Optional, List
         | 
| 1 | 
            +
            from typing import Optional, List, Union
         | 
| 2 2 | 
             
            from datetime import datetime
         | 
| 3 3 |  | 
| 4 4 | 
             
            from pydantic import BaseModel
         | 
| 5 | 
            -
            from gmicloud._internal._enums import BuildStatus, TaskEndpointStatus
         | 
| 5 | 
            +
            from gmicloud._internal._enums import BuildStatus, TaskStatus, TaskEndpointStatus, ModelParameterType
         | 
| 6 6 |  | 
| 7 7 |  | 
| 8 8 | 
             
            class BigFileMetadata(BaseModel):
         | 
| @@ -24,6 +24,7 @@ class ArtifactMetadata(BaseModel): | |
| 24 24 | 
             
                artifact_description: Optional[str] = ""  # Description of the artifact.
         | 
| 25 25 | 
             
                artifact_tags: Optional[List[str]] = ""  # Comma-separated tags for categorizing the artifact.
         | 
| 26 26 | 
             
                artifact_volume_path: Optional[str] = ""  # Path to the volume where the artifact is stored.
         | 
| 27 | 
            +
                artifact_template_id: Optional[str] = ""  # The template ID used to create this artifact.
         | 
| 27 28 |  | 
| 28 29 |  | 
| 29 30 | 
             
            class ArtifactData(BaseModel):
         | 
| @@ -69,6 +70,7 @@ class CreateArtifactRequest(BaseModel): | |
| 69 70 | 
             
                artifact_name: str  # The name of the artifact to create.
         | 
| 70 71 | 
             
                artifact_description: Optional[str] = ""  # Description of the artifact.
         | 
| 71 72 | 
             
                artifact_tags: Optional[List[str]] = None  # Tags for the artifact, separated by commas.
         | 
| 73 | 
            +
                model_parameters: Optional[List["ModelParameter"]] = None  # Parameters for the artifact.
         | 
| 72 74 |  | 
| 73 75 |  | 
| 74 76 | 
             
            class CreateArtifactResponse(BaseModel):
         | 
| @@ -130,7 +132,7 @@ class DeleteBigfileResponse(BaseModel): | |
| 130 132 | 
             
                status: Optional[str] = ""  # Status of the deletion process.
         | 
| 131 133 |  | 
| 132 134 |  | 
| 133 | 
            -
            class  | 
| 135 | 
            +
            class GetPublicTemplatesResponse(BaseModel):
         | 
| 134 136 | 
             
                """
         | 
| 135 137 | 
             
                Response containing a list of artifact templates.
         | 
| 136 138 | 
             
                """
         | 
| @@ -141,24 +143,61 @@ class ArtifactTemplate(BaseModel): | |
| 141 143 | 
             
                """
         | 
| 142 144 | 
             
                Template for creating an artifact.
         | 
| 143 145 | 
             
                """
         | 
| 144 | 
            -
                 | 
| 145 | 
            -
                 | 
| 146 | 
            -
                 | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 146 | 
            +
                template_id: str  # Unique identifier for the artifact template.
         | 
| 147 | 
            +
                template_data: Optional["TemplateData"] = None  # Data for the artifact template.
         | 
| 148 | 
            +
                template_metadata: Optional["TemplateMetadata"] = None  # Metadata for the artifact template.
         | 
| 149 | 
            +
             | 
| 150 | 
            +
             | 
| 151 | 
            +
            class TemplateMetadata(BaseModel):
         | 
| 152 | 
            +
                """
         | 
| 153 | 
            +
                Metadata for an artifact template.
         | 
| 154 | 
            +
                """
         | 
| 155 | 
            +
                create_at: Optional[str] = None  # Timestamp when the template was created.
         | 
| 156 | 
            +
                create_by: Optional[str] = ""  # ID of the user who created the template.
         | 
| 157 | 
            +
                create_by_org_id: Optional[str] = ""  # ID of the organization to which the user belongs.
         | 
| 158 | 
            +
                is_public: Optional[bool] = False  # Indicates if the template is public.
         | 
| 159 | 
            +
                update_at: Optional[str] = None  # Timestamp when the template was last updated.
         | 
| 160 | 
            +
                update_by: Optional[str] = ""  # ID of the user who last updated the template.
         | 
| 161 | 
            +
             | 
| 162 | 
            +
             | 
| 163 | 
            +
            class TemplateData(BaseModel):
         | 
| 164 | 
            +
                """
         | 
| 165 | 
            +
                Data for an artifact template.
         | 
| 166 | 
            +
                """
         | 
| 167 | 
            +
                description: Optional[str] = ""  # Description of the artifact template.
         | 
| 168 | 
            +
                icon_link: Optional[str] = ""  # Link to the icon for the artifact template.
         | 
| 169 | 
            +
                image_link: Optional[str] = ""  # Link to the image for the artifact template.
         | 
| 170 | 
            +
                model_parameters: Optional[List["ModelParameter"]] = None  # Parameters for the artifact template.
         | 
| 171 | 
            +
                name: Optional[str] = ""  # Name of the artifact template.
         | 
| 172 | 
            +
                ray: Optional["RayContent"] = None  # Template for Ray-based artifacts.
         | 
| 149 173 | 
             
                resources: Optional["ResourcesTemplate"] = None  # Resource allocation template.
         | 
| 174 | 
            +
                tags: Optional[List[str]] = None  # Tags associated with the artifact template.
         | 
| 175 | 
            +
                volume_path: Optional[str] = ""  # Path to the volume where the artifact is stored.
         | 
| 176 | 
            +
             | 
| 150 177 |  | 
| 178 | 
            +
            class ModelParameter(BaseModel):
         | 
| 179 | 
            +
                """
         | 
| 180 | 
            +
                Parameter for an artifact template.
         | 
| 181 | 
            +
                """
         | 
| 182 | 
            +
                category: Optional[str] = ""  # Category of the parameter.
         | 
| 183 | 
            +
                display_name: Optional[str] = ""  # Display name of the parameter.
         | 
| 184 | 
            +
                key: Optional[str] = ""  # Key for the parameter.
         | 
| 185 | 
            +
                max: Optional[float] = 0  # Maximum value for the parameter.
         | 
| 186 | 
            +
                min: Optional[float] = 0  # Minimum value for the parameter.
         | 
| 187 | 
            +
                step: Optional[float] = 0  # Step value for the parameter.
         | 
| 188 | 
            +
                type: Optional[ModelParameterType] = ModelParameterType.TEXT  # Type of the parameter (e.g., numeric, bool, text).
         | 
| 189 | 
            +
                value: Optional[Union[int, float, bool, str]] = ""  # Default value for the parameter.
         | 
| 151 190 |  | 
| 152 | 
            -
            class  | 
| 191 | 
            +
            class RayContent(BaseModel):
         | 
| 153 192 | 
             
                deployment_name: Optional[str] = ""  # Name of the deployment.
         | 
| 154 193 | 
             
                file_path: Optional[str] = ""  # Path to the task file in storage.
         | 
| 155 | 
            -
                version: Optional[str] = ""  # Version of Ray used.
         | 
| 156 194 |  | 
| 157 195 |  | 
| 158 196 | 
             
            class ResourcesTemplate(BaseModel):
         | 
| 159 197 | 
             
                cpu: Optional[int] = 0  # Number of CPU cores allocated.
         | 
| 160 198 | 
             
                memory: Optional[int] = 0  # Amount of RAM (in GB) allocated.
         | 
| 161 199 | 
             
                gpu: Optional[int] = 0  # Number of GPUs allocated.
         | 
| 200 | 
            +
                gpu_name: Optional[str] = ""  # Type the GPU allocated.
         | 
| 162 201 |  | 
| 163 202 |  | 
| 164 203 | 
             
            class CreateArtifactFromTemplateRequest(BaseModel):
         | 
| @@ -211,7 +250,6 @@ class RayTaskConfig(BaseModel): | |
| 211 250 | 
             
                Configuration settings for Ray tasks.
         | 
| 212 251 | 
             
                """
         | 
| 213 252 | 
             
                artifact_id: Optional[str] = ""  # Associated artifact ID.
         | 
| 214 | 
            -
                ray_version: Optional[str] = ""  # Version of Ray used.
         | 
| 215 253 | 
             
                ray_cluster_image: Optional[str] = ""  # Docker image for the Ray cluster.
         | 
| 216 254 | 
             
                file_path: Optional[str] = ""  # Path to the task file in storage.
         | 
| 217 255 | 
             
                deployment_name: Optional[str] = ""  # Name of the deployment.
         | 
| @@ -259,6 +297,7 @@ class TaskConfig(BaseModel): | |
| 259 297 | 
             
                """
         | 
| 260 298 | 
             
                Configuration data for a task.
         | 
| 261 299 | 
             
                """
         | 
| 300 | 
            +
                task_name: Optional[str] = ""  # Name of the task.
         | 
| 262 301 | 
             
                ray_task_config: Optional[RayTaskConfig] = None  # Configuration for a Ray-based task.
         | 
| 263 302 | 
             
                task_scheduling: Optional[TaskScheduling] = None  # Scheduling configuration for the task.
         | 
| 264 303 | 
             
                create_timestamp: Optional[int] = 0  # Timestamp when the task was created.
         | 
| @@ -290,7 +329,7 @@ class Task(BaseModel): | |
| 290 329 | 
             
                config: Optional[TaskConfig] = None  # Configuration data for the task.
         | 
| 291 330 | 
             
                endpoint_info: Optional[EndpointInfo] = None  # Additional information about the task endpoint.
         | 
| 292 331 | 
             
                cluster_endpoints: Optional[List[EndpointInfo]] = None  # Endpoints for the task cluster.
         | 
| 293 | 
            -
                task_status: Optional[ | 
| 332 | 
            +
                task_status: Optional[TaskStatus] = ""  # Status of the task.
         | 
| 294 333 | 
             
                readiness_status: Optional[str] = ""  # Readiness status of the task.
         | 
| 295 334 | 
             
                user_preference: Optional[UserPreference] = None  # User preference for the task.
         | 
| 296 335 |  | 
| @@ -373,3 +412,73 @@ class LoginRequest(BaseModel): | |
| 373 412 | 
             
                """
         | 
| 374 413 | 
             
                email: str  # User email.
         | 
| 375 414 | 
             
                password: str  # User password.
         | 
| 415 | 
            +
             | 
| 416 | 
            +
             | 
| 417 | 
            +
            class User(BaseModel):
         | 
| 418 | 
            +
                """
         | 
| 419 | 
            +
                User information.
         | 
| 420 | 
            +
                """
         | 
| 421 | 
            +
                id: Optional[str] = ""  # User ID.
         | 
| 422 | 
            +
                email: Optional[str] = ""  # User email.
         | 
| 423 | 
            +
                firstName: Optional[str] = ""  # User first name.
         | 
| 424 | 
            +
                lastName: Optional[str] = ""  # User last name.
         | 
| 425 | 
            +
             | 
| 426 | 
            +
             | 
| 427 | 
            +
            class Organization(BaseModel):
         | 
| 428 | 
            +
                """
         | 
| 429 | 
            +
                Organization information.
         | 
| 430 | 
            +
                """
         | 
| 431 | 
            +
                id: Optional[str] = ""  # Organization ID.
         | 
| 432 | 
            +
                role: Optional[str] = ""  # Organization role.
         | 
| 433 | 
            +
             | 
| 434 | 
            +
             | 
| 435 | 
            +
            class ProfileResponse(BaseModel):
         | 
| 436 | 
            +
                """
         | 
| 437 | 
            +
                Response object for user profile.
         | 
| 438 | 
            +
                """
         | 
| 439 | 
            +
                user: User  # User information.
         | 
| 440 | 
            +
                organization: Organization  # Organization information.
         | 
| 441 | 
            +
             | 
| 442 | 
            +
             | 
| 443 | 
            +
            class CreateAPIKeyRequest(BaseModel):
         | 
| 444 | 
            +
                """
         | 
| 445 | 
            +
                Request object for creating an API key.
         | 
| 446 | 
            +
                """
         | 
| 447 | 
            +
                name: str  # Name of the API key.
         | 
| 448 | 
            +
                type: Optional[str] = ""  # Type of the API key.
         | 
| 449 | 
            +
                expiresAt: Optional[int] = 0  # Expiration timestamp for the API key.
         | 
| 450 | 
            +
             | 
| 451 | 
            +
             | 
| 452 | 
            +
            class CreateAPIKeyResponse(BaseModel):
         | 
| 453 | 
            +
                """
         | 
| 454 | 
            +
                Response object for creating an API key.
         | 
| 455 | 
            +
                """
         | 
| 456 | 
            +
                key: str  # The created API key.
         | 
| 457 | 
            +
             | 
| 458 | 
            +
             | 
| 459 | 
            +
            class APIKey(BaseModel):
         | 
| 460 | 
            +
                """
         | 
| 461 | 
            +
                API key information.
         | 
| 462 | 
            +
                """
         | 
| 463 | 
            +
                id: Optional[str] = ""  # API key ID.
         | 
| 464 | 
            +
                name: Optional[str] = ""  # API key name.
         | 
| 465 | 
            +
                type: Optional[str] = ""  # API key type.
         | 
| 466 | 
            +
                partialKey: Optional[str] = ""  # Partial key for the API key.
         | 
| 467 | 
            +
                expiresAt: Optional[int] = 0  # Expiration timestamp for the API key.
         | 
| 468 | 
            +
                createdAt: Optional[int] = 0  # Creation timestamp for the API key.
         | 
| 469 | 
            +
                owner: Optional[User] = None  # Owner of the API key.
         | 
| 470 | 
            +
             | 
| 471 | 
            +
             | 
| 472 | 
            +
            class GetAPIKeysResponse(BaseModel):
         | 
| 473 | 
            +
                """
         | 
| 474 | 
            +
                Response object for getting a list of API keys.
         | 
| 475 | 
            +
                """
         | 
| 476 | 
            +
                keys: list[APIKey]  # List of API keys.
         | 
| 477 | 
            +
             | 
| 478 | 
            +
             | 
| 479 | 
            +
            class GetSelfAPIKeyResponse(BaseModel):
         | 
| 480 | 
            +
                """
         | 
| 481 | 
            +
                Response object for getting the API key of the current user.
         | 
| 482 | 
            +
                """
         | 
| 483 | 
            +
                key: APIKey  # The API key of the current user.
         | 
| 484 | 
            +
                organization: Optional[Organization] = None  # Organization information.
         | 
    
        gmicloud/client.py
    CHANGED
    
    | @@ -1,14 +1,18 @@ | |
| 1 1 | 
             
            import os
         | 
| 2 2 | 
             
            import time
         | 
| 3 | 
            +
            import logging
         | 
| 3 4 |  | 
| 4 5 | 
             
            from typing import Optional
         | 
| 5 6 |  | 
| 6 7 | 
             
            from ._internal._client._iam_client import IAMClient
         | 
| 7 8 | 
             
            from ._internal._manager._artifact_manager import ArtifactManager
         | 
| 8 9 | 
             
            from ._internal._manager._task_manager import TaskManager
         | 
| 9 | 
            -
            from ._internal. | 
| 10 | 
            +
            from ._internal._manager._iam_manager import IAMManager
         | 
| 11 | 
            +
            from ._internal._enums import BuildStatus, TaskStatus, TaskEndpointStatus
         | 
| 10 12 | 
             
            from ._internal._models import Task, TaskConfig, RayTaskConfig, TaskScheduling, ReplicaResource
         | 
| 11 13 |  | 
| 14 | 
            +
            logger = logging.getLogger(__name__)
         | 
| 15 | 
            +
             | 
| 12 16 |  | 
| 13 17 | 
             
            class Client:
         | 
| 14 18 | 
             
                def __init__(self, client_id: Optional[str] = "", email: Optional[str] = "", password: Optional[str] = ""):
         | 
| @@ -32,74 +36,7 @@ class Client: | |
| 32 36 | 
             
                    # Managers are lazily initialized through private attributes
         | 
| 33 37 | 
             
                    self._artifact_manager = None
         | 
| 34 38 | 
             
                    self._task_manager = None
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def create_task_from_artifact_template(self, artifact_template_id: str, task_scheduling: TaskScheduling) -> Task:
         | 
| 37 | 
            -
                    """
         | 
| 38 | 
            -
                    Create a task from a template.
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                    :param artifact_template_id: The ID of the artifact template to use.
         | 
| 41 | 
            -
                    :param task_scheduling: The scheduling configuration for the task.
         | 
| 42 | 
            -
                    :return: A `Task` object containing the details of the created task.
         | 
| 43 | 
            -
                    :rtype: Task
         | 
| 44 | 
            -
                    """
         | 
| 45 | 
            -
                    if not artifact_template_id or not artifact_template_id.strip():
         | 
| 46 | 
            -
                        raise ValueError("Artifact Template ID must be provided.")
         | 
| 47 | 
            -
                    if not task_scheduling:
         | 
| 48 | 
            -
                        raise ValueError("Task Scheduling must be provided.")
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                    artifact_manager = self.artifact_manager
         | 
| 51 | 
            -
                    task_manager = self.task_manager
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                    templates = artifact_manager.get_artifact_templates()
         | 
| 54 | 
            -
                    template = None
         | 
| 55 | 
            -
                    for v in templates:
         | 
| 56 | 
            -
                        if v.artifact_template_id == artifact_template_id:
         | 
| 57 | 
            -
                            template = v
         | 
| 58 | 
            -
                    if not template:
         | 
| 59 | 
            -
                        raise ValueError(f"Template with ID {artifact_template_id} not found.")
         | 
| 60 | 
            -
                    if not template.ray:
         | 
| 61 | 
            -
                        raise ValueError("Template does not contain Ray configuration.")
         | 
| 62 | 
            -
                    if not template.resources:
         | 
| 63 | 
            -
                        raise ValueError("Template does not contain resource configuration.")
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                    artifact_id = artifact_manager.create_artifact_from_template(artifact_template_id)
         | 
| 66 | 
            -
                    # Wait for the artifact to be ready
         | 
| 67 | 
            -
                    while True:
         | 
| 68 | 
            -
                        try:
         | 
| 69 | 
            -
                            artifact = artifact_manager.get_artifact(artifact_id)
         | 
| 70 | 
            -
                            print(f"Artifact status: {artifact.build_status}")
         | 
| 71 | 
            -
                            # Wait until the artifact is ready
         | 
| 72 | 
            -
                            if artifact.build_status == BuildStatus.SUCCESS:
         | 
| 73 | 
            -
                                break
         | 
| 74 | 
            -
                        except Exception as e:
         | 
| 75 | 
            -
                            raise e
         | 
| 76 | 
            -
                        # Wait for 2 seconds
         | 
| 77 | 
            -
                        time.sleep(2)
         | 
| 78 | 
            -
                    try:
         | 
| 79 | 
            -
                        # Create a task
         | 
| 80 | 
            -
                        task = task_manager.create_task(Task(
         | 
| 81 | 
            -
                            config=TaskConfig(
         | 
| 82 | 
            -
                                ray_task_config=RayTaskConfig(
         | 
| 83 | 
            -
                                    ray_version=template.ray.version,
         | 
| 84 | 
            -
                                    file_path=template.ray.file_path,
         | 
| 85 | 
            -
                                    artifact_id=artifact_id,
         | 
| 86 | 
            -
                                    deployment_name=template.ray.deployment_name,
         | 
| 87 | 
            -
                                    replica_resource=ReplicaResource(
         | 
| 88 | 
            -
                                        cpu=template.resources.cpu,
         | 
| 89 | 
            -
                                        ram_gb=template.resources.memory,
         | 
| 90 | 
            -
                                        gpu=template.resources.gpu,
         | 
| 91 | 
            -
                                    ),
         | 
| 92 | 
            -
                                ),
         | 
| 93 | 
            -
                                task_scheduling=task_scheduling,
         | 
| 94 | 
            -
                            ),
         | 
| 95 | 
            -
                        ))
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                        # Start the task
         | 
| 98 | 
            -
                        task_manager.start_task(task.task_id)
         | 
| 99 | 
            -
                    except Exception as e:
         | 
| 100 | 
            -
                        raise e
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                    return task
         | 
| 39 | 
            +
                    self._iam_manager = None
         | 
| 103 40 |  | 
| 104 41 | 
             
                @property
         | 
| 105 42 | 
             
                def artifact_manager(self):
         | 
| @@ -120,3 +57,191 @@ class Client: | |
| 120 57 | 
             
                    if self._task_manager is None:
         | 
| 121 58 | 
             
                        self._task_manager = TaskManager(self.iam_client)
         | 
| 122 59 | 
             
                    return self._task_manager
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                @property
         | 
| 62 | 
            +
                def iam_manager(self):
         | 
| 63 | 
            +
                    """
         | 
| 64 | 
            +
                    Lazy initialization for IAMManager.
         | 
| 65 | 
            +
                    Ensures the Client instance controls its lifecycle.
         | 
| 66 | 
            +
                    """
         | 
| 67 | 
            +
                    if self._iam_manager is None:
         | 
| 68 | 
            +
                        self._iam_manager = IAMManager(self.iam_client)
         | 
| 69 | 
            +
                    return self._iam_manager
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                # def list_templates(self) -> list[str]:
         | 
| 72 | 
            +
                #     """
         | 
| 73 | 
            +
                #     List all public templates.
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                #     :return: A list of template names.
         | 
| 76 | 
            +
                #     :rtype: list[str]
         | 
| 77 | 
            +
                #     """
         | 
| 78 | 
            +
                #     template_names = []
         | 
| 79 | 
            +
                #     try: 
         | 
| 80 | 
            +
                #         templates = self.artifact_manager.get_public_templates()
         | 
| 81 | 
            +
                #         for template in templates:
         | 
| 82 | 
            +
                #             if template.template_data and template.template_data.name:
         | 
| 83 | 
            +
                #                 template_names.append(template.template_data.name)
         | 
| 84 | 
            +
                #         return template_names
         | 
| 85 | 
            +
                #     except Exception as e:
         | 
| 86 | 
            +
                #         logger.error(f"Failed to get artifact templates, Error: {e}")
         | 
| 87 | 
            +
                #         return []
         | 
| 88 | 
            +
                    
         | 
| 89 | 
            +
                # def wait_for_artifact_ready(self, artifact_id: str, timeout_s: int = 900) -> None:
         | 
| 90 | 
            +
                #     """
         | 
| 91 | 
            +
                #     Wait for an artifact to be ready.
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                #     :param artifact_id: The ID of the artifact to wait for.
         | 
| 94 | 
            +
                #     :param timeout_s: The timeout in seconds.
         | 
| 95 | 
            +
                #     :return: None
         | 
| 96 | 
            +
                #     """
         | 
| 97 | 
            +
                #     artifact_manager = self.artifact_manager
         | 
| 98 | 
            +
                #     start_time = time.time()
         | 
| 99 | 
            +
                #     while True:
         | 
| 100 | 
            +
                #         try:
         | 
| 101 | 
            +
                #             artifact = artifact_manager.get_artifact(artifact_id)
         | 
| 102 | 
            +
                #             if artifact.build_status == BuildStatus.SUCCESS:
         | 
| 103 | 
            +
                #                 return
         | 
| 104 | 
            +
                #             elif artifact.build_status in [BuildStatus.FAILED, BuildStatus.TIMEOUT, BuildStatus.CANCELLED]:
         | 
| 105 | 
            +
                #                 raise Exception(f"Artifact build failed, status: {artifact.build_status}")
         | 
| 106 | 
            +
                #         except Exception as e:
         | 
| 107 | 
            +
                #             logger.error(f"Failed to get artifact, Error: {e}")
         | 
| 108 | 
            +
                #         if time.time() - start_time > timeout_s:
         | 
| 109 | 
            +
                #             raise Exception(f"Artifact build takes more than {timeout_s // 60} minutes. Testing aborted.")
         | 
| 110 | 
            +
                #         time.sleep(10)
         | 
| 111 | 
            +
                    
         | 
| 112 | 
            +
                # def create_artifact_from_template(self, artifact_template_name: str) -> tuple[str, ReplicaResource]:
         | 
| 113 | 
            +
                #     """
         | 
| 114 | 
            +
                #     Create an artifact from a template.
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                #     :param artifact_template_name: The name of the template to use.
         | 
| 117 | 
            +
                #     :return: A tuple containing the artifact ID and the recommended replica resources.
         | 
| 118 | 
            +
                #     :rtype: tuple[str, ReplicaResource]
         | 
| 119 | 
            +
                #     """
         | 
| 120 | 
            +
                #     artifact_manager = self.artifact_manager
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                #     recommended_replica_resources = None
         | 
| 123 | 
            +
                #     template_id = None
         | 
| 124 | 
            +
                #     try:
         | 
| 125 | 
            +
                #         templates = artifact_manager.get_public_templates()
         | 
| 126 | 
            +
                #     except Exception as e:
         | 
| 127 | 
            +
                #         logger.error(f"Failed to get artifact templates, Error: {e}")
         | 
| 128 | 
            +
                #     for template in templates:
         | 
| 129 | 
            +
                #         if template.template_data and template.template_data.name == artifact_template_name:
         | 
| 130 | 
            +
                #             resources_template = template.template_data.resources
         | 
| 131 | 
            +
                #             recommended_replica_resources = ReplicaResource(
         | 
| 132 | 
            +
                #                 cpu=resources_template.cpu,
         | 
| 133 | 
            +
                #                 ram_gb=resources_template.memory,
         | 
| 134 | 
            +
                #                 gpu=resources_template.gpu,
         | 
| 135 | 
            +
                #                 gpu_name=resources_template.gpu_name,
         | 
| 136 | 
            +
                #             )
         | 
| 137 | 
            +
                #             template_id = template.template_id
         | 
| 138 | 
            +
                #             break
         | 
| 139 | 
            +
                #     if not template_id:
         | 
| 140 | 
            +
                #         raise ValueError(f"Template with name {artifact_template_name} not found.")
         | 
| 141 | 
            +
                #     try: 
         | 
| 142 | 
            +
                #         artifact_id = artifact_manager.create_artifact_from_template(template_id)
         | 
| 143 | 
            +
                #         self.wait_for_artifact_ready(artifact_id)
         | 
| 144 | 
            +
                #         return artifact_id, recommended_replica_resources
         | 
| 145 | 
            +
                #     except Exception as e:
         | 
| 146 | 
            +
                #         logger.error(f"Failed to create artifact from template, Error: {e}")
         | 
| 147 | 
            +
                #         raise e
         | 
| 148 | 
            +
                    
         | 
| 149 | 
            +
                # def create_task(self, artifact_id: str, replica_resources: ReplicaResource, task_scheduling: TaskScheduling) -> str:
         | 
| 150 | 
            +
                #     """
         | 
| 151 | 
            +
                #     Create a task.
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                #     :param artifact_id: The ID of the artifact to use.
         | 
| 154 | 
            +
                #     :param replica_resources: The recommended replica resources.
         | 
| 155 | 
            +
                #     :param task_scheduling: The scheduling configuration for the task.
         | 
| 156 | 
            +
                #     :return: The ID of the created task.
         | 
| 157 | 
            +
                #     :rtype: str
         | 
| 158 | 
            +
                #     """
         | 
| 159 | 
            +
                #     task_manager = self.task_manager
         | 
| 160 | 
            +
                #     task = None
         | 
| 161 | 
            +
                #     try:
         | 
| 162 | 
            +
                #         task = task_manager.create_task(Task(
         | 
| 163 | 
            +
                #             config=TaskConfig(
         | 
| 164 | 
            +
                #                 ray_task_config=RayTaskConfig(
         | 
| 165 | 
            +
                #                     artifact_id=artifact_id,
         | 
| 166 | 
            +
                #                     file_path="serve",
         | 
| 167 | 
            +
                #                     deployment_name="app",
         | 
| 168 | 
            +
                #                     replica_resource=replica_resources,
         | 
| 169 | 
            +
                #                 ),
         | 
| 170 | 
            +
                #                 task_scheduling = task_scheduling,
         | 
| 171 | 
            +
                #             ),
         | 
| 172 | 
            +
                #         ))
         | 
| 173 | 
            +
                #     except Exception as e:
         | 
| 174 | 
            +
                #         logger.error(f"Failed to create task, Error: {e}")
         | 
| 175 | 
            +
                #         raise e
         | 
| 176 | 
            +
                #     return task.task_id 
         | 
| 177 | 
            +
                
         | 
| 178 | 
            +
                # def start_task_and_wait(self, task_id: str, timeout_s: int = 900) -> Task:
         | 
| 179 | 
            +
                #     """
         | 
| 180 | 
            +
                #     Start a task and wait for it to be ready.
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                #     :param task_id: The ID of the task to start.
         | 
| 183 | 
            +
                #     :param timeout_s: The timeout in seconds.
         | 
| 184 | 
            +
                #     :return: The task object.
         | 
| 185 | 
            +
                #     :rtype: Task
         | 
| 186 | 
            +
                #     """
         | 
| 187 | 
            +
                #     task_manager = self.task_manager
         | 
| 188 | 
            +
                #     # trigger start task
         | 
| 189 | 
            +
                #     try:
         | 
| 190 | 
            +
                #         task_manager.start_task(task_id)
         | 
| 191 | 
            +
                #         logger.info(f"Started task ID: {task_id}")
         | 
| 192 | 
            +
                #     except Exception as e:
         | 
| 193 | 
            +
                #         logger.error(f"Failed to start task, Error: {e}")
         | 
| 194 | 
            +
                #         raise e
         | 
| 195 | 
            +
                    
         | 
| 196 | 
            +
                #     start_time = time.time()
         | 
| 197 | 
            +
                #     while True:
         | 
| 198 | 
            +
                #         try:
         | 
| 199 | 
            +
                #             task = task_manager.get_task(task_id)
         | 
| 200 | 
            +
                #             if task.task_status == TaskStatus.RUNNING:
         | 
| 201 | 
            +
                #                 return task
         | 
| 202 | 
            +
                #             elif task.task_status in [TaskStatus.NEEDSTOP, TaskStatus.ARCHIVED]:
         | 
| 203 | 
            +
                #                 raise Exception(f"Unexpected task status after starting: {task.task_status}")
         | 
| 204 | 
            +
                #             # Also check endpoint status. 
         | 
| 205 | 
            +
                #             elif task.task_status == TaskStatus.RUNNING:
         | 
| 206 | 
            +
                #                 if task.endpoint_info and task.endpoint_info.endpoint_status == TaskEndpointStatus.RUNNING:
         | 
| 207 | 
            +
                #                     return task
         | 
| 208 | 
            +
                #                 elif task.endpoint_info and task.endpoint_info.endpoint_status in [TaskEndpointStatus.UNKNOWN, TaskEndpointStatus.ARCHIVED]:
         | 
| 209 | 
            +
                #                     raise Exception(f"Unexpected endpoint status after starting: {task.endpoint_info.endpoint_status}")
         | 
| 210 | 
            +
                #                 else:
         | 
| 211 | 
            +
                #                     logger.info(f"Pending endpoint starting. endpoint status: {task.endpoint_info.endpoint_status}")
         | 
| 212 | 
            +
                #             else:
         | 
| 213 | 
            +
                #                 logger.info(f"Pending task starting. Task status: {task.task_status}")
         | 
| 214 | 
            +
             | 
| 215 | 
            +
                #         except Exception as e:
         | 
| 216 | 
            +
                #             logger.error(f"Failed to get task, Error: {e}")
         | 
| 217 | 
            +
                #         if time.time() - start_time > timeout_s:
         | 
| 218 | 
            +
                #             raise Exception(f"Task creation takes more than {timeout_s // 60} minutes. Testing aborted.")
         | 
| 219 | 
            +
                #         time.sleep(10)
         | 
| 220 | 
            +
             | 
| 221 | 
            +
                # def stop_task(self, task_id: str, timeout_s: int = 900):
         | 
| 222 | 
            +
                #     task_manager = self.task_manager
         | 
| 223 | 
            +
                #     try:
         | 
| 224 | 
            +
                #         self.task_manager.stop_task(task_id)
         | 
| 225 | 
            +
                #         logger.info(f"Stopping task ID: {task_id}")
         | 
| 226 | 
            +
                #     except Exception as e:
         | 
| 227 | 
            +
                #         logger.error(f"Failed to stop task, Error: {e}")
         | 
| 228 | 
            +
                #     task_manager = self.task_manager
         | 
| 229 | 
            +
                #     start_time = time.time()
         | 
| 230 | 
            +
                #     while True:
         | 
| 231 | 
            +
                #         try:
         | 
| 232 | 
            +
                #             task = task_manager.get_task(task_id)
         | 
| 233 | 
            +
                #             if task.task_status == TaskStatus.IDLE:
         | 
| 234 | 
            +
                #                 break
         | 
| 235 | 
            +
                #         except Exception as e:
         | 
| 236 | 
            +
                #             logger.error(f"Failed to get task, Error: {e}")
         | 
| 237 | 
            +
                #         if time.time() - start_time > timeout_s:
         | 
| 238 | 
            +
                #             raise Exception(f"Task stopping takes more than {timeout_s // 60} minutes. Testing aborted.")
         | 
| 239 | 
            +
                #         time.sleep(10)
         | 
| 240 | 
            +
             | 
| 241 | 
            +
                # def archive_task(self, task_id: str, timeout_s: int = 900):
         | 
| 242 | 
            +
                #     task_manager = self.task_manager
         | 
| 243 | 
            +
                #     try:
         | 
| 244 | 
            +
                #         self.task_manager.archive_task(task_id)
         | 
| 245 | 
            +
                #         logger.info(f"Archived task ID: {task_id}")
         | 
| 246 | 
            +
                #     except Exception as e:
         | 
| 247 | 
            +
                #         logger.error(f"Failed to archive task, Error: {e}")  
         | 
    
        gmicloud/tests/test_artifacts.py
    CHANGED
    
    | @@ -251,24 +251,23 @@ class TestArtifactManager(unittest.TestCase): | |
| 251 251 | 
             
                        self.artifact_manager.delete_bigfile("nonexistent_id", "file.txt")
         | 
| 252 252 | 
             
                    self.assertTrue("Artifact not found" in str(context.exception))
         | 
| 253 253 |  | 
| 254 | 
            -
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient. | 
| 255 | 
            -
                def test_get_artifact_templates_returns_templates(self,  | 
| 256 | 
            -
                     | 
| 257 | 
            -
             | 
| 258 | 
            -
                    templates = self.artifact_manager.get_artifact_templates()
         | 
| 254 | 
            +
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient.get_public_templates')
         | 
| 255 | 
            +
                def test_get_artifact_templates_returns_templates(self, mock_get_public_templates):
         | 
| 256 | 
            +
                    mock_get_public_templates.return_value = [ArtifactTemplate(template_id="1", template_data=TemplateData(name="Template1"))]
         | 
| 257 | 
            +
                    templates = self.artifact_manager.get_public_templates()
         | 
| 259 258 | 
             
                    self.assertEqual(len(templates), 1)
         | 
| 260 | 
            -
                    self.assertEqual(templates[0]. | 
| 261 | 
            -
                    self.assertEqual(templates[0]. | 
| 259 | 
            +
                    self.assertEqual(templates[0].template_id, "1")
         | 
| 260 | 
            +
                    self.assertEqual(templates[0].template_data.name, "Template1")
         | 
| 262 261 |  | 
| 263 | 
            -
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient. | 
| 264 | 
            -
                def test_get_artifact_templates_returns_empty_list_when_no_templates(self,  | 
| 265 | 
            -
                     | 
| 266 | 
            -
                    templates = self.artifact_manager. | 
| 262 | 
            +
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient.get_public_templates')
         | 
| 263 | 
            +
                def test_get_artifact_templates_returns_empty_list_when_no_templates(self, mock_get_public_templates):
         | 
| 264 | 
            +
                    mock_get_public_templates.return_value = []
         | 
| 265 | 
            +
                    templates = self.artifact_manager.get_public_templates()
         | 
| 267 266 | 
             
                    self.assertEqual(len(templates), 0)
         | 
| 268 267 |  | 
| 269 | 
            -
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient. | 
| 270 | 
            -
                def test_get_artifact_templates_raises_error_on_failure(self,  | 
| 271 | 
            -
                     | 
| 268 | 
            +
                @patch('gmicloud._internal._client._artifact_client.ArtifactClient.get_public_templates')
         | 
| 269 | 
            +
                def test_get_artifact_templates_raises_error_on_failure(self, mock_get_public_templates):
         | 
| 270 | 
            +
                    mock_get_public_templates.side_effect = Exception("Failed to fetch templates")
         | 
| 272 271 | 
             
                    with self.assertRaises(Exception) as context:
         | 
| 273 | 
            -
                        self.artifact_manager. | 
| 272 | 
            +
                        self.artifact_manager.get_public_templates()
         | 
| 274 273 | 
             
                    self.assertTrue("Failed to fetch templates" in str(context.exception))
         | 
    
        gmicloud/tests/test_tasks.py
    CHANGED
    
    
| @@ -0,0 +1,147 @@ | |
| 1 | 
            +
            Metadata-Version: 2.2
         | 
| 2 | 
            +
            Name: gmicloud
         | 
| 3 | 
            +
            Version: 0.1.6
         | 
| 4 | 
            +
            Summary: GMI Cloud Python SDK
         | 
| 5 | 
            +
            Author-email: GMI <support@gmicloud.ai>
         | 
| 6 | 
            +
            License: MIT
         | 
| 7 | 
            +
            Classifier: Programming Language :: Python :: 3
         | 
| 8 | 
            +
            Classifier: License :: OSI Approved :: MIT License
         | 
| 9 | 
            +
            Classifier: Operating System :: OS Independent
         | 
| 10 | 
            +
            Requires-Python: >=3.6
         | 
| 11 | 
            +
            Description-Content-Type: text/markdown
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            # GMICloud SDK (Beta)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## Overview
         | 
| 16 | 
            +
            Before you start: Our service and GPU resource is currenly invite-only so please contact our team (getstarted@gmicloud.ai) to get invited if you don't have one yet.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            The GMI Inference Engine SDK provides a Python interface for deploying and managing machine learning models in production environments. It allows users to create model artifacts, schedule tasks for serving models, and call inference APIs easily.
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            This SDK streamlines the process of utilizing GMI Cloud capabilities such as deploying models with Kubernetes-based Ray services, managing resources automatically, and accessing model inference endpoints. With minimal setup, developers can focus on building ML solutions instead of infrastructure.
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            ## Features
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            - Artifact Management: Easily create, update, and manage ML model artifacts.
         | 
| 25 | 
            +
            - Task Management: Quickly create, schedule, and manage deployment tasks for model inference.
         | 
| 26 | 
            +
            - Usage Data Retrieval : Fetch and analyze usage data to optimize resource allocation.
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ## Installation
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            To install the SDK, use pip:
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            ```bash
         | 
| 33 | 
            +
            pip install gmicloud
         | 
| 34 | 
            +
            ```
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            ## Setup
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            You must configure authentication credentials for accessing the GMI Cloud API. 
         | 
| 39 | 
            +
            To create account and get log in info please visit **GMI inference platform: https://inference-engine.gmicloud.ai/**.
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            There are two ways to configure the SDK:
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ### Option 1: Using Environment Variables
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            Set the following environment variables:
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ```shell
         | 
| 48 | 
            +
            export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
         | 
| 49 | 
            +
            export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
         | 
| 50 | 
            +
            export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
         | 
| 51 | 
            +
            ```
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            ### Option 2: Passing Credentials as Parameters
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            Pass `client_id`, `email`, and `password` directly to the Client object when initializing it in your script:
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            ```python
         | 
| 58 | 
            +
            from gmicloud import Client
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            client = Client(client_id="<YOUR_CLIENT_ID>", email="<YOUR_EMAIL>", password="<YOUR_PASSWORD>")
         | 
| 61 | 
            +
            ```
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            ## Quick Start
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            ### 1. How to run the code in the example folder
         | 
| 66 | 
            +
            ```bash
         | 
| 67 | 
            +
            cd path/to/gmicloud-sdk
         | 
| 68 | 
            +
            # Create a virtual environment
         | 
| 69 | 
            +
            python -m venv venv
         | 
| 70 | 
            +
            source venv/bin/activate
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            pip install -r requirements.txt
         | 
| 73 | 
            +
            python -m examples.create_task_from_artifact_template.py
         | 
| 74 | 
            +
            ```
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            ### 2. Create an inference task from an artifact template
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            This is the simplest example to deploy an inference task using an existing artifact template:
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            Up-to-date code in /examples/create_task_from_artifact_template.py
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            ```python
         | 
| 83 | 
            +
            from datetime import datetime
         | 
| 84 | 
            +
            import os
         | 
| 85 | 
            +
            import sys
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            from gmicloud import *
         | 
| 88 | 
            +
            from examples.completion import call_chat_completion
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            cli = Client()
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            # List templates offered by GMI cloud 
         | 
| 93 | 
            +
            templates = cli.list_templates()
         | 
| 94 | 
            +
            print(f"Found {len(templates)} templates: {templates}")
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            # Pick a template from the list
         | 
| 97 | 
            +
            pick_template = "Llama-3.1-8B"
         | 
| 98 | 
            +
             | 
| 99 | 
            +
            # Create Artifact from template
         | 
| 100 | 
            +
            artifact_id, recommended_replica_resources = cli.create_artifact_from_template(templates[0])
         | 
| 101 | 
            +
            print(f"Created artifact {artifact_id} with recommended replica resources: {recommended_replica_resources}")
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            # Create Task based on Artifact
         | 
| 104 | 
            +
            task_id = cli.create_task(artifact_id, recommended_replica_resources, TaskScheduling(
         | 
| 105 | 
            +
                scheduling_oneoff=OneOffScheduling(
         | 
| 106 | 
            +
                    trigger_timestamp=int(datetime.now().timestamp()),
         | 
| 107 | 
            +
                    min_replicas=1,
         | 
| 108 | 
            +
                    max_replicas=1,
         | 
| 109 | 
            +
                )
         | 
| 110 | 
            +
            ))
         | 
| 111 | 
            +
            task = cli.task_manager.get_task(task_id)
         | 
| 112 | 
            +
            print(f"Task created: {task.config.task_name}. You can check details at https://inference-engine.gmicloud.ai/user-console/task")
         | 
| 113 | 
            +
             | 
| 114 | 
            +
            # Start Task and wait for it to be ready
         | 
| 115 | 
            +
            cli.start_task_and_wait(task.task_id)
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            # Testing with calling chat completion
         | 
| 118 | 
            +
            print(call_chat_completion(cli, task.task_id))
         | 
| 119 | 
            +
             | 
| 120 | 
            +
            ```
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            ## API Reference
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            ### Client
         | 
| 125 | 
            +
             | 
| 126 | 
            +
            Represents the entry point to interact with GMI Cloud APIs.
         | 
| 127 | 
            +
            Client(
         | 
| 128 | 
            +
            client_id: Optional[str] = "",
         | 
| 129 | 
            +
            email: Optional[str] = "",
         | 
| 130 | 
            +
            password: Optional[str] = ""
         | 
| 131 | 
            +
            )
         | 
| 132 | 
            +
             | 
| 133 | 
            +
            ### Artifact Management
         | 
| 134 | 
            +
             | 
| 135 | 
            +
            * get_artifact_templates(): Fetch a list of available artifact templates.
         | 
| 136 | 
            +
            * create_artifact_from_template(template_id: str): Create a model artifact from a given template.
         | 
| 137 | 
            +
            * get_artifact(artifact_id: str): Get details of a specific artifact.
         | 
| 138 | 
            +
             | 
| 139 | 
            +
            ### Task Management
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            * create_task_from_artifact_template(template_id: str, scheduling: TaskScheduling): Create and schedule a task using an
         | 
| 142 | 
            +
              artifact template.
         | 
| 143 | 
            +
            * start_task(task_id: str): Start a task.
         | 
| 144 | 
            +
            * get_task(task_id: str): Retrieve the status and details of a specific task.
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            ## Notes & Troubleshooting
         | 
| 147 | 
            +
            k
         |