Skip to content

Commit 3d604a8

Browse files
authored
refactor(client): revive individual client initialization (#219)
Because - We should still support individual client initialization functions This commit - revive individual client initialization
1 parent d0a3f58 commit 3d604a8

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

instill/clients/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from instill.clients.client import InstillClient, init_core_client
1+
from instill.clients.client import (
2+
InstillClient,
3+
init_artifact_client,
4+
init_core_client,
5+
init_mgmt_client,
6+
init_model_client,
7+
init_pipeline_client,
8+
)
29
from instill.clients.mgmt import MgmtClient
310
from instill.clients.model import ModelClient
411
from instill.clients.pipeline import PipelineClient

instill/clients/client.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,83 @@ def get_model(self) -> ModelClient:
104104
return self.model
105105

106106

107-
def init_core_client(api_token: str, async_enabled: bool = False) -> InstillClient:
108-
return InstillClient(api_token=api_token, async_enabled=async_enabled)
107+
def init_core_client(
108+
api_token: str,
109+
requester_id="",
110+
async_enabled: bool = False,
111+
) -> InstillClient:
112+
return InstillClient(
113+
api_token=api_token,
114+
requester_id=requester_id,
115+
async_enabled=async_enabled,
116+
)
117+
118+
119+
def init_artifact_client(
120+
api_token: str,
121+
requester_id="",
122+
async_enabled: bool = False,
123+
) -> ArtifactClient:
124+
client = InstillClient(
125+
api_token=api_token,
126+
requester_id=requester_id,
127+
async_enabled=async_enabled,
128+
)
129+
if not client.get_artifact().is_serving():
130+
Logger.w(
131+
"Instill Artifact is not serving, Artifact functionalities will not work"
132+
)
133+
raise NotServingException
134+
135+
return client.get_artifact()
136+
137+
138+
def init_model_client(
139+
api_token: str,
140+
requester_id="",
141+
async_enabled: bool = False,
142+
) -> ModelClient:
143+
client = InstillClient(
144+
api_token=api_token,
145+
requester_id=requester_id,
146+
async_enabled=async_enabled,
147+
)
148+
if not client.get_model().is_serving():
149+
Logger.w("Instill Model is not serving, Model functionalities will not work")
150+
raise NotServingException
151+
152+
return client.get_model()
153+
154+
155+
def init_pipeline_client(
156+
api_token: str,
157+
requester_id="",
158+
async_enabled: bool = False,
159+
) -> PipelineClient:
160+
client = InstillClient(
161+
api_token=api_token,
162+
requester_id=requester_id,
163+
async_enabled=async_enabled,
164+
)
165+
if not client.get_pipeline().is_serving():
166+
Logger.w("Instill VDP is not serving, VDP functionalities will not work")
167+
raise NotServingException
168+
169+
return client.get_pipeline()
170+
171+
172+
def init_mgmt_client(
173+
api_token: str,
174+
requester_id="",
175+
async_enabled: bool = False,
176+
) -> MgmtClient:
177+
client = InstillClient(
178+
api_token=api_token,
179+
requester_id=requester_id,
180+
async_enabled=async_enabled,
181+
)
182+
if not client.get_mgmt().is_serving():
183+
Logger.w("Instill Core is required")
184+
raise NotServingException
185+
186+
return client.get_mgmt()

0 commit comments

Comments
 (0)