gmicloud 0.1.5__py3-none-any.whl → 0.1.7__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.
@@ -0,0 +1,121 @@
1
+ import shlex
2
+ import os
3
+ import logging
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ def parse_server_command(cmd_str: str) -> tuple[str, dict, dict]:
8
+ """
9
+ parse server command
10
+ Maybe their are more than two types of server command
11
+ if not found, we can add more parse function
12
+ """
13
+ if "vllm serve" in cmd_str:
14
+ return ("vllm", *parse_server_vllm_command(cmd_str))
15
+ elif "sglang.launch_server" in cmd_str:
16
+ return ("sglang", *parse_server_sglang_command(cmd_str))
17
+ else:
18
+ raise ValueError(f"Unknown serve command: {cmd_str}")
19
+
20
+ def extract_env_and_args(tokens: list) -> tuple[dict, list]:
21
+ """
22
+ Extract environment variables from the tokens list.
23
+ and add the params or flags to environment variables
24
+ """
25
+ env_vars = {}
26
+ while tokens and '=' in tokens[0] and not tokens[0].startswith('--'):
27
+ key, value = tokens.pop(0).split('=', 1)
28
+ env_vars[key] = value
29
+ for k, v in env_vars.items():
30
+ os.environ[k] = v
31
+ return env_vars, tokens
32
+
33
+ def parse_flags_and_args(tokens: list) -> dict:
34
+ """
35
+ parse flags and args
36
+ include three types --flag=value and --flag value annd --flag
37
+ """
38
+ result = {}
39
+ i = 0
40
+ while i < len(tokens):
41
+ token = tokens[i]
42
+ if token.startswith('--'):
43
+ if '=' in token:
44
+ key, value = token[2:].split('=', 1)
45
+ result[key] = value.strip("'\"")
46
+ elif i + 1 < len(tokens) and not tokens[i + 1].startswith('--'):
47
+ result[token[2:]] = tokens[i + 1].strip("'\"")
48
+ i += 1
49
+ elif i + 1 < len(tokens) and not tokens[i + 1].startswith('-'):
50
+ result[token[1:]] = tokens[i + 1].strip("'\"")
51
+ i += 1
52
+ else:
53
+ result[token[2:]] = True
54
+ else:
55
+ logger.warning(f"Ignoring unknown token: {token}")
56
+ i += 1
57
+ return result
58
+
59
+ def parse_server_vllm_command(cmd_str: str) -> tuple[dict, dict]:
60
+ """ parse vllm command"""
61
+ tokens = shlex.split(cmd_str)
62
+ result = {}
63
+
64
+ # 提取环境变量
65
+ env_vars, tokens = extract_env_and_args(tokens)
66
+ if env_vars:
67
+ result["env_vars"] = env_vars
68
+
69
+ # vllm serve + model
70
+ if tokens[:2] != ['vllm', 'serve']:
71
+ raise ValueError("Invalid vllm serve command format. Example: vllm serve <model path>")
72
+
73
+ if len(tokens) < 3:
74
+ raise ValueError("Missing model path in vllm serve command. Example: vllm serve <model path>")
75
+
76
+ model_path = tokens[2]
77
+ result["model-path"] = model_path
78
+
79
+ flags = parse_flags_and_args(tokens[3:])
80
+ result.update(flags)
81
+ return (env_vars, result)
82
+
83
+ def parse_server_sglang_command(cmd_str: str) -> tuple[dict, dict]:
84
+ """ parse sglang command"""
85
+ tokens = shlex.split(cmd_str)
86
+ result = {}
87
+
88
+ # 提取环境变量
89
+ env_vars, tokens = extract_env_and_args(tokens)
90
+ if env_vars:
91
+ result["env_vars"] = env_vars
92
+ # python3 -m sglang.launch_server
93
+ if tokens[:3] != ['python3', '-m', 'sglang.launch_server'] and tokens[:3] != ['python', '-m', 'sglang.launch_server']:
94
+ raise ValueError("Invalid sglang command format. Example: python3 -m sglang.launch_server")
95
+
96
+ flags = parse_flags_and_args(tokens[3:])
97
+ result.update(flags)
98
+ return (env_vars, result)
99
+
100
+ def extract_gpu_num_from_serve_command(serve_args_dict: dict) -> int:
101
+ """ extract gpu num from serve command """
102
+ cmd_tp_size = 1
103
+ cmd_dp_size = 1
104
+ if "tensor-parallel-size" in serve_args_dict:
105
+ cmd_tp_size = int(serve_args_dict["tensor-parallel-size"])
106
+ elif "tp" in serve_args_dict:
107
+ cmd_tp_size = int(serve_args_dict["tp"])
108
+ elif "tp-size" in serve_args_dict:
109
+ cmd_tp_size = int(serve_args_dict["tp-size"])
110
+ if "data-parallel-size" in serve_args_dict:
111
+ cmd_dp_size = int(serve_args_dict["data-parallel-size"])
112
+ elif "dp" in serve_args_dict:
113
+ cmd_dp_size = int(serve_args_dict["dp"])
114
+ elif "dp-size" in serve_args_dict:
115
+ cmd_dp_size = int(serve_args_dict["dp-size"])
116
+ if "pipeline_parallel_size" in serve_args_dict or "pp" in serve_args_dict:
117
+ raise ValueError("Pipeline parallel size is not supported.")
118
+ cmd_gpu_num = cmd_tp_size * cmd_dp_size
119
+ if cmd_gpu_num > 8:
120
+ raise ValueError("Only support up to 8 GPUs for single task replica.")
121
+ return cmd_gpu_num
@@ -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, TaskStatus, TaskEndpointStatus
5
+ from gmicloud._internal._enums import BuildStatus, TaskStatus, TaskEndpointStatus, ModelParameterType
6
6
 
7
7
 
8
8
  class BigFileMetadata(BaseModel):
@@ -22,9 +22,13 @@ class ArtifactMetadata(BaseModel):
22
22
  user_id: Optional[str] = "" # The user ID associated with this artifact.
23
23
  artifact_name: Optional[str] = "" # Name of the artifact.
24
24
  artifact_description: Optional[str] = "" # Description of the artifact.
25
- artifact_tags: Optional[List[str]] = "" # Comma-separated tags for categorizing the artifact.
25
+ artifact_tags: Optional[List[str]] = None # Changed from List[str] with default to Optional[List[str]]
26
26
  artifact_volume_path: Optional[str] = "" # Path to the volume where the artifact is stored.
27
27
  artifact_template_id: Optional[str] = "" # The template ID used to create this artifact.
28
+ artifact_icon_link: Optional[str] = "" # Link to the icon for the artifact.
29
+ is_public: Optional[bool] = False # Indicates if the artifact is public.
30
+ org_id: Optional[str] = "" # Organization ID associated with this artifact.
31
+ update_by: Optional[str] = "" # User ID who last updated the artifact.
28
32
 
29
33
 
30
34
  class ArtifactData(BaseModel):
@@ -43,6 +47,29 @@ class ArtifactData(BaseModel):
43
47
  update_at: Optional[datetime] # Timestamp when the artifact was last updated.
44
48
 
45
49
 
50
+ class EnvParameter(BaseModel):
51
+ """
52
+ Environment parameter for an artifact.
53
+ """
54
+ key: str # Key for the environment parameter.
55
+ value: str # Value for the environment parameter.
56
+
57
+
58
+ class ArtifactDetails(BaseModel):
59
+ """
60
+ Additional details for an artifact.
61
+ """
62
+ model_description: Optional[str] = "" # Description of the model.
63
+
64
+
65
+ class ArtifactParameters(BaseModel):
66
+ """
67
+ Parameters for an artifact.
68
+ """
69
+ env_parameters: Optional[List[EnvParameter]] = None # Environment parameters.
70
+ model_parameters: Optional[List["ModelParameter"]] = None # Model parameters.
71
+
72
+
46
73
  class Artifact(BaseModel):
47
74
  """
48
75
  Representation of an artifact, including its data and metadata.
@@ -53,6 +80,7 @@ class Artifact(BaseModel):
53
80
  build_status: Optional[BuildStatus] = None # Status of the artifact build (e.g., in progress, succeeded, failed).
54
81
  artifact_data: Optional[ArtifactData] = None # Data associated with the artifact.
55
82
  artifact_metadata: Optional[ArtifactMetadata] = None # Metadata describing the artifact.
83
+ artifact_parameters: Optional[ArtifactParameters] = None # Parameters for the artifact.
56
84
  big_files_metadata: Optional[List[BigFileMetadata]] = None # Metadata for large files associated with the artifact.
57
85
 
58
86
 
@@ -69,7 +97,12 @@ class CreateArtifactRequest(BaseModel):
69
97
  """
70
98
  artifact_name: str # The name of the artifact to create.
71
99
  artifact_description: Optional[str] = "" # Description of the artifact.
72
- artifact_tags: Optional[List[str]] = None # Tags for the artifact, separated by commas.
100
+ artifact_tags: Optional[List[str]] = None # Tags for the artifact.
101
+ deployment_type: Optional[str] = "" # Deployment type
102
+ template_id: Optional[str] = "" # Template ID
103
+ env_parameters: Optional[List["EnvParameter"]] = None # Environment parameters.
104
+ model_description: Optional[str] = "" # Description of the model.
105
+ model_parameters: Optional[List["ModelParameter"]] = None # Parameters for the artifact.
73
106
 
74
107
 
75
108
  class CreateArtifactResponse(BaseModel):
@@ -78,9 +111,10 @@ class CreateArtifactResponse(BaseModel):
78
111
  """
79
112
  artifact_id: str # ID of the newly created artifact.
80
113
  upload_link: str # URL to upload the artifact data.
114
+ artifact_icon_link: Optional[str] = "" # Link to the icon for the artifact.
81
115
 
82
116
 
83
- class GetBigFileUploadUrlRequest(BaseModel):
117
+ class ResumableUploadLinkRequest(BaseModel):
84
118
  """
85
119
  Request to generate a pre-signed URL for uploading large files.
86
120
  """
@@ -89,7 +123,7 @@ class GetBigFileUploadUrlRequest(BaseModel):
89
123
  file_type: Optional[str] = "" # MIME type of the file.
90
124
 
91
125
 
92
- class GetBigFileUploadUrlResponse(BaseModel):
126
+ class ResumableUploadLinkResponse(BaseModel):
93
127
  """
94
128
  Response containing a pre-signed upload URL for large files.
95
129
  """
@@ -97,6 +131,13 @@ class GetBigFileUploadUrlResponse(BaseModel):
97
131
  upload_link: str # Pre-signed upload URL for the file.
98
132
 
99
133
 
134
+ class RebuildArtifactRequest(BaseModel):
135
+ """
136
+ Request object for rebuilding an artifact.
137
+ """
138
+ artifact_id: str # ID of the artifact to rebuild.
139
+
140
+
100
141
  class RebuildArtifactResponse(BaseModel):
101
142
  """
102
143
  Response object after rebuilding an artifact.
@@ -105,6 +146,91 @@ class RebuildArtifactResponse(BaseModel):
105
146
  build_status: BuildStatus # Status of the artifact build (e.g., in progress, succeeded, failed).
106
147
 
107
148
 
149
+ class EndpointInfo(BaseModel):
150
+ """
151
+ Additional information about the task endpoint.
152
+ """
153
+ endpoint_status: Optional[TaskEndpointStatus] = None # Current status of the task (e.g., running, stopped).
154
+ endpoint_url: Optional[str] = "" # URL for accessing the task endpoint.
155
+
156
+
157
+ class GetAllArtifactsWithEndpointsResponse(BaseModel):
158
+ """
159
+ Response containing a list of all artifacts with their endpoints.
160
+ """
161
+ artifact_id: str # Unique identifier for the artifact.
162
+ artifact_data: Optional[ArtifactData] = None # Data associated with the artifact.
163
+ artifact_metadata: Optional[ArtifactMetadata] = None # Metadata describing the artifact.
164
+ artifact_details: Optional[ArtifactDetails] = None # Additional details about the artifact.
165
+ artifact_parameters: Optional[ArtifactParameters] = None # Parameters for the artifact.
166
+ big_files_metadata: Optional[List[BigFileMetadata]] = None # Metadata for large files.
167
+ endpoints: Optional[List[EndpointInfo]] = None # Endpoints associated with the artifact.
168
+
169
+
170
+ class GetArtifactResponse(BaseModel):
171
+ """
172
+ Response containing the details of an artifact.
173
+ """
174
+ artifact_id: str # Unique identifier for the artifact.
175
+ artifact_link: Optional[str] = "" # Link to access the artifact.
176
+ artifact_resource: Optional[str] = "" # Resource associated with the artifact.
177
+ build_file_name: Optional[str] = "" # Name of the file used for the build.
178
+ build_status: Optional[str] = "" # Status of the artifact build.
179
+ artifact_metadata: Optional[ArtifactMetadata] = None # Metadata describing the artifact.
180
+ artifact_parameters: Optional[ArtifactParameters] = None # Parameters for the artifact.
181
+ big_files_metadata: Optional[List[BigFileMetadata]] = None # Metadata for large files.
182
+
183
+
184
+ class GetPublicArtifactsResponse(BaseModel):
185
+ """
186
+ Response containing public artifact details.
187
+ """
188
+ artifact_id: str # Unique identifier for the artifact.
189
+ artifact_data: Optional[ArtifactData] = None # Data associated with the artifact.
190
+ artifact_metadata: Optional[ArtifactMetadata] = None # Metadata describing the artifact.
191
+ artifact_details: Optional[ArtifactDetails] = None # Additional details about the artifact.
192
+ artifact_parameters: Optional[ArtifactParameters] = None # Parameters for the artifact.
193
+ endpoints: Optional[List[EndpointInfo]] = None # Endpoints associated with the artifact.
194
+
195
+
196
+ class UpdateArtifactRequestBody(BaseModel):
197
+ """
198
+ Request object for updating an artifact.
199
+ """
200
+ artifact_name: Optional[str] = "" # The name of the artifact.
201
+ artifact_description: Optional[str] = "" # Description of the artifact.
202
+ artifact_tags: Optional[List[str]] = None # Tags for the artifact.
203
+ env_parameters: Optional[List[EnvParameter]] = None # Environment parameters.
204
+ model_description: Optional[str] = "" # Description of the model.
205
+ model_parameters: Optional[List["ModelParameter"]] = None # Parameters for the artifact.
206
+ need_update_icon: Optional[bool] = False # Whether to update the artifact icon.
207
+
208
+
209
+ class UpdateArtifactResponse(BaseModel):
210
+ """
211
+ Response object after updating an artifact.
212
+ """
213
+ artifact_id: str # ID of the updated artifact.
214
+ status: str # Status of the update operation.
215
+ artifact_icon_link: Optional[str] = "" # Link to the icon for the artifact.
216
+
217
+
218
+ class GetTemplatesResponse(BaseModel):
219
+ """
220
+ Response containing a list of artifact templates.
221
+ """
222
+ artifact_templates: list["Template"] # List of artifact templates.
223
+
224
+
225
+ class Template(BaseModel):
226
+ """
227
+ Template for creating an artifact.
228
+ """
229
+ template_id: str # Unique identifier for the artifact template.
230
+ template_data: Optional["TemplateData"] = None # Data for the artifact template.
231
+ template_metadata: Optional["TemplateMetadata"] = None # Metadata for the artifact template.
232
+
233
+
108
234
  class DeleteArtifactResponse(BaseModel):
109
235
  """
110
236
  Response object after deleting an artifact.
@@ -131,22 +257,6 @@ class DeleteBigfileResponse(BaseModel):
131
257
  status: Optional[str] = "" # Status of the deletion process.
132
258
 
133
259
 
134
- class GetPublicTemplatesResponse(BaseModel):
135
- """
136
- Response containing a list of artifact templates.
137
- """
138
- artifact_templates: list["ArtifactTemplate"] # List of artifact templates.
139
-
140
-
141
- class ArtifactTemplate(BaseModel):
142
- """
143
- Template for creating an artifact.
144
- """
145
- template_id: str # Unique identifier for the artifact template.
146
- template_data: Optional["TemplateData"] = None # Data for the artifact template.
147
- template_metadata: Optional["TemplateMetadata"] = None # Metadata for the artifact template.
148
-
149
-
150
260
  class TemplateMetadata(BaseModel):
151
261
  """
152
262
  Metadata for an artifact template.
@@ -157,6 +267,8 @@ class TemplateMetadata(BaseModel):
157
267
  is_public: Optional[bool] = False # Indicates if the template is public.
158
268
  update_at: Optional[str] = None # Timestamp when the template was last updated.
159
269
  update_by: Optional[str] = "" # ID of the user who last updated the template.
270
+ status: Optional[str] = "" # Status of the template.
271
+
160
272
 
161
273
  class TemplateData(BaseModel):
162
274
  """
@@ -165,13 +277,28 @@ class TemplateData(BaseModel):
165
277
  description: Optional[str] = "" # Description of the artifact template.
166
278
  icon_link: Optional[str] = "" # Link to the icon for the artifact template.
167
279
  image_link: Optional[str] = "" # Link to the image for the artifact template.
280
+ model_parameters: Optional[List["ModelParameter"]] = None # Parameters for the artifact template.
168
281
  name: Optional[str] = "" # Name of the artifact template.
169
282
  ray: Optional["RayContent"] = None # Template for Ray-based artifacts.
170
283
  resources: Optional["ResourcesTemplate"] = None # Resource allocation template.
171
284
  tags: Optional[List[str]] = None # Tags associated with the artifact template.
172
285
  volume_path: Optional[str] = "" # Path to the volume where the artifact is stored.
286
+ env_parameters: Optional[List["EnvParameter"]] = None # Added missing field
173
287
 
174
288
 
289
+ class ModelParameter(BaseModel):
290
+ """
291
+ Parameter for an artifact template.
292
+ """
293
+ category: Optional[str] = "" # Category of the parameter.
294
+ display_name: Optional[str] = "" # Display name of the parameter.
295
+ key: Optional[str] = "" # Key for the parameter.
296
+ max: Optional[float] = 0 # Maximum value for the parameter.
297
+ min: Optional[float] = 0 # Minimum value for the parameter.
298
+ step: Optional[float] = 0 # Step value for the parameter.
299
+ type: Optional[ModelParameterType] = ModelParameterType.TEXT # Type of the parameter (e.g., numeric, bool, text).
300
+ value: Optional[Union[int, float, bool, str]] = "" # Default value for the parameter.
301
+
175
302
  class RayContent(BaseModel):
176
303
  deployment_name: Optional[str] = "" # Name of the deployment.
177
304
  file_path: Optional[str] = "" # Path to the task file in storage.
@@ -188,8 +315,9 @@ class CreateArtifactFromTemplateRequest(BaseModel):
188
315
  """
189
316
  Request object to create a new artifact from a template.
190
317
  """
191
- user_id: str # The user ID creating the artifact.
318
+ # user_id: str # The user ID creating the artifact.
192
319
  artifact_template_id: str # The ID of the artifact template to use.
320
+ env_parameters: Optional[List["EnvParameter"]] = None # Environment parameters.
193
321
 
194
322
 
195
323
  class CreateArtifactFromTemplateResponse(BaseModel):
@@ -234,7 +362,6 @@ class RayTaskConfig(BaseModel):
234
362
  Configuration settings for Ray tasks.
235
363
  """
236
364
  artifact_id: Optional[str] = "" # Associated artifact ID.
237
- ray_version: Optional[str] = "" # Version of Ray used.
238
365
  ray_cluster_image: Optional[str] = "" # Docker image for the Ray cluster.
239
366
  file_path: Optional[str] = "" # Path to the task file in storage.
240
367
  deployment_name: Optional[str] = "" # Name of the deployment.
@@ -282,20 +409,13 @@ class TaskConfig(BaseModel):
282
409
  """
283
410
  Configuration data for a task.
284
411
  """
412
+ task_name: Optional[str] = "" # Name of the task.
285
413
  ray_task_config: Optional[RayTaskConfig] = None # Configuration for a Ray-based task.
286
414
  task_scheduling: Optional[TaskScheduling] = None # Scheduling configuration for the task.
287
415
  create_timestamp: Optional[int] = 0 # Timestamp when the task was created.
288
416
  last_update_timestamp: Optional[int] = 0 # Timestamp when the task was last updated.
289
417
 
290
418
 
291
- class EndpointInfo(BaseModel):
292
- """
293
- Additional information about the task endpoint.
294
- """
295
- endpoint_status: Optional[TaskEndpointStatus] = None # Current status of the task (e.g., running, stopped).
296
- endpoint_url: Optional[str] = "" # URL for accessing the task endpoint.
297
-
298
-
299
419
  class UserPreference(BaseModel):
300
420
  """
301
421
  User preference for a task.
@@ -313,8 +433,8 @@ class Task(BaseModel):
313
433
  config: Optional[TaskConfig] = None # Configuration data for the task.
314
434
  endpoint_info: Optional[EndpointInfo] = None # Additional information about the task endpoint.
315
435
  cluster_endpoints: Optional[List[EndpointInfo]] = None # Endpoints for the task cluster.
316
- task_status: Optional[TaskStatus] = "" # Status of the task.
317
- readiness_status: Optional[str] = "" # Readiness status of the task.
436
+ task_status: Optional[TaskStatus] = None # Status of the task.
437
+ readiness_status: Optional[str] = None # Readiness status of the task.
318
438
  user_preference: Optional[UserPreference] = None # User preference for the task.
319
439
 
320
440