-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve cli * Intro ConfigLoader and fix some bugs * Fix query
- Loading branch information
Showing
8 changed files
with
189 additions
and
82 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,13 +1,11 @@ | ||
from pathlib import Path | ||
|
||
from moriarty.matrix.operator_.params import CreateEndpointParams | ||
from moriarty.deploy.endpoint import Endpoint | ||
|
||
_HERE = Path(__file__).parent | ||
|
||
if __name__ == "__main__": | ||
define = CreateEndpointParams( | ||
endpoint_name="hello-world", image="wh1isper/moriarty-compute-image:latest" | ||
) | ||
define = Endpoint(endpoint_name="hello-world", image="wh1isper/moriarty-compute-image:latest") | ||
dump_path = _HERE / "config.json" | ||
dump_path.write_text(define.model_dump_json(indent=4)) | ||
print(f"Dumped config to {dump_path.as_posix()}") |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from moriarty.envs import MORIARTY_MATRIX_API_URL_ENV, MORIARTY_MATRIX_TOKEN_ENV | ||
from moriarty.log import logger | ||
|
||
|
||
class Config(BaseModel): | ||
api_url: Optional[str] = None | ||
api_token: Optional[str] = None | ||
|
||
|
||
class ConfigLoader: | ||
def __init__(self, config_path: str = "~/.config/moriarty/config.json") -> None: | ||
self.config_path = Path(config_path).expanduser() | ||
if not self.config_path.exists(): | ||
self.config = Config() | ||
self.init_config_file() | ||
else: | ||
logger.info(f"Load config from: {self.config_path}") | ||
self.config = Config.model_validate_json(self.config_path.read_text()) | ||
|
||
def get_api_url(self) -> str | None: | ||
return self.config.api_url or os.getenv(MORIARTY_MATRIX_API_URL_ENV) | ||
|
||
def get_api_token(self) -> str | None: | ||
return self.config.api_token or os.getenv(MORIARTY_MATRIX_TOKEN_ENV) | ||
|
||
def init_config_file(self) -> None: | ||
if self.config_path.exists(): | ||
return | ||
|
||
self.config_path.parent.mkdir(parents=True, exist_ok=True) | ||
self.config_path.write_text(Config().model_dump_json()) |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from moriarty.matrix.operator_.enums_ import MetricType | ||
from moriarty.matrix.operator_.params import ( | ||
ContainerScope, | ||
ResourceScope, | ||
ScheduleScope, | ||
SidecarScope, | ||
) | ||
|
||
|
||
class Endpoint(BaseModel): | ||
endpoint_name: str | ||
image: str | ||
model_path: Optional[str] = None | ||
|
||
queue_capacity: Optional[int] = 5 | ||
replicas: int = 1 | ||
resource: Optional[ResourceScope] = ResourceScope() | ||
schedule: Optional[ScheduleScope] = ScheduleScope() | ||
container: Optional[ContainerScope] = ContainerScope() | ||
sidecar: Optional[SidecarScope] = SidecarScope() | ||
|
||
min_replicas: Optional[int] = None | ||
max_replicas: Optional[int] = None | ||
scale_in_cooldown: Optional[int] = None | ||
scale_out_cooldown: Optional[int] = None | ||
metrics: Optional[MetricType] = None | ||
metrics_threshold: Optional[float] = None | ||
|
||
@property | ||
def config_autoscale(self) -> bool: | ||
return any( | ||
[ | ||
self.min_replicas is not None, | ||
self.max_replicas is not None, | ||
self.scale_in_cooldown is not None, | ||
self.scale_out_cooldown is not None, | ||
self.metrics is not None, | ||
self.metrics_threshold is not None, | ||
] | ||
) |
Oops, something went wrong.