gmicloud 0.1.4__tar.gz → 0.1.6__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.6/PKG-INFO +147 -0
- gmicloud-0.1.6/README.md +135 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/__init__.py +12 -1
- gmicloud-0.1.6/gmicloud/_internal/_client/_artifact_client.py +212 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_client/_http_client.py +5 -1
- gmicloud-0.1.6/gmicloud/_internal/_client/_iam_client.py +189 -0
- gmicloud-0.1.6/gmicloud/_internal/_client/_task_client.py +153 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_enums.py +13 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_manager/_artifact_manager.py +100 -5
- gmicloud-0.1.6/gmicloud/_internal/_manager/_iam_manager.py +36 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_manager/_task_manager.py +88 -12
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_models.py +121 -12
- gmicloud-0.1.6/gmicloud/client.py +247 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/tests/test_artifacts.py +14 -15
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/tests/test_tasks.py +1 -1
- gmicloud-0.1.6/gmicloud.egg-info/PKG-INFO +147 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud.egg-info/SOURCES.txt +1 -1
- {gmicloud-0.1.4 → gmicloud-0.1.6}/pyproject.toml +3 -3
- gmicloud-0.1.4/PKG-INFO +0 -250
- gmicloud-0.1.4/README.md +0 -238
- gmicloud-0.1.4/gmicloud/_internal/_client/_artifact_client.py +0 -142
- gmicloud-0.1.4/gmicloud/_internal/_client/_iam_client.py +0 -124
- gmicloud-0.1.4/gmicloud/_internal/_client/_task_client.py +0 -108
- gmicloud-0.1.4/gmicloud/client.py +0 -122
- gmicloud-0.1.4/gmicloud/tests/__init__.py +0 -0
- gmicloud-0.1.4/gmicloud.egg-info/PKG-INFO +0 -250
- {gmicloud-0.1.4/examples → gmicloud-0.1.6/gmicloud/_internal}/__init__.py +0 -0
- {gmicloud-0.1.4/gmicloud/_internal → gmicloud-0.1.6/gmicloud/_internal/_client}/__init__.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_client/_decorator.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_client/_file_upload_client.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_config.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_constants.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/_internal/_exceptions.py +0 -0
- {gmicloud-0.1.4/gmicloud/_internal/_client → gmicloud-0.1.6/gmicloud/_internal/_manager}/__init__.py +0 -0
- {gmicloud-0.1.4/gmicloud/_internal/_manager → gmicloud-0.1.6/gmicloud/tests}/__init__.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud/utils/uninstall_packages.py +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud.egg-info/dependency_links.txt +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/gmicloud.egg-info/top_level.txt +0 -0
- {gmicloud-0.1.4 → gmicloud-0.1.6}/setup.cfg +0 -0
gmicloud-0.1.6/PKG-INFO
ADDED
@@ -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
|
gmicloud-0.1.6/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# GMICloud SDK (Beta)
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
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.
|
5
|
+
|
6
|
+
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.
|
7
|
+
|
8
|
+
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.
|
9
|
+
|
10
|
+
## Features
|
11
|
+
|
12
|
+
- Artifact Management: Easily create, update, and manage ML model artifacts.
|
13
|
+
- Task Management: Quickly create, schedule, and manage deployment tasks for model inference.
|
14
|
+
- Usage Data Retrieval : Fetch and analyze usage data to optimize resource allocation.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
To install the SDK, use pip:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
pip install gmicloud
|
22
|
+
```
|
23
|
+
|
24
|
+
## Setup
|
25
|
+
|
26
|
+
You must configure authentication credentials for accessing the GMI Cloud API.
|
27
|
+
To create account and get log in info please visit **GMI inference platform: https://inference-engine.gmicloud.ai/**.
|
28
|
+
|
29
|
+
There are two ways to configure the SDK:
|
30
|
+
|
31
|
+
### Option 1: Using Environment Variables
|
32
|
+
|
33
|
+
Set the following environment variables:
|
34
|
+
|
35
|
+
```shell
|
36
|
+
export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
|
37
|
+
export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
|
38
|
+
export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
|
39
|
+
```
|
40
|
+
|
41
|
+
### Option 2: Passing Credentials as Parameters
|
42
|
+
|
43
|
+
Pass `client_id`, `email`, and `password` directly to the Client object when initializing it in your script:
|
44
|
+
|
45
|
+
```python
|
46
|
+
from gmicloud import Client
|
47
|
+
|
48
|
+
client = Client(client_id="<YOUR_CLIENT_ID>", email="<YOUR_EMAIL>", password="<YOUR_PASSWORD>")
|
49
|
+
```
|
50
|
+
|
51
|
+
## Quick Start
|
52
|
+
|
53
|
+
### 1. How to run the code in the example folder
|
54
|
+
```bash
|
55
|
+
cd path/to/gmicloud-sdk
|
56
|
+
# Create a virtual environment
|
57
|
+
python -m venv venv
|
58
|
+
source venv/bin/activate
|
59
|
+
|
60
|
+
pip install -r requirements.txt
|
61
|
+
python -m examples.create_task_from_artifact_template.py
|
62
|
+
```
|
63
|
+
|
64
|
+
### 2. Create an inference task from an artifact template
|
65
|
+
|
66
|
+
This is the simplest example to deploy an inference task using an existing artifact template:
|
67
|
+
|
68
|
+
Up-to-date code in /examples/create_task_from_artifact_template.py
|
69
|
+
|
70
|
+
```python
|
71
|
+
from datetime import datetime
|
72
|
+
import os
|
73
|
+
import sys
|
74
|
+
|
75
|
+
from gmicloud import *
|
76
|
+
from examples.completion import call_chat_completion
|
77
|
+
|
78
|
+
cli = Client()
|
79
|
+
|
80
|
+
# List templates offered by GMI cloud
|
81
|
+
templates = cli.list_templates()
|
82
|
+
print(f"Found {len(templates)} templates: {templates}")
|
83
|
+
|
84
|
+
# Pick a template from the list
|
85
|
+
pick_template = "Llama-3.1-8B"
|
86
|
+
|
87
|
+
# Create Artifact from template
|
88
|
+
artifact_id, recommended_replica_resources = cli.create_artifact_from_template(templates[0])
|
89
|
+
print(f"Created artifact {artifact_id} with recommended replica resources: {recommended_replica_resources}")
|
90
|
+
|
91
|
+
# Create Task based on Artifact
|
92
|
+
task_id = cli.create_task(artifact_id, recommended_replica_resources, TaskScheduling(
|
93
|
+
scheduling_oneoff=OneOffScheduling(
|
94
|
+
trigger_timestamp=int(datetime.now().timestamp()),
|
95
|
+
min_replicas=1,
|
96
|
+
max_replicas=1,
|
97
|
+
)
|
98
|
+
))
|
99
|
+
task = cli.task_manager.get_task(task_id)
|
100
|
+
print(f"Task created: {task.config.task_name}. You can check details at https://inference-engine.gmicloud.ai/user-console/task")
|
101
|
+
|
102
|
+
# Start Task and wait for it to be ready
|
103
|
+
cli.start_task_and_wait(task.task_id)
|
104
|
+
|
105
|
+
# Testing with calling chat completion
|
106
|
+
print(call_chat_completion(cli, task.task_id))
|
107
|
+
|
108
|
+
```
|
109
|
+
|
110
|
+
## API Reference
|
111
|
+
|
112
|
+
### Client
|
113
|
+
|
114
|
+
Represents the entry point to interact with GMI Cloud APIs.
|
115
|
+
Client(
|
116
|
+
client_id: Optional[str] = "",
|
117
|
+
email: Optional[str] = "",
|
118
|
+
password: Optional[str] = ""
|
119
|
+
)
|
120
|
+
|
121
|
+
### Artifact Management
|
122
|
+
|
123
|
+
* get_artifact_templates(): Fetch a list of available artifact templates.
|
124
|
+
* create_artifact_from_template(template_id: str): Create a model artifact from a given template.
|
125
|
+
* get_artifact(artifact_id: str): Get details of a specific artifact.
|
126
|
+
|
127
|
+
### Task Management
|
128
|
+
|
129
|
+
* create_task_from_artifact_template(template_id: str, scheduling: TaskScheduling): Create and schedule a task using an
|
130
|
+
artifact template.
|
131
|
+
* start_task(task_id: str): Start a task.
|
132
|
+
* get_task(task_id: str): Retrieve the status and details of a specific task.
|
133
|
+
|
134
|
+
## Notes & Troubleshooting
|
135
|
+
k
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import logging
|
2
|
+
import os
|
3
|
+
|
1
4
|
from ._internal._models import (
|
2
5
|
Artifact,
|
3
6
|
ArtifactData,
|
@@ -16,7 +19,8 @@ from ._internal._models import (
|
|
16
19
|
)
|
17
20
|
from ._internal._enums import (
|
18
21
|
BuildStatus,
|
19
|
-
TaskEndpointStatus
|
22
|
+
TaskEndpointStatus,
|
23
|
+
TaskStatus
|
20
24
|
)
|
21
25
|
from .client import Client
|
22
26
|
|
@@ -39,3 +43,10 @@ __all__ = [
|
|
39
43
|
"BuildStatus",
|
40
44
|
"TaskEndpointStatus",
|
41
45
|
]
|
46
|
+
|
47
|
+
# Configure logging
|
48
|
+
log_level = os.getenv("GMI_CLOUD_LOG_LEVEL", "INFO").upper()
|
49
|
+
logging.basicConfig(
|
50
|
+
level=log_level,
|
51
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
52
|
+
)
|
@@ -0,0 +1,212 @@
|
|
1
|
+
from typing import List
|
2
|
+
import logging
|
3
|
+
from requests.exceptions import RequestException
|
4
|
+
|
5
|
+
from ._http_client import HTTPClient
|
6
|
+
from ._iam_client import IAMClient
|
7
|
+
from ._decorator import handle_refresh_token
|
8
|
+
from .._models import *
|
9
|
+
from .._config import ARTIFACT_SERVICE_BASE_URL
|
10
|
+
|
11
|
+
logger = logging.getLogger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
class ArtifactClient:
|
15
|
+
"""
|
16
|
+
Client for interacting with the Artifact Service API.
|
17
|
+
|
18
|
+
This client provides methods to perform CRUD operations on artifacts,
|
19
|
+
as well as generating signed URLs for uploading large files.
|
20
|
+
"""
|
21
|
+
|
22
|
+
def __init__(self, iam_client: IAMClient):
|
23
|
+
"""
|
24
|
+
Initializes the ArtifactClient with an HTTPClient configured
|
25
|
+
to communicate with the Artifact Service base URL.
|
26
|
+
"""
|
27
|
+
self.client = HTTPClient(ARTIFACT_SERVICE_BASE_URL)
|
28
|
+
self.iam_client = iam_client
|
29
|
+
|
30
|
+
@handle_refresh_token
|
31
|
+
def get_artifact(self, artifact_id: str) -> Optional[Artifact]:
|
32
|
+
"""
|
33
|
+
Fetches an artifact by its ID.
|
34
|
+
|
35
|
+
:param artifact_id: The ID of the artifact to fetch.
|
36
|
+
:return: The Artifact object or None if an error occurs.
|
37
|
+
"""
|
38
|
+
try:
|
39
|
+
response = self.client.get(
|
40
|
+
"/get_artifact",
|
41
|
+
self.iam_client.get_custom_headers(),
|
42
|
+
{"artifact_id": artifact_id}
|
43
|
+
)
|
44
|
+
return Artifact.model_validate(response) if response else None
|
45
|
+
except (RequestException, ValueError) as e:
|
46
|
+
logger.error(f"Failed to fetch artifact {artifact_id}: {e}")
|
47
|
+
return None
|
48
|
+
|
49
|
+
@handle_refresh_token
|
50
|
+
def get_all_artifacts(self) -> List[Artifact]:
|
51
|
+
"""
|
52
|
+
Fetches all artifacts.
|
53
|
+
|
54
|
+
:return: A list of Artifact objects. If an error occurs, returns an empty list.
|
55
|
+
"""
|
56
|
+
try:
|
57
|
+
response = self.client.get("/get_all_artifacts", self.iam_client.get_custom_headers())
|
58
|
+
if not response:
|
59
|
+
logger.error("Empty response from /get_all_artifacts")
|
60
|
+
return []
|
61
|
+
return [Artifact.model_validate(item) for item in response]
|
62
|
+
except (RequestException, ValueError) as e:
|
63
|
+
logger.error(f"Failed to fetch all artifacts: {e}")
|
64
|
+
return []
|
65
|
+
|
66
|
+
@handle_refresh_token
|
67
|
+
def create_artifact(self, request: CreateArtifactRequest) -> Optional[CreateArtifactResponse]:
|
68
|
+
"""
|
69
|
+
Creates a new artifact in the service.
|
70
|
+
|
71
|
+
:param request: The request object containing artifact details.
|
72
|
+
:return: The response object containing the created artifact details, or None on error.
|
73
|
+
"""
|
74
|
+
try:
|
75
|
+
response = self.client.post(
|
76
|
+
"/create_artifact",
|
77
|
+
self.iam_client.get_custom_headers(),
|
78
|
+
request.model_dump()
|
79
|
+
)
|
80
|
+
return CreateArtifactResponse.model_validate(response) if response else None
|
81
|
+
except (RequestException, ValueError) as e:
|
82
|
+
logger.error(f"Failed to create artifact: {e}")
|
83
|
+
return None
|
84
|
+
|
85
|
+
@handle_refresh_token
|
86
|
+
def create_artifact_from_template(self, artifact_template_id: str) -> Optional[CreateArtifactFromTemplateResponse]:
|
87
|
+
"""
|
88
|
+
Creates a new artifact in the service.
|
89
|
+
|
90
|
+
:param artifact_template_id: The ID of the artifact template to use.
|
91
|
+
:return: The response object containing the created artifact details or None if an error occurs.
|
92
|
+
"""
|
93
|
+
try:
|
94
|
+
response = self.client.post(
|
95
|
+
"/create_artifact_from_template",
|
96
|
+
self.iam_client.get_custom_headers(),
|
97
|
+
{"artifact_template_id": artifact_template_id}
|
98
|
+
)
|
99
|
+
return CreateArtifactFromTemplateResponse.model_validate(response) if response else None
|
100
|
+
except (RequestException, ValueError) as e:
|
101
|
+
logger.error(f"Failed to create artifact from template {artifact_template_id}: {e}")
|
102
|
+
return None
|
103
|
+
|
104
|
+
@handle_refresh_token
|
105
|
+
def rebuild_artifact(self, artifact_id: str) -> Optional[RebuildArtifactResponse]:
|
106
|
+
"""
|
107
|
+
Rebuilds an artifact in the service.
|
108
|
+
|
109
|
+
:param artifact_id: The ID of the artifact to rebuild.
|
110
|
+
:return: The response object containing the rebuilt artifact details or None if an error occurs.
|
111
|
+
"""
|
112
|
+
try:
|
113
|
+
response = self.client.post(
|
114
|
+
"/rebuild_artifact",
|
115
|
+
self.iam_client.get_custom_headers(),
|
116
|
+
{"artifact_id": artifact_id}
|
117
|
+
)
|
118
|
+
return RebuildArtifactResponse.model_validate(response) if response else None
|
119
|
+
except (RequestException, ValueError) as e:
|
120
|
+
logger.error(f"Failed to rebuild artifact {artifact_id}: {e}")
|
121
|
+
return None
|
122
|
+
|
123
|
+
@handle_refresh_token
|
124
|
+
def delete_artifact(self, artifact_id: str) -> Optional[DeleteArtifactResponse]:
|
125
|
+
"""
|
126
|
+
Deletes an artifact by its ID.
|
127
|
+
|
128
|
+
:param artifact_id: The ID of the artifact to delete.
|
129
|
+
:return: The response object containing the deleted artifact details or None if an error occurs.
|
130
|
+
"""
|
131
|
+
try:
|
132
|
+
response = self.client.delete(
|
133
|
+
"/delete_artifact",
|
134
|
+
self.iam_client.get_custom_headers(),
|
135
|
+
{"artifact_id": artifact_id}
|
136
|
+
)
|
137
|
+
return DeleteArtifactResponse.model_validate(response) if response else None
|
138
|
+
except (RequestException, ValueError) as e:
|
139
|
+
logger.error(f"Failed to delete artifact {artifact_id}: {e}")
|
140
|
+
return None
|
141
|
+
|
142
|
+
@handle_refresh_token
|
143
|
+
def get_bigfile_upload_url(self, request: GetBigFileUploadUrlRequest) -> Optional[GetBigFileUploadUrlResponse]:
|
144
|
+
"""
|
145
|
+
Generates a pre-signed URL for uploading a large file.
|
146
|
+
|
147
|
+
:param request: The request object containing the artifact ID, file name, and file type.
|
148
|
+
:return: The response object containing the pre-signed URL and upload details, or None if an error occurs.
|
149
|
+
"""
|
150
|
+
try:
|
151
|
+
response = self.client.post("/get_bigfile_upload_url",
|
152
|
+
self.iam_client.get_custom_headers(),
|
153
|
+
request.model_dump())
|
154
|
+
|
155
|
+
if not response:
|
156
|
+
logger.error("Empty response from /get_bigfile_upload_url")
|
157
|
+
return None
|
158
|
+
|
159
|
+
return GetBigFileUploadUrlResponse.model_validate(response)
|
160
|
+
|
161
|
+
except (RequestException, ValueError) as e:
|
162
|
+
logger.error(f"Failed to generate upload URL: {e}")
|
163
|
+
return None
|
164
|
+
|
165
|
+
@handle_refresh_token
|
166
|
+
def delete_bigfile(self, request: DeleteBigfileRequest) -> Optional[DeleteBigfileResponse]:
|
167
|
+
"""
|
168
|
+
Deletes a large file associated with an artifact.
|
169
|
+
|
170
|
+
:param request: The request object containing the artifact ID and file name.
|
171
|
+
:return: The response object containing the deletion status, or None if an error occurs.
|
172
|
+
"""
|
173
|
+
try:
|
174
|
+
response = self.client.delete("/delete_bigfile",
|
175
|
+
self.iam_client.get_custom_headers(),
|
176
|
+
request.model_dump())
|
177
|
+
|
178
|
+
if not response:
|
179
|
+
logger.error("Empty response from /delete_bigfile")
|
180
|
+
return None
|
181
|
+
|
182
|
+
return DeleteBigfileResponse.model_validate(response)
|
183
|
+
|
184
|
+
except (RequestException, ValueError) as e:
|
185
|
+
logger.error(f"Failed to delete big file: {e}")
|
186
|
+
return None
|
187
|
+
|
188
|
+
@handle_refresh_token
|
189
|
+
def get_public_templates(self) -> List[ArtifactTemplate]:
|
190
|
+
"""
|
191
|
+
Fetches all artifact templates.
|
192
|
+
|
193
|
+
:return: A list of ArtifactTemplate objects.
|
194
|
+
:rtype: List[ArtifactTemplate]
|
195
|
+
"""
|
196
|
+
try:
|
197
|
+
response = self.client.get("/get_public_templates", self.iam_client.get_custom_headers())
|
198
|
+
|
199
|
+
if not response:
|
200
|
+
logger.error("Empty response received from /get_public_templates API")
|
201
|
+
return []
|
202
|
+
|
203
|
+
try:
|
204
|
+
result = GetPublicTemplatesResponse.model_validate(response)
|
205
|
+
return result.artifact_templates
|
206
|
+
except ValueError as ve:
|
207
|
+
logger.error(f"Failed to validate response data: {ve}")
|
208
|
+
return []
|
209
|
+
|
210
|
+
except RequestException as e:
|
211
|
+
logger.error(f"Request to /get_public_templates failed: {e}")
|
212
|
+
return []
|
@@ -1,8 +1,12 @@
|
|
1
|
+
import logging
|
2
|
+
|
1
3
|
import requests
|
2
4
|
from .._exceptions import APIError
|
3
5
|
from .._exceptions import UnauthorizedError
|
4
6
|
from .._constants import *
|
5
7
|
|
8
|
+
logger = logging.getLogger(__name__)
|
9
|
+
|
6
10
|
|
7
11
|
class HTTPClient:
|
8
12
|
"""
|
@@ -51,6 +55,7 @@ class HTTPClient:
|
|
51
55
|
response = None
|
52
56
|
try:
|
53
57
|
response = requests.request(method, url, params=params, json=data, headers=headers)
|
58
|
+
logger.debug(response.text)
|
54
59
|
if response.status_code == 401:
|
55
60
|
raise UnauthorizedError("Access token expired or invalid.")
|
56
61
|
elif response.status_code != 200 and response.status_code != 201:
|
@@ -61,7 +66,6 @@ class HTTPClient:
|
|
61
66
|
raise APIError(f"HTTP Request failed: {error_message}")
|
62
67
|
# Raise for HTTP errors
|
63
68
|
response.raise_for_status()
|
64
|
-
print(response.text)
|
65
69
|
|
66
70
|
except requests.exceptions.RequestException as e:
|
67
71
|
raise APIError(f"HTTP Request failed: {str(e)}")
|