gmicloud 0.1.3__tar.gz → 0.1.4__tar.gz
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-0.1.3 → gmicloud-0.1.4}/PKG-INFO +81 -45
- {gmicloud-0.1.3 → gmicloud-0.1.4}/README.md +80 -44
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_http_client.py +0 -1
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_iam_client.py +30 -7
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_models.py +26 -1
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud.egg-info/PKG-INFO +81 -45
- {gmicloud-0.1.3 → gmicloud-0.1.4}/pyproject.toml +1 -1
- {gmicloud-0.1.3 → gmicloud-0.1.4}/examples/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_artifact_client.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_decorator.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_file_upload_client.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_client/_task_client.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_config.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_constants.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_enums.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_exceptions.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_manager/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_manager/_artifact_manager.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/_internal/_manager/_task_manager.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/client.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/tests/__init__.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/tests/test_artifacts.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/tests/test_tasks.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud/utils/uninstall_packages.py +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud.egg-info/SOURCES.txt +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud.egg-info/dependency_links.txt +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/gmicloud.egg-info/top_level.txt +0 -0
- {gmicloud-0.1.3 → gmicloud-0.1.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: gmicloud
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: GMI Cloud Python SDK
|
5
5
|
Author-email: GMI <gmi@gmitec.net>
|
6
6
|
License: MIT
|
@@ -14,7 +14,8 @@ Description-Content-Type: text/markdown
|
|
14
14
|
|
15
15
|
## Overview
|
16
16
|
|
17
|
-
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
17
|
+
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
18
|
+
getstarted@gmicloud.ai) to get invited if you don't have one yet.
|
18
19
|
|
19
20
|
The GMI Inference Engine SDK provides a Python interface for deploying and managing machine learning models in
|
20
21
|
production environments. It allows users to create model artifacts, schedule tasks for serving models, and call
|
@@ -64,7 +65,18 @@ client = Client(client_id="<YOUR_CLIENT_ID>", email="<YOUR_EMAIL>", password="<Y
|
|
64
65
|
|
65
66
|
## Quick Start
|
66
67
|
|
67
|
-
### 1.
|
68
|
+
### 1. How to run the code in the example folder
|
69
|
+
```bash
|
70
|
+
cd path/to/gmicloud-sdk
|
71
|
+
# Create a virtual environment
|
72
|
+
python -m venv venv
|
73
|
+
source venv/bin/activate
|
74
|
+
|
75
|
+
pip install -r requirements.txt
|
76
|
+
python -m examples.<example_name>
|
77
|
+
```
|
78
|
+
|
79
|
+
### 2. Create a Task from an Artifact Template
|
68
80
|
|
69
81
|
This is the simplest example to deploy an existing artifact template:
|
70
82
|
|
@@ -93,24 +105,30 @@ response = call_chat_completion(client, task.task_id)
|
|
93
105
|
print(response)
|
94
106
|
```
|
95
107
|
|
96
|
-
###
|
108
|
+
### 3. Step-by-Step Example: Create Artifact, Task, and Query the Endpoint
|
97
109
|
|
98
110
|
#### (a) Create an Artifact from a Template
|
99
111
|
|
100
112
|
First, you’ll retrieve all templates and create an artifact based on the desired template (e.g., "Llama3.1 8B"):
|
101
113
|
|
102
114
|
```python
|
103
|
-
|
115
|
+
from gmicloud import *
|
116
|
+
|
117
|
+
def create_artifact_from_template(client: Client) -> str:
|
104
118
|
artifact_manager = client.artifact_manager
|
105
119
|
|
106
|
-
#
|
120
|
+
# Get all artifact templates
|
107
121
|
templates = artifact_manager.get_artifact_templates()
|
108
122
|
for template in templates:
|
109
123
|
if template.artifact_template_id == "qwen_2.5_14b_instruct_template_001":
|
110
|
-
|
111
|
-
|
124
|
+
# Create an artifact from a template
|
125
|
+
artifact_id = artifact_manager.create_artifact_from_template(
|
126
|
+
artifact_template_id=template.artifact_template_id,
|
112
127
|
)
|
113
|
-
|
128
|
+
|
129
|
+
return artifact_id
|
130
|
+
|
131
|
+
return ""
|
114
132
|
```
|
115
133
|
|
116
134
|
#### (b) Create a Task from the Artifact
|
@@ -118,43 +136,55 @@ def create_artifact_from_template(client):
|
|
118
136
|
Wait until the artifact becomes "ready" and then deploy it using task scheduling:
|
119
137
|
|
120
138
|
```python
|
121
|
-
|
122
|
-
|
139
|
+
from gmicloud import *
|
140
|
+
import time
|
141
|
+
from datetime import datetime
|
123
142
|
|
124
|
-
|
143
|
+
def create_task_and_start(client: Client, artifact_id: str) -> str:
|
144
|
+
artifact_manager = client.artifact_manager
|
145
|
+
# Wait for the artifact to be ready
|
125
146
|
while True:
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
147
|
+
try:
|
148
|
+
artifact = artifact_manager.get_artifact(artifact_id)
|
149
|
+
print(f"Artifact status: {artifact.build_status}")
|
150
|
+
# Wait until the artifact is ready
|
151
|
+
if artifact.build_status == BuildStatus.SUCCESS:
|
152
|
+
break
|
153
|
+
except Exception as e:
|
154
|
+
raise e
|
155
|
+
# Wait for 2 seconds
|
130
156
|
time.sleep(2)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
157
|
+
try:
|
158
|
+
task_manager = client.task_manager
|
159
|
+
# Create a task
|
160
|
+
task = task_manager.create_task(Task(
|
161
|
+
config=TaskConfig(
|
162
|
+
ray_task_config=RayTaskConfig(
|
163
|
+
ray_version="2.40.0-py310-gpu",
|
164
|
+
file_path="serve",
|
165
|
+
artifact_id=artifact_id,
|
166
|
+
deployment_name="app",
|
167
|
+
replica_resource=ReplicaResource(
|
168
|
+
cpu=10,
|
169
|
+
ram_gb=100,
|
170
|
+
gpu=1,
|
171
|
+
),
|
172
|
+
),
|
173
|
+
task_scheduling=TaskScheduling(
|
174
|
+
scheduling_oneoff=OneOffScheduling(
|
175
|
+
trigger_timestamp=int(datetime.now().timestamp()) + 10,
|
176
|
+
min_replicas=1,
|
177
|
+
max_replicas=10,
|
178
|
+
)
|
145
179
|
),
|
146
180
|
),
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
),
|
154
|
-
),
|
155
|
-
))
|
181
|
+
))
|
182
|
+
|
183
|
+
# Start the task
|
184
|
+
task_manager.start_task(task.task_id)
|
185
|
+
except Exception as e:
|
186
|
+
raise e
|
156
187
|
|
157
|
-
task_manager.start_task(task.task_id)
|
158
188
|
return task.task_id
|
159
189
|
```
|
160
190
|
|
@@ -163,14 +193,20 @@ def create_task_and_start(client, artifact_id):
|
|
163
193
|
Once the task is running, use the endpoint for inference:
|
164
194
|
|
165
195
|
```python
|
196
|
+
from gmicloud import *
|
166
197
|
from examples.completion import call_chat_completion
|
167
198
|
|
168
|
-
|
169
|
-
|
170
|
-
task_id = create_task_and_start(client, artifact_id)
|
199
|
+
# Initialize the Client
|
200
|
+
cli = Client()
|
171
201
|
|
172
|
-
|
173
|
-
|
202
|
+
# Create an artifact from a template
|
203
|
+
artifact_id = create_artifact_from_template(cli)
|
204
|
+
|
205
|
+
# Create a task and start it
|
206
|
+
task_id = create_task_and_start(cli, artifact_id)
|
207
|
+
|
208
|
+
# Call chat completion
|
209
|
+
print(call_chat_completion(cli, task_id))
|
174
210
|
```
|
175
211
|
|
176
212
|
## API Reference
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
5
|
+
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
6
|
+
getstarted@gmicloud.ai) to get invited if you don't have one yet.
|
6
7
|
|
7
8
|
The GMI Inference Engine SDK provides a Python interface for deploying and managing machine learning models in
|
8
9
|
production environments. It allows users to create model artifacts, schedule tasks for serving models, and call
|
@@ -52,7 +53,18 @@ client = Client(client_id="<YOUR_CLIENT_ID>", email="<YOUR_EMAIL>", password="<Y
|
|
52
53
|
|
53
54
|
## Quick Start
|
54
55
|
|
55
|
-
### 1.
|
56
|
+
### 1. How to run the code in the example folder
|
57
|
+
```bash
|
58
|
+
cd path/to/gmicloud-sdk
|
59
|
+
# Create a virtual environment
|
60
|
+
python -m venv venv
|
61
|
+
source venv/bin/activate
|
62
|
+
|
63
|
+
pip install -r requirements.txt
|
64
|
+
python -m examples.<example_name>
|
65
|
+
```
|
66
|
+
|
67
|
+
### 2. Create a Task from an Artifact Template
|
56
68
|
|
57
69
|
This is the simplest example to deploy an existing artifact template:
|
58
70
|
|
@@ -81,24 +93,30 @@ response = call_chat_completion(client, task.task_id)
|
|
81
93
|
print(response)
|
82
94
|
```
|
83
95
|
|
84
|
-
###
|
96
|
+
### 3. Step-by-Step Example: Create Artifact, Task, and Query the Endpoint
|
85
97
|
|
86
98
|
#### (a) Create an Artifact from a Template
|
87
99
|
|
88
100
|
First, you’ll retrieve all templates and create an artifact based on the desired template (e.g., "Llama3.1 8B"):
|
89
101
|
|
90
102
|
```python
|
91
|
-
|
103
|
+
from gmicloud import *
|
104
|
+
|
105
|
+
def create_artifact_from_template(client: Client) -> str:
|
92
106
|
artifact_manager = client.artifact_manager
|
93
107
|
|
94
|
-
#
|
108
|
+
# Get all artifact templates
|
95
109
|
templates = artifact_manager.get_artifact_templates()
|
96
110
|
for template in templates:
|
97
111
|
if template.artifact_template_id == "qwen_2.5_14b_instruct_template_001":
|
98
|
-
|
99
|
-
|
112
|
+
# Create an artifact from a template
|
113
|
+
artifact_id = artifact_manager.create_artifact_from_template(
|
114
|
+
artifact_template_id=template.artifact_template_id,
|
100
115
|
)
|
101
|
-
|
116
|
+
|
117
|
+
return artifact_id
|
118
|
+
|
119
|
+
return ""
|
102
120
|
```
|
103
121
|
|
104
122
|
#### (b) Create a Task from the Artifact
|
@@ -106,43 +124,55 @@ def create_artifact_from_template(client):
|
|
106
124
|
Wait until the artifact becomes "ready" and then deploy it using task scheduling:
|
107
125
|
|
108
126
|
```python
|
109
|
-
|
110
|
-
|
127
|
+
from gmicloud import *
|
128
|
+
import time
|
129
|
+
from datetime import datetime
|
111
130
|
|
112
|
-
|
131
|
+
def create_task_and_start(client: Client, artifact_id: str) -> str:
|
132
|
+
artifact_manager = client.artifact_manager
|
133
|
+
# Wait for the artifact to be ready
|
113
134
|
while True:
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
135
|
+
try:
|
136
|
+
artifact = artifact_manager.get_artifact(artifact_id)
|
137
|
+
print(f"Artifact status: {artifact.build_status}")
|
138
|
+
# Wait until the artifact is ready
|
139
|
+
if artifact.build_status == BuildStatus.SUCCESS:
|
140
|
+
break
|
141
|
+
except Exception as e:
|
142
|
+
raise e
|
143
|
+
# Wait for 2 seconds
|
118
144
|
time.sleep(2)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
145
|
+
try:
|
146
|
+
task_manager = client.task_manager
|
147
|
+
# Create a task
|
148
|
+
task = task_manager.create_task(Task(
|
149
|
+
config=TaskConfig(
|
150
|
+
ray_task_config=RayTaskConfig(
|
151
|
+
ray_version="2.40.0-py310-gpu",
|
152
|
+
file_path="serve",
|
153
|
+
artifact_id=artifact_id,
|
154
|
+
deployment_name="app",
|
155
|
+
replica_resource=ReplicaResource(
|
156
|
+
cpu=10,
|
157
|
+
ram_gb=100,
|
158
|
+
gpu=1,
|
159
|
+
),
|
160
|
+
),
|
161
|
+
task_scheduling=TaskScheduling(
|
162
|
+
scheduling_oneoff=OneOffScheduling(
|
163
|
+
trigger_timestamp=int(datetime.now().timestamp()) + 10,
|
164
|
+
min_replicas=1,
|
165
|
+
max_replicas=10,
|
166
|
+
)
|
133
167
|
),
|
134
168
|
),
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
),
|
142
|
-
),
|
143
|
-
))
|
169
|
+
))
|
170
|
+
|
171
|
+
# Start the task
|
172
|
+
task_manager.start_task(task.task_id)
|
173
|
+
except Exception as e:
|
174
|
+
raise e
|
144
175
|
|
145
|
-
task_manager.start_task(task.task_id)
|
146
176
|
return task.task_id
|
147
177
|
```
|
148
178
|
|
@@ -151,14 +181,20 @@ def create_task_and_start(client, artifact_id):
|
|
151
181
|
Once the task is running, use the endpoint for inference:
|
152
182
|
|
153
183
|
```python
|
184
|
+
from gmicloud import *
|
154
185
|
from examples.completion import call_chat_completion
|
155
186
|
|
156
|
-
|
157
|
-
|
158
|
-
task_id = create_task_and_start(client, artifact_id)
|
187
|
+
# Initialize the Client
|
188
|
+
cli = Client()
|
159
189
|
|
160
|
-
|
161
|
-
|
190
|
+
# Create an artifact from a template
|
191
|
+
artifact_id = create_artifact_from_template(cli)
|
192
|
+
|
193
|
+
# Create a task and start it
|
194
|
+
task_id = create_task_and_start(cli, artifact_id)
|
195
|
+
|
196
|
+
# Call chat completion
|
197
|
+
print(call_chat_completion(cli, task_id))
|
162
198
|
```
|
163
199
|
|
164
200
|
## API Reference
|
@@ -34,12 +34,35 @@ class IAMClient:
|
|
34
34
|
custom_headers = {
|
35
35
|
CLIENT_ID_HEADER: self._client_id
|
36
36
|
}
|
37
|
-
req =
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
req = AuthTokenRequest(email=self._email, password=self._password)
|
38
|
+
auth_tokens_result = self.client.post("/me/auth-tokens", custom_headers, req.model_dump())
|
39
|
+
auth_tokens_resp = AuthTokenResponse.model_validate(auth_tokens_result)
|
40
|
+
|
41
|
+
create_session_result = None
|
42
|
+
if auth_tokens_resp.is2FARequired:
|
43
|
+
max_attempts = 3
|
44
|
+
for attempt in range(max_attempts):
|
45
|
+
code = input(f"Attempt {attempt + 1}/{max_attempts}: Please enter the 2FA code: ")
|
46
|
+
|
47
|
+
create_session_req = CreateSessionRequest(
|
48
|
+
type="native", authToken=auth_tokens_resp.authToken, otpCode=code
|
49
|
+
)
|
50
|
+
try:
|
51
|
+
create_session_result = self.client.post(
|
52
|
+
"/me/sessions", custom_headers, create_session_req.model_dump()
|
53
|
+
)
|
54
|
+
break
|
55
|
+
except Exception as e:
|
56
|
+
print("Invalid 2FA code, please try again.")
|
57
|
+
if attempt == max_attempts - 1:
|
58
|
+
raise Exception("Failed to create session after 3 incorrect 2FA attempts.") from e
|
59
|
+
else:
|
60
|
+
create_session_req = CreateSessionRequest(type="native", authToken=auth_tokens_resp.authToken, otpCode=None)
|
61
|
+
create_session_result = self.client.post("/me/sessions", custom_headers, create_session_req.model_dump())
|
62
|
+
|
63
|
+
create_session_resp = CreateSessionResponse.model_validate(create_session_result)
|
64
|
+
self._access_token = create_session_resp.accessToken
|
65
|
+
self._refresh_token = create_session_resp.refreshToken
|
43
66
|
self._user_id = self.parse_user_id()
|
44
67
|
|
45
68
|
def refresh_token(self):
|
@@ -51,7 +74,7 @@ class IAMClient:
|
|
51
74
|
}
|
52
75
|
result = self.client.patch("/me/sessions", custom_headers, {"refreshToken": self._refresh_token})
|
53
76
|
|
54
|
-
resp =
|
77
|
+
resp = CreateSessionResponse.model_validate(result)
|
55
78
|
self._access_token = resp.accessToken
|
56
79
|
self._refresh_token = resp.refreshToken
|
57
80
|
|
@@ -307,10 +307,35 @@ class CreateTaskResponse(BaseModel):
|
|
307
307
|
upload_link: str # URL to upload the task data.
|
308
308
|
|
309
309
|
|
310
|
-
class
|
310
|
+
class AuthTokenRequest(BaseModel):
|
311
|
+
"""
|
312
|
+
Request object for user login.
|
313
|
+
"""
|
314
|
+
email: str # User email.
|
315
|
+
password: str # User password.
|
316
|
+
|
317
|
+
|
318
|
+
class AuthTokenResponse(BaseModel):
|
311
319
|
"""
|
312
320
|
Response object for user login.
|
313
321
|
"""
|
322
|
+
authToken: str # Access token for the user session.
|
323
|
+
is2FARequired: bool # Indicates if 2FA is required for the user.
|
324
|
+
|
325
|
+
|
326
|
+
class CreateSessionRequest(BaseModel):
|
327
|
+
"""
|
328
|
+
Request object for creating a user session.
|
329
|
+
"""
|
330
|
+
type: str # Type of the session (e.g., native).
|
331
|
+
authToken: str # Access token for the user session.
|
332
|
+
otpCode: Optional[str] # 2FA code for the user session.
|
333
|
+
|
334
|
+
|
335
|
+
class CreateSessionResponse(BaseModel):
|
336
|
+
"""
|
337
|
+
Response object for creating a user session.
|
338
|
+
"""
|
314
339
|
accessToken: str # Access token for the user session.
|
315
340
|
refreshToken: str # Refresh token for the user session.
|
316
341
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: gmicloud
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: GMI Cloud Python SDK
|
5
5
|
Author-email: GMI <gmi@gmitec.net>
|
6
6
|
License: MIT
|
@@ -14,7 +14,8 @@ Description-Content-Type: text/markdown
|
|
14
14
|
|
15
15
|
## Overview
|
16
16
|
|
17
|
-
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
17
|
+
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (
|
18
|
+
getstarted@gmicloud.ai) to get invited if you don't have one yet.
|
18
19
|
|
19
20
|
The GMI Inference Engine SDK provides a Python interface for deploying and managing machine learning models in
|
20
21
|
production environments. It allows users to create model artifacts, schedule tasks for serving models, and call
|
@@ -64,7 +65,18 @@ client = Client(client_id="<YOUR_CLIENT_ID>", email="<YOUR_EMAIL>", password="<Y
|
|
64
65
|
|
65
66
|
## Quick Start
|
66
67
|
|
67
|
-
### 1.
|
68
|
+
### 1. How to run the code in the example folder
|
69
|
+
```bash
|
70
|
+
cd path/to/gmicloud-sdk
|
71
|
+
# Create a virtual environment
|
72
|
+
python -m venv venv
|
73
|
+
source venv/bin/activate
|
74
|
+
|
75
|
+
pip install -r requirements.txt
|
76
|
+
python -m examples.<example_name>
|
77
|
+
```
|
78
|
+
|
79
|
+
### 2. Create a Task from an Artifact Template
|
68
80
|
|
69
81
|
This is the simplest example to deploy an existing artifact template:
|
70
82
|
|
@@ -93,24 +105,30 @@ response = call_chat_completion(client, task.task_id)
|
|
93
105
|
print(response)
|
94
106
|
```
|
95
107
|
|
96
|
-
###
|
108
|
+
### 3. Step-by-Step Example: Create Artifact, Task, and Query the Endpoint
|
97
109
|
|
98
110
|
#### (a) Create an Artifact from a Template
|
99
111
|
|
100
112
|
First, you’ll retrieve all templates and create an artifact based on the desired template (e.g., "Llama3.1 8B"):
|
101
113
|
|
102
114
|
```python
|
103
|
-
|
115
|
+
from gmicloud import *
|
116
|
+
|
117
|
+
def create_artifact_from_template(client: Client) -> str:
|
104
118
|
artifact_manager = client.artifact_manager
|
105
119
|
|
106
|
-
#
|
120
|
+
# Get all artifact templates
|
107
121
|
templates = artifact_manager.get_artifact_templates()
|
108
122
|
for template in templates:
|
109
123
|
if template.artifact_template_id == "qwen_2.5_14b_instruct_template_001":
|
110
|
-
|
111
|
-
|
124
|
+
# Create an artifact from a template
|
125
|
+
artifact_id = artifact_manager.create_artifact_from_template(
|
126
|
+
artifact_template_id=template.artifact_template_id,
|
112
127
|
)
|
113
|
-
|
128
|
+
|
129
|
+
return artifact_id
|
130
|
+
|
131
|
+
return ""
|
114
132
|
```
|
115
133
|
|
116
134
|
#### (b) Create a Task from the Artifact
|
@@ -118,43 +136,55 @@ def create_artifact_from_template(client):
|
|
118
136
|
Wait until the artifact becomes "ready" and then deploy it using task scheduling:
|
119
137
|
|
120
138
|
```python
|
121
|
-
|
122
|
-
|
139
|
+
from gmicloud import *
|
140
|
+
import time
|
141
|
+
from datetime import datetime
|
123
142
|
|
124
|
-
|
143
|
+
def create_task_and_start(client: Client, artifact_id: str) -> str:
|
144
|
+
artifact_manager = client.artifact_manager
|
145
|
+
# Wait for the artifact to be ready
|
125
146
|
while True:
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
147
|
+
try:
|
148
|
+
artifact = artifact_manager.get_artifact(artifact_id)
|
149
|
+
print(f"Artifact status: {artifact.build_status}")
|
150
|
+
# Wait until the artifact is ready
|
151
|
+
if artifact.build_status == BuildStatus.SUCCESS:
|
152
|
+
break
|
153
|
+
except Exception as e:
|
154
|
+
raise e
|
155
|
+
# Wait for 2 seconds
|
130
156
|
time.sleep(2)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
157
|
+
try:
|
158
|
+
task_manager = client.task_manager
|
159
|
+
# Create a task
|
160
|
+
task = task_manager.create_task(Task(
|
161
|
+
config=TaskConfig(
|
162
|
+
ray_task_config=RayTaskConfig(
|
163
|
+
ray_version="2.40.0-py310-gpu",
|
164
|
+
file_path="serve",
|
165
|
+
artifact_id=artifact_id,
|
166
|
+
deployment_name="app",
|
167
|
+
replica_resource=ReplicaResource(
|
168
|
+
cpu=10,
|
169
|
+
ram_gb=100,
|
170
|
+
gpu=1,
|
171
|
+
),
|
172
|
+
),
|
173
|
+
task_scheduling=TaskScheduling(
|
174
|
+
scheduling_oneoff=OneOffScheduling(
|
175
|
+
trigger_timestamp=int(datetime.now().timestamp()) + 10,
|
176
|
+
min_replicas=1,
|
177
|
+
max_replicas=10,
|
178
|
+
)
|
145
179
|
),
|
146
180
|
),
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
),
|
154
|
-
),
|
155
|
-
))
|
181
|
+
))
|
182
|
+
|
183
|
+
# Start the task
|
184
|
+
task_manager.start_task(task.task_id)
|
185
|
+
except Exception as e:
|
186
|
+
raise e
|
156
187
|
|
157
|
-
task_manager.start_task(task.task_id)
|
158
188
|
return task.task_id
|
159
189
|
```
|
160
190
|
|
@@ -163,14 +193,20 @@ def create_task_and_start(client, artifact_id):
|
|
163
193
|
Once the task is running, use the endpoint for inference:
|
164
194
|
|
165
195
|
```python
|
196
|
+
from gmicloud import *
|
166
197
|
from examples.completion import call_chat_completion
|
167
198
|
|
168
|
-
|
169
|
-
|
170
|
-
task_id = create_task_and_start(client, artifact_id)
|
199
|
+
# Initialize the Client
|
200
|
+
cli = Client()
|
171
201
|
|
172
|
-
|
173
|
-
|
202
|
+
# Create an artifact from a template
|
203
|
+
artifact_id = create_artifact_from_template(cli)
|
204
|
+
|
205
|
+
# Create a task and start it
|
206
|
+
task_id = create_task_and_start(cli, artifact_id)
|
207
|
+
|
208
|
+
# Call chat completion
|
209
|
+
print(call_chat_completion(cli, task_id))
|
174
210
|
```
|
175
211
|
|
176
212
|
## API Reference
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|