-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restructure the code of bentocloud client
Signed-off-by: Frost Ming <me@frostming.com>
- Loading branch information
Showing
22 changed files
with
1,084 additions
and
962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,62 @@ | ||
from .base import CloudClient as CloudClient | ||
from .bentocloud import BentoCloudClient as BentoCloudClient | ||
from __future__ import annotations | ||
|
||
import attrs | ||
|
||
from bentoml._internal.cloud.client import RestApiClient | ||
|
||
from .bento import BentoAPI | ||
from .config import CloudClientConfig | ||
from .deployment import DeploymentAPI | ||
from .model import ModelAPI | ||
from .secret import SecretAPI | ||
from .yatai import YataiClient as YataiClient | ||
|
||
DEFAULT_ENDPOINT = "https://cloud.bentoml.com" | ||
|
||
|
||
@attrs.frozen | ||
class BentoCloudClient: | ||
""" | ||
BentoCloudClient is a client for the BentoCloud API. | ||
Args: | ||
api_key: The API key to use for the client. env: BENTO_CLOUD_API_KEY | ||
endpoint: The endpoint to use for the client. env: BENTO_CLOUD_ENDPOINT | ||
Attributes: | ||
bento: BentoAPI | ||
model: ModelAPI | ||
deployment: Deployment | ||
""" | ||
|
||
bento: BentoAPI | ||
model: ModelAPI | ||
deployment: DeploymentAPI | ||
secret: SecretAPI | ||
|
||
def __init__( | ||
self, api_key: str | None = None, endpoint: str = DEFAULT_ENDPOINT | ||
) -> None: | ||
if api_key is None: | ||
from ..configuration.containers import BentoMLContainer | ||
|
||
cfg = CloudClientConfig.get_config() | ||
ctx = cfg.get_context(BentoMLContainer.cloud_context.get()) | ||
api_key = ctx.api_token | ||
endpoint = ctx.endpoint | ||
|
||
client = RestApiClient(endpoint, api_key) | ||
bento = BentoAPI(client) | ||
model = ModelAPI(client) | ||
deployment = DeploymentAPI(client) | ||
secret = SecretAPI(client) | ||
|
||
self.__attrs_init__( | ||
bento=bento, model=model, deployment=deployment, secret=secret | ||
) | ||
|
||
@classmethod | ||
def for_context(cls, context: str | None = None) -> "BentoCloudClient": | ||
cfg = CloudClientConfig.get_config() | ||
ctx = cfg.get_context(context) | ||
return cls(ctx.api_token, ctx.endpoint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.