gmicloud 0.1.0__py3-none-any.whl → 0.1.1__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 CHANGED
@@ -12,7 +12,8 @@ from ._internal._models import (
12
12
  OneOffScheduling,
13
13
  DailyScheduling,
14
14
  DailyTrigger,
15
- ArtifactTemplate
15
+ ArtifactTemplate,
16
+ CreateArtifactFromTemplateResponse
16
17
  )
17
18
  from ._internal._enums import (
18
19
  BuildStatus,
@@ -37,5 +38,6 @@ __all__ = [
37
38
  "DailyTrigger",
38
39
  "ArtifactTemplate",
39
40
  "BuildStatus",
40
- "TaskEndpointStatus"
41
+ "TaskEndpointStatus",
42
+ "CreateArtifactFromTemplateResponse"
41
43
  ]
@@ -42,11 +42,10 @@ class ArtifactClient:
42
42
  return Artifact.model_validate(result)
43
43
 
44
44
  @handle_refresh_token
45
- def get_all_artifacts(self, user_id: str) -> List[Artifact]:
45
+ def get_all_artifacts(self) -> List[Artifact]:
46
46
  """
47
- Fetches all artifacts for a given user ID.
47
+ Fetches all artifacts.
48
48
 
49
- :param user_id: The ID of the user whose artifacts are being fetched.
50
49
  :return: A list of Artifact objects.
51
50
  :rtype: List[Artifact]
52
51
  """
@@ -54,7 +53,7 @@ class ArtifactClient:
54
53
  ACCESS_TOKEN_HEADER: self.iam_client.get_access_token(),
55
54
  CLIENT_ID_HEADER: self.iam_client.get_client_id()
56
55
  }
57
- result = self.client.get("/get_all_artifacts", custom_headers, {"user_id": user_id})
56
+ result = self.client.get("/get_all_artifacts", custom_headers)
58
57
  if not result:
59
58
  return []
60
59
  return [Artifact.model_validate(item) for item in result]
@@ -77,12 +76,11 @@ class ArtifactClient:
77
76
  return CreateArtifactResponse.model_validate(result)
78
77
 
79
78
  @handle_refresh_token
80
- def create_artifact_from_template(self,
81
- request: CreateArtifactFromTemplateRequest) -> CreateArtifactFromTemplateResponse:
79
+ def create_artifact_from_template(self, artifact_template_id: str) -> CreateArtifactFromTemplateResponse:
82
80
  """
83
81
  Creates a new artifact in the service.
84
82
 
85
- :param request: The request object containing artifact details.
83
+ :param artifact_template_id: The ID of the artifact template to use.
86
84
  :return: The response object containing the created artifact details.
87
85
  :rtype: CreateArtifactFromTemplateResponse
88
86
  """
@@ -91,7 +89,7 @@ class ArtifactClient:
91
89
  CLIENT_ID_HEADER: self.iam_client.get_client_id()
92
90
  }
93
91
  result = self.client.post("/create_artifact_from_template", custom_headers,
94
- request.model_dump())
92
+ {"artifact_template_id": artifact_template_id})
95
93
 
96
94
  return CreateArtifactFromTemplateResponse.model_validate(result)
97
95
 
@@ -39,7 +39,6 @@ class HTTPClient:
39
39
  :return: The JSON response parsed as a Python dictionary.
40
40
  :raises APIError: If the request fails or the response is invalid.
41
41
  """
42
- print("data=", data)
43
42
  url = self._prepare_url(endpoint)
44
43
  headers = {
45
44
  ACCEPT_HEADER: JSON_CONTENT_TYPE,
@@ -52,21 +51,7 @@ class HTTPClient:
52
51
 
53
52
  response = None
54
53
  try:
55
- # if method == HTTP_METHOD_POST:
56
- # response = requests.post(url, json=data, headers=headers)
57
- # elif method == HTTP_METHOD_GET:
58
- # response = requests.get(url, params=params, headers=headers)
59
- # elif method == HTTP_METHOD_PATCH:
60
- # response = requests.patch(url, data=data, headers=headers)
61
- # elif method == HTTP_METHOD_DELETE:
62
- # response = requests.delete(url, params=params, headers=headers)
63
- # else:
64
- # raise APIError(f"Unsupported HTTP method: {method}")
65
54
  response = requests.request(method, url, params=params, json=data, headers=headers)
66
- # response = method_map[method](url, json=data if method != HTTP_METHOD_GET else None,
67
- # params=params, headers=headers)
68
-
69
- print("=============", response.text)
70
55
  if response.status_code == 401:
71
56
  raise UnauthorizedError("Access token expired or invalid.")
72
57
  elif response.status_code != 200 and response.status_code != 201:
@@ -39,7 +39,7 @@ class TaskClient:
39
39
  return Task.model_validate(result)
40
40
 
41
41
  @handle_refresh_token
42
- def get_all_tasks(self, user_id: str) -> GetAllTasksResponse:
42
+ def get_all_tasks(self) -> GetAllTasksResponse:
43
43
  """
44
44
  Retrieves all tasks from the task service.
45
45
 
@@ -50,7 +50,7 @@ class TaskClient:
50
50
  ACCESS_TOKEN_HEADER: self.iam_client.get_access_token(),
51
51
  CLIENT_ID_HEADER: self.iam_client.get_client_id()
52
52
  }
53
- result = self.client.get("/get_tasks", custom_headers, {"user_id": user_id})
53
+ result = self.client.get("/get_tasks", custom_headers)
54
54
  if not result:
55
55
  return GetAllTasksResponse(tasks=[])
56
56
 
@@ -43,7 +43,7 @@ class ArtifactManager:
43
43
  :return: A list of Artifact objects associated with the user.
44
44
  :rtype: List[Artifact]
45
45
  """
46
- return self.artifact_client.get_all_artifacts(self.iam_client.get_user_id())
46
+ return self.artifact_client.get_all_artifacts()
47
47
 
48
48
  def create_artifact(
49
49
  self,
@@ -63,27 +63,25 @@ class ArtifactManager:
63
63
  if not artifact_name or not artifact_name.strip():
64
64
  raise ValueError("Artifact name is required and cannot be empty.")
65
65
 
66
- req = CreateArtifactRequest(user_id=self.iam_client.get_user_id(), artifact_name=artifact_name,
66
+ req = CreateArtifactRequest(artifact_name=artifact_name,
67
67
  artifact_description=description,
68
68
  artifact_tags=tags, )
69
69
 
70
70
  return self.artifact_client.create_artifact(req)
71
71
 
72
- def create_artifact_from_template(self, artifact_template_id: str) -> CreateArtifactFromTemplateResponse:
72
+ def create_artifact_from_template(self, artifact_template_id: str) -> str:
73
73
  """
74
74
  Create a new artifact for a user using a template.
75
75
 
76
76
  :param artifact_template_id: The ID of the template to use for the artifact.
77
- :return: A `CreateArtifactResponse` object containing information about the created artifact.
78
- :rtype: CreateArtifactResponse
77
+ :return: The `artifact_id` of the created artifact.
78
+ :rtype: str
79
+ :raises ValueError: If `artifact_template_id` is None or empty.
79
80
  """
80
81
  if not artifact_template_id or not artifact_template_id.strip():
81
82
  raise ValueError("Artifact template ID is required and cannot be empty.")
82
83
 
83
- req = CreateArtifactFromTemplateRequest(user_id=self.iam_client.get_user_id(),
84
- artifact_template_id=artifact_template_id)
85
-
86
- return self.artifact_client.create_artifact_from_template(req)
84
+ return self.artifact_client.create_artifact_from_template(artifact_template_id).artifact_id
87
85
 
88
86
  def rebuild_artifact(self, artifact_id: str) -> RebuildArtifactResponse:
89
87
  """
@@ -106,7 +106,6 @@ class TaskManager:
106
106
  self._validate_file_path(config_file_path)
107
107
 
108
108
  task = self._read_file_and_parse_task(config_file_path)
109
- print("================", task)
110
109
  task.task_id = task_id
111
110
  task.config.ray_task_config.artifact_id = artifact_id
112
111
 
@@ -213,7 +212,6 @@ class TaskManager:
213
212
  file_data = file.read()
214
213
 
215
214
  try:
216
- print("!!!!!!!!!!!1", file_data)
217
215
  task = Task.model_validate_json(file_data) # Ensure Task has a static method for model validation.
218
216
  except Exception as e:
219
217
  raise ValueError(f"Failed to parse Task from file: {file_path}. Error: {str(e)}")
@@ -66,7 +66,6 @@ class CreateArtifactRequest(BaseModel):
66
66
  """
67
67
  Request object to create a new artifact.
68
68
  """
69
- user_id: str # The user ID creating the artifact.
70
69
  artifact_name: str # The name of the artifact to create.
71
70
  artifact_description: Optional[str] = "" # Description of the artifact.
72
71
  artifact_tags: Optional[List[str]] = None # Tags for the artifact, separated by commas.
@@ -146,6 +145,20 @@ class ArtifactTemplate(BaseModel):
146
145
  artifact_description: Optional[str] = "" # Description of the artifact template.
147
146
  artifact_name: Optional[str] = "" # Name of the artifact template.
148
147
  artifact_tags: Optional[List[str]] = None # Tags associated with the artifact template.
148
+ ray: Optional["RayTemplate"] = None # Template for Ray-based artifacts.
149
+ resources: Optional["ResourcesTemplate"] = None # Resource allocation template.
150
+
151
+
152
+ class RayTemplate(BaseModel):
153
+ deployment_name: Optional[str] = "" # Name of the deployment.
154
+ file_path: Optional[str] = "" # Path to the task file in storage.
155
+ version: Optional[str] = "" # Version of Ray used.
156
+
157
+
158
+ class ResourcesTemplate(BaseModel):
159
+ cpu: Optional[int] = 0 # Number of CPU cores allocated.
160
+ memory: Optional[int] = 0 # Amount of RAM (in GB) allocated.
161
+ gpu: Optional[int] = 0 # Number of GPUs allocated.
149
162
 
150
163
 
151
164
  class CreateArtifactFromTemplateRequest(BaseModel):
gmicloud/client.py CHANGED
@@ -1,10 +1,13 @@
1
1
  import os
2
+ import time
2
3
 
3
4
  from typing import Optional
4
5
 
5
6
  from ._internal._client._iam_client import IAMClient
6
7
  from ._internal._manager._artifact_manager import ArtifactManager
7
8
  from ._internal._manager._task_manager import TaskManager
9
+ from ._internal._enums import BuildStatus
10
+ from ._internal._models import Task, TaskConfig, RayTaskConfig, TaskScheduling, OneOffScheduling, ReplicaResource
8
11
 
9
12
 
10
13
  class Client:
@@ -30,6 +33,74 @@ class Client:
30
33
  self._artifact_manager = None
31
34
  self._task_manager = None
32
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
103
+
33
104
  @property
34
105
  def artifact_manager(self):
35
106
  """
@@ -105,7 +105,7 @@ class TestArtifactManager(unittest.TestCase):
105
105
  status="success")
106
106
  artifact_template_id = "template123"
107
107
  response = self.artifact_manager.create_artifact_from_template(artifact_template_id)
108
- self.assertEqual(response.artifact_id, "1")
108
+ self.assertEqual(response, "1")
109
109
 
110
110
  @patch('gmicloud._internal._client._artifact_client.ArtifactClient.create_artifact_from_template')
111
111
  def test_create_artifact_from_template_raises_error_for_invalid_template_id(self,
@@ -0,0 +1,39 @@
1
+ import subprocess
2
+
3
+
4
+ def get_installed_packages():
5
+ """
6
+ Get a list of currently installed packages using pip freeze.
7
+ """
8
+ result = subprocess.run(['pip', 'freeze'], capture_output=True, text=True)
9
+ return set(result.stdout.splitlines())
10
+
11
+
12
+ def get_required_packages(file_path):
13
+ """
14
+ Get a list of required packages from the requirements file.
15
+ """
16
+ with open(file_path, 'r') as file:
17
+ return {line.strip() for line in file}
18
+
19
+
20
+ def uninstall_packages(packages):
21
+ """
22
+ Uninstall the given packages using pip.
23
+ """
24
+ for package in packages:
25
+ subprocess.run(['pip', 'uninstall', '-y', package])
26
+
27
+
28
+ if __name__ == '__main__':
29
+ # Get the list of installed packages
30
+ installed_packages = get_installed_packages()
31
+
32
+ # Get the list of required packages from the requirements file
33
+ required_packages = get_required_packages('../../requirements.txt')
34
+
35
+ # Determine the packages that need to be uninstalled
36
+ packages_to_uninstall = installed_packages - required_packages
37
+
38
+ # Uninstall the packages that are not required
39
+ uninstall_packages(packages_to_uninstall)
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.2
2
+ Name: gmicloud
3
+ Version: 0.1.1
4
+ Summary: GMI Cloud Python SDK
5
+ Author-email: GMI <gmi@gmitec.net>
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
14
+
15
+ ## Overview
16
+
17
+ The GMI Inference Engine SDK provides a Python interface for deploying and managing machine learning models in
18
+ production environments. It allows users to create model artifacts, schedule tasks for serving models, and call
19
+ inference APIs easily.
20
+
21
+ This SDK streamlines the process of utilizing GMI Cloud capabilities such as deploying models with Kubernetes-based Ray
22
+ services, managing resources automatically, and accessing model inference endpoints. With minimal setup, developers can
23
+ focus on building ML solutions instead of infrastructure.
24
+
25
+ ## Features
26
+
27
+ - Artifact Management: Easily create, update, and manage ML model artifacts.
28
+ - Task Management: Quickly create, schedule, and manage deployment tasks for model inference.
29
+ - Usage Data Retrieval : Fetch and analyze usage data to optimize resource allocation.
30
+
31
+ ## Installation
32
+
33
+ To install the SDK, use pip:
34
+
35
+ ```bash
36
+ pip install gmicloud
37
+ ```
38
+
39
+ ## Setup
40
+
41
+ You must configure authentication credentials for accessing the GMI Cloud API. 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. Create a Task from an Artifact Template
66
+
67
+ This is the simplest example to deploy an existing artifact template:
68
+
69
+ ```python
70
+ from datetime import datetime
71
+ from gmicloud import Client, TaskScheduling, OneOffScheduling
72
+ from examples.completion import call_chat_completion
73
+
74
+ # Initialize the client
75
+ client = Client()
76
+
77
+ # Schedule and start a task from an artifact template
78
+ task = client.create_task_from_artifact_template(
79
+ "llama31_8b_template_001",
80
+ TaskScheduling(
81
+ scheduling_oneoff=OneOffScheduling(
82
+ trigger_timestamp=int(datetime.now().timestamp()) + 60, # Delay by 1 min
83
+ min_replicas=1,
84
+ max_replicas=10,
85
+ )
86
+ )
87
+ )
88
+
89
+ # Make a chat completion request via the task endpoint
90
+ response = call_chat_completion(client, task.task_id)
91
+ print(response)
92
+ ```
93
+
94
+ ### 2. Step-by-Step Example: Create Artifact, Task, and Query the Endpoint
95
+
96
+ #### (a) Create an Artifact from a Template
97
+
98
+ First, you’ll retrieve all templates and create an artifact based on the desired template (e.g., "Llama3.1 8B"):
99
+
100
+ ```python
101
+ def create_artifact_from_template(client):
102
+ artifact_manager = client.artifact_manager
103
+
104
+ # List all available templates
105
+ templates = artifact_manager.get_artifact_templates()
106
+ for template in templates:
107
+ if template.artifact_name == "Llama3.1 8B":
108
+ return artifact_manager.create_artifact_from_template(
109
+ artifact_template_id=template.artifact_template_id
110
+ )
111
+ return None
112
+ ```
113
+
114
+ #### (b) Create a Task from the Artifact
115
+
116
+ Wait until the artifact becomes "ready" and then deploy it using task scheduling:
117
+
118
+ ```python
119
+ def create_task_and_start(client, artifact_id):
120
+ artifact_manager = client.artifact_manager
121
+
122
+ # Wait until the artifact is ready
123
+ while True:
124
+ artifact = artifact_manager.get_artifact(artifact_id)
125
+ if artifact.build_status == "SUCCESS":
126
+ break
127
+ print("Waiting for artifact to be ready...")
128
+ time.sleep(2)
129
+
130
+ # Configure and start the task
131
+ task_manager = client.task_manager
132
+ task = task_manager.create_task(Task(
133
+ config=TaskConfig(
134
+ ray_task_config=RayTaskConfig(
135
+ ray_version="latest-py311-gpu",
136
+ file_path="serve",
137
+ artifact_id=artifact_id,
138
+ deployment_name="app",
139
+ replica_resource=ReplicaResource(
140
+ cpu=24,
141
+ ram_gb=128,
142
+ gpu=2,
143
+ ),
144
+ ),
145
+ task_scheduling=TaskScheduling(
146
+ scheduling_oneoff=OneOffScheduling(
147
+ trigger_timestamp=int(datetime.now().timestamp()) + 60,
148
+ min_replicas=1,
149
+ max_replicas=10,
150
+ )
151
+ ),
152
+ ),
153
+ ))
154
+
155
+ task_manager.start_task(task.task_id)
156
+ return task.task_id
157
+ ```
158
+
159
+ ### (c) Query the Model Endpoint
160
+
161
+ Once the task is ready, use the endpoint for inference:
162
+
163
+ ```python
164
+ from examples.completion import call_chat_completion
165
+
166
+ client = Client()
167
+ artifact_id = create_artifact_from_template(client)
168
+ task_id = create_task_and_start(client, artifact_id)
169
+
170
+ response = call_chat_completion(client, task_id)
171
+ print(response)
172
+ ```
173
+
174
+ ## API Reference
175
+
176
+ ### Client
177
+
178
+ Represents the entry point to interact with GMI Cloud APIs.
179
+ Client(
180
+ client_id: Optional[str] = "",
181
+ email: Optional[str] = "",
182
+ password: Optional[str] = ""
183
+ )
184
+
185
+ ### Artifact Management
186
+
187
+ * get_artifact_templates(): Fetch a list of available artifact templates.
188
+ * create_artifact_from_template(template_id: str): Create a model artifact from a given template.
189
+ * get_artifact(artifact_id: str): Get details of a specific artifact.
190
+
191
+ ### Task Management
192
+
193
+ * create_task_from_artifact_template(template_id: str, scheduling: TaskScheduling): Create and schedule a task using an
194
+ artifact template.
195
+ * start_task(task_id: str): Start a task.
196
+ * get_task(task_id: str): Retrieve the status and details of a specific task.
197
+
198
+ ## Notes & Troubleshooting
199
+
200
+ Ensure Credentials are Correct: Double-check your environment variables or parameters passed into the Client object.
201
+ Artifact Status: It may take a few minutes for an artifact or task to transition to the "ready" state.
202
+ Inference Endpoint Readiness: Use the task endpoint only after the task status changes to "ready".
203
+ Default OpenAI Key: By default, the OpenAI API base URL is derived from the endpoint provided by GMI.
204
+
205
+ ## Contributing
206
+
207
+ We welcome contributions to enhance the SDK. Please follow these steps:
208
+
209
+ 1. Fork the repository.
210
+ 2. Create a new branch for your feature or bugfix.
211
+ 3. Commit changes with clear messages.
212
+ 4. Submit a pull request for review.
@@ -0,0 +1,26 @@
1
+ gmicloud/__init__.py,sha256=jIefHqO_DemXBs6qR9cTtXsuHAEBQo0INuKZKEl3mW8,822
2
+ gmicloud/client.py,sha256=qgN6Pcoa_dRwBWRy463yW3Nne52d_D8ogdEODH7LGp4,4751
3
+ gmicloud/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ gmicloud/_internal/_config.py,sha256=qIH76TSyS3MQWe62LHI46RJhDnklNFisdajY75oUAqE,218
5
+ gmicloud/_internal/_constants.py,sha256=EyhjJp_mEIsAuopFyfnRzGRVjQH9jOhU5AQvtBF_IeU,339
6
+ gmicloud/_internal/_enums.py,sha256=1xGle0FARJEQWkphjUM6yJ1hCqD9YKsh8_5GfkGEvio,477
7
+ gmicloud/_internal/_exceptions.py,sha256=hScBq7n2fOit4_umlkabZJchY8zVbWSRfWM2Y0rLCbw,306
8
+ gmicloud/_internal/_models.py,sha256=tqPiqVktwCtHaldi4imzmQVi7zpjKPCi9O8c6QN2Zn8,13083
9
+ gmicloud/_internal/_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ gmicloud/_internal/_client/_artifact_client.py,sha256=V8q78L1wys0d2GYJ87m2EFsLUOJG7nsJvAkrHBeXVU8,6895
11
+ gmicloud/_internal/_client/_decorator.py,sha256=sy4gxzsUB6ORXHw5pqmMf7TTlK41Nmu1fhIhK2AIsbY,670
12
+ gmicloud/_internal/_client/_file_upload_client.py,sha256=1JRs4X57S3EScPIP9w2DC1Uo6_Wbcjumcw3nVM7uIGM,4667
13
+ gmicloud/_internal/_client/_http_client.py,sha256=6xvzYp-pFcKV9U2nOcMKkWpOi3NB_zfWx-bMfsGQwQY,5672
14
+ gmicloud/_internal/_client/_iam_client.py,sha256=57KHyGg_0Vj5AzwhIto0kmbqQYxnixKIOilNO8hCwr0,2698
15
+ gmicloud/_internal/_client/_task_client.py,sha256=G0MqsNDHhdL885jo-isuu9H_Pv_6DLimN7lT-gz2Uv4,5074
16
+ gmicloud/_internal/_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ gmicloud/_internal/_manager/_artifact_manager.py,sha256=cc367Kd-W9Zn2d_wUcG6tT06544HRItIZ5IsFfA5_RQ,12201
18
+ gmicloud/_internal/_manager/_task_manager.py,sha256=QQfpYXFKAAI_FSI--Nxvjlgf_jeVZuVnTuRGTQzrZso,8034
19
+ gmicloud/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ gmicloud/tests/test_artifacts.py,sha256=YiC1HBMS7g491Ra4acTLI9AdwyjXZfnY9f-fNKn2azQ,17108
21
+ gmicloud/tests/test_tasks.py,sha256=AY90zTJdsXk1cxn6Jxhi4TDdwXRiGxz_r_aRk_Jkl8Y,10956
22
+ gmicloud/utils/uninstall_packages.py,sha256=zzuuaJPf39oTXWZ_7tUAGseoxocuCbbkoglJSD5yDrE,1127
23
+ gmicloud-0.1.1.dist-info/METADATA,sha256=VtHBj-gOFzBp-4aMRKibO13UAK7wX8Rc71xtXi6fVvs,6583
24
+ gmicloud-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
25
+ gmicloud-0.1.1.dist-info/top_level.txt,sha256=AZimLw3y0WPpLiSiOidZ1gD0dxALh-jQNk4fxC05hYE,9
26
+ gmicloud-0.1.1.dist-info/RECORD,,
@@ -1,2 +1 @@
1
- examples
2
1
  gmicloud
examples/__init__.py DELETED
File without changes
examples/example.py DELETED
@@ -1,145 +0,0 @@
1
- import os
2
- import time
3
- from datetime import datetime
4
-
5
- from openai import OpenAI
6
-
7
- from gmicloud import *
8
-
9
-
10
- def create_artifact_with_file(client: Client) -> str:
11
- artifact_manager = client.artifact_manager
12
-
13
- # Create an artifact with a file
14
- artifact_id = artifact_manager.create_artifact_with_file(
15
- artifact_name="Llama3.1 8B",
16
- artifact_file_path="./files/Llama-3.1-8B-Instruct.zip",
17
- description="This is a test artifact",
18
- tags=['example', 'test']
19
- )
20
-
21
- return artifact_id
22
-
23
-
24
- def create_artifact_from_template(client: Client) -> str:
25
- artifact_manager = client.artifact_manager
26
-
27
- # Get all artifact templates
28
- templates = artifact_manager.get_artifact_templates()
29
- print(templates)
30
- for template in templates:
31
- if template.artifact_name == "Llama3.1 8B":
32
- # Create an artifact from a template
33
- artifact_id = artifact_manager.create_artifact_from_template(
34
- artifact_template_id=template.artifact_template_id,
35
- )
36
-
37
- return artifact_id
38
-
39
- return ""
40
-
41
-
42
- def create_task_and_start(client: Client, artifact_id: str) -> str:
43
- artifact_manager = client.artifact_manager
44
- # Wait for the artifact to be ready
45
- while True:
46
- try:
47
- artifact = artifact_manager.get_artifact(artifact_id)
48
- print(f"Artifact status: {artifact.build_status}")
49
- # Wait until the artifact is ready
50
- if artifact.build_status == BuildStatus.SUCCESS:
51
- break
52
- except Exception as e:
53
- raise e
54
- # Wait for 2 seconds
55
- time.sleep(2)
56
- try:
57
- task_manager = client.task_manager
58
- # Create a task
59
- task = task_manager.create_task(Task(
60
- config=TaskConfig(
61
- ray_task_config=RayTaskConfig(
62
- ray_version="latest-py311-gpu",
63
- file_path="serve",
64
- artifact_id=artifact_id,
65
- deployment_name="app",
66
- replica_resource=ReplicaResource(
67
- cpu=24,
68
- ram_gb=128,
69
- gpu=2,
70
- ),
71
- ),
72
- task_scheduling=TaskScheduling(
73
- scheduling_oneoff=OneOffScheduling(
74
- trigger_timestamp=int(datetime.now().timestamp()) + 60,
75
- min_replicas=1,
76
- max_replicas=10,
77
- )
78
- ),
79
- ),
80
- ))
81
-
82
- # Start the task
83
- task_manager.start_task(task.task_id)
84
- except Exception as e:
85
- raise e
86
-
87
- return task.task_id
88
-
89
-
90
- def call_chat_completion(client: Client, task_id: str):
91
- task_manager = client.task_manager
92
- # Wait for the task to be ready
93
- while True:
94
- try:
95
- task = task_manager.get_task(task_id)
96
- print(f"task status: {task.task_status}")
97
- # Wait until the task is ready
98
- if task.task_status == "ready":
99
- break
100
- except Exception as e:
101
- print(e)
102
- return
103
- # Wait for 2 seconds
104
- time.sleep(2)
105
-
106
- if not task.info.endpoint or not task.info.endpoint.strip():
107
- raise Exception("Task endpoint is not ready yet")
108
-
109
- open_ai = OpenAI(
110
- api_key=os.getenv("OPENAI_API_KEY", "YOUR_DEFAULT_API_KEY"),
111
- base_url=os.getenv("OPENAI_API_BASE", task.info.endpoint)
112
- )
113
- # Make a chat completion request using the new OpenAI client.
114
- completion = open_ai.chat.completions.create(
115
- model="meta-llama/Llama-3.1-8B-Instruct",
116
- messages=[
117
- {"role": "system", "content": "You are a helpful assistant."},
118
- {"role": "user",
119
- "content": f"Translate the sentences to Chinese"},
120
- ],
121
- max_tokens=200,
122
- temperature=0.7
123
- )
124
-
125
- print(completion.choices[0].message.content)
126
-
127
-
128
- if __name__ == '__main__':
129
- # Initialize the Client
130
- cli = Client()
131
-
132
- # print(cli.artifact_manager.get_all_artifacts())
133
-
134
- # Create an artifact with a file
135
- # artifact_id = create_artifact_with_file(cli)
136
-
137
- # Create an artifact from a template
138
- #artifact_id = create_artifact_from_template(cli)
139
- artifact_id = "cba6db2f-315a-4765-9e94-1e692f7fdb39"
140
-
141
- # Create a task and start it
142
- task_id = create_task_and_start(cli, artifact_id)
143
-
144
- # Call chat completion
145
- call_chat_completion(cli, task_id)
@@ -1,208 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: gmicloud
3
- Version: 0.1.0
4
- Summary: GMI Cloud Python SDK
5
- Home-page: https://github.com/GMISWE/python-sdk
6
- Author: GMI
7
- Author-email: GMI <gmi@gmitec.net>
8
- License: MIT
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/markdown
14
- Dynamic: author
15
- Dynamic: home-page
16
- Dynamic: requires-python
17
-
18
- # GMICloud
19
-
20
- ## Overview
21
-
22
- This project is an open-source SDK for interacting with the GMICLOUD platform. It provides functionalities to manage
23
- artifacts, tasks, and usage data efficiently.
24
-
25
- ## Features
26
-
27
- - Create and manage artifacts
28
- - Create and manage tasks
29
- - Fetch usage data
30
- - Integration with OpenAI for chat completions
31
-
32
- ## Installation
33
-
34
- To install the SDK, use pip:
35
-
36
- ```bash
37
- pip install gmicloud-sdk
38
- ```
39
-
40
- ## Usage
41
-
42
- ### Initialize the Client
43
-
44
- ```python
45
- from gmicloud import Client
46
-
47
- client = Client(username="your_username", password="your_password")
48
- ```
49
-
50
- ### Create an Artifact with a File
51
-
52
- ```python
53
- artifact_id = client.artifact_manager.create_artifact_with_file(
54
- artifact_name="Llama3.1 8B",
55
- artifact_file_path="./files/Llama-3.1-8B-Instruct.zip",
56
- description="This is a test artifact",
57
- tags=['example', 'test']
58
- )
59
- ```
60
-
61
- ### Create an Artifact from a Template
62
-
63
- ```python
64
- artifact_id = client.artifact_manager.create_artifact_from_template(
65
- artifact_template_id="template_id"
66
- )
67
- ```
68
-
69
- ### Create and Start a Task
70
-
71
- ```python
72
- task_id = client.task_manager.create_task(Task(
73
- config=TaskConfig(
74
- ray_task_config=RayTaskConfig(
75
- ray_version="2.40.0-py310-gpu",
76
- file_path="serve",
77
- artifact_id=artifact_id,
78
- deployment_name="app",
79
- replica_resource=ReplicaResource(
80
- cpu=2,
81
- ram_gb=128,
82
- gpu=2,
83
- ),
84
- ),
85
- task_scheduling=TaskScheduling(
86
- scheduling_oneoff=OneOffScheduling(
87
- trigger_timestamp=int(datetime.now().timestamp()) + 60,
88
- min_replicas=1,
89
- max_replicas=10,
90
- )
91
- ),
92
- ),
93
- ))
94
-
95
- client.task_manager.start_task(task_id)
96
- ```
97
-
98
- ### Call Chat Completion
99
-
100
- ```python
101
- from openai import OpenAI
102
-
103
- task = client.task_manager.get_task(task_id)
104
- open_ai = OpenAI(
105
- api_key="YOUR_API_KEY",
106
- base_url=task.info.endpoint
107
- )
108
-
109
- completion = open_ai.chat.completions.create(
110
- model="meta-llama/Llama-3.1-8B-Instruct",
111
- messages=[
112
- {"role": "system", "content": "You are a helpful assistant."},
113
- {"role": "user", "content": "Translate the sentences to Chinese"},
114
- ],
115
- max_tokens=200,
116
- temperature=0.7
117
- )
118
-
119
- print(completion.choices[0].message.content)
120
- ```
121
-
122
- ## Configuration
123
-
124
- ### One-off Task Configuration
125
-
126
- `examples/config/one-off_task.json`:
127
-
128
- ```json
129
- {
130
- "config": {
131
- "ray_task_config": {
132
- "ray_version": "2.40.0",
133
- "file_path": "serve",
134
- "deployment_name": "string",
135
- "replica_resource": {
136
- "cpu": 2,
137
- "ram_gb": 12,
138
- "gpu": 1
139
- }
140
- },
141
- "task_scheduling": {
142
- "scheduling_oneoff": {
143
- "min_replicas": 1,
144
- "max_replicas": 1
145
- }
146
- }
147
- }
148
- }
149
- ```
150
-
151
- ### Daily Task Configuration
152
-
153
- `examples/config/daily_task.json`:
154
-
155
- ```json
156
- {
157
- "config": {
158
- "ray_task_config": {
159
- "ray_version": "2.40.0-py310-gpu",
160
- "file_path": "serve",
161
- "deployment_name": "string",
162
- "replica_resource": {
163
- "cpu": 6,
164
- "ram_gb": 64,
165
- "gpu": 2
166
- }
167
- },
168
- "task_scheduling": {
169
- "scheduling_daily": {
170
- "triggers": [
171
- {
172
- "timezone": "UTC",
173
- "Hour": 0,
174
- "minute": 10,
175
- "second": 0,
176
- "min_replicas": 1,
177
- "max_replicas": 2
178
- },
179
- {
180
- "timezone": "UTC",
181
- "Hour": 0,
182
- "minute": 10,
183
- "second": 30,
184
- "min_replicas": 1,
185
- "max_replicas": 4
186
- }
187
- ]
188
- }
189
- }
190
- }
191
- }
192
- ```
193
-
194
- ## Running Tests
195
-
196
- To run the unit tests, use the following command:
197
-
198
- ```bash
199
- pytest
200
- ```
201
-
202
- ## Contributing
203
-
204
- Contributions are welcome! Please open an issue or submit a pull request.
205
-
206
- ## License
207
-
208
- This project is licensed under the MIT License. See the `LICENSE` file for details.
@@ -1,27 +0,0 @@
1
- examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- examples/example.py,sha256=VX0EQoLshF2bOm1eDCcrnA-9t3ZPUffKdSMUBVax_UM,4446
3
- gmicloud/__init__.py,sha256=nvdQUQfy6KxeVU889VKyJjz9iXfShVHKb65rNfyIPlQ,740
4
- gmicloud/client.py,sha256=D6wPXutlr3hWaFF_3azmYk5kMrvLSObvubDOe29mKfk,1775
5
- gmicloud/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- gmicloud/_internal/_config.py,sha256=qIH76TSyS3MQWe62LHI46RJhDnklNFisdajY75oUAqE,218
7
- gmicloud/_internal/_constants.py,sha256=EyhjJp_mEIsAuopFyfnRzGRVjQH9jOhU5AQvtBF_IeU,339
8
- gmicloud/_internal/_enums.py,sha256=1xGle0FARJEQWkphjUM6yJ1hCqD9YKsh8_5GfkGEvio,477
9
- gmicloud/_internal/_exceptions.py,sha256=hScBq7n2fOit4_umlkabZJchY8zVbWSRfWM2Y0rLCbw,306
10
- gmicloud/_internal/_models.py,sha256=n8lHes_o3BzpHqS2ZL96OZ1HuaQRD7c1qqTvlHetYpg,12529
11
- gmicloud/_internal/_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- gmicloud/_internal/_client/_artifact_client.py,sha256=IY3CZzcDUg7bM8-UwogF5n7Tb2gWQKUY1SCYcdvjhmA,7053
13
- gmicloud/_internal/_client/_decorator.py,sha256=sy4gxzsUB6ORXHw5pqmMf7TTlK41Nmu1fhIhK2AIsbY,670
14
- gmicloud/_internal/_client/_file_upload_client.py,sha256=1JRs4X57S3EScPIP9w2DC1Uo6_Wbcjumcw3nVM7uIGM,4667
15
- gmicloud/_internal/_client/_http_client.py,sha256=V1fZ5O-Ja2n1Z0YHa-PkAMHY-yNFw--Dk_httldNYxA,6520
16
- gmicloud/_internal/_client/_iam_client.py,sha256=57KHyGg_0Vj5AzwhIto0kmbqQYxnixKIOilNO8hCwr0,2698
17
- gmicloud/_internal/_client/_task_client.py,sha256=76PpI2-ZjHHtGLMxJ_wEOh0mHnmPzVG7sCkWLxV2rAw,5110
18
- gmicloud/_internal/_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- gmicloud/_internal/_manager/_artifact_manager.py,sha256=eUxi7ABAivGK_6B8xo9RXr_pieHyFZLFyDDtOU37SnA,12439
20
- gmicloud/_internal/_manager/_task_manager.py,sha256=0GYjXRPtJswxDLPmVhLl3LNbQiXZP_49WUvd5OE3wn0,8119
21
- gmicloud/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- gmicloud/tests/test_artifacts.py,sha256=c1MlkaLTaIeVJ3acn92fl3txcDFdy3itOTRhUXaze0E,17120
23
- gmicloud/tests/test_tasks.py,sha256=AY90zTJdsXk1cxn6Jxhi4TDdwXRiGxz_r_aRk_Jkl8Y,10956
24
- gmicloud-0.1.0.dist-info/METADATA,sha256=Vu5h1LtOonBVJ98U-noSJEHfnsFS0_N-wvc9gv9ZGzk,4308
25
- gmicloud-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
26
- gmicloud-0.1.0.dist-info/top_level.txt,sha256=2GhHEguTB3WOeNihOOrIwGp1n7pw_VTJbG8pa5WyyFk,18
27
- gmicloud-0.1.0.dist-info/RECORD,,