Skip to content

Commit

Permalink
working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlov721 committed Nov 7, 2024
1 parent 406035d commit 0674fce
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 81 deletions.
21 changes: 14 additions & 7 deletions modelconverter/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,17 @@ class ModelPrecision(str, Enum):
Optional[str], typer.Option(help="The ID of the model", show_default=False)
]

ModelIDRequired = Annotated[str, typer.Argument(help="The ID of the model")]
ModelIDOptionRequired = Annotated[
str, typer.Option(help="The ID of the model")
]

ModelVersionIDOption = Annotated[
Optional[str],
typer.Option(help="The ID of the model version", show_default=False),
]

ModelVersionIDArgument = Annotated[
str, typer.Argument(help="The ID of the model version")
ModelVersionIDOptionRequired = Annotated[
str, typer.Option(help="The ID of the model version")
]

ModelPrecisionOption = Annotated[
Expand Down Expand Up @@ -274,13 +276,13 @@ class ModelPrecision(str, Enum):
typer.Option(help="Commit hash", show_default=False),
]

HubVersionRequired = Annotated[
HubVersionOptionRequired = Annotated[
str,
typer.Option(help="What version to ", show_default=False),
]

NameArgument = Annotated[
str, typer.Argument(help="Name of the resource", show_default=False)
str, typer.Argument(help="Name of the model", show_default=False)
]

UserIDOption = Annotated[
Expand All @@ -294,7 +296,7 @@ class ModelPrecision(str, Enum):
]

DescriptionOption = Annotated[
str,
Optional[str],
typer.Option(help="Description of the model", show_default=False),
]

Expand All @@ -303,7 +305,12 @@ class ModelPrecision(str, Enum):
typer.Option(help="Short description of the model", show_default=False),
]

LicenseTypeOption = Annotated[License, typer.Option(help="License type.")]
LicenseTypeOptionRequired = Annotated[
License, typer.Option(help="License type.")
]
LicenseTypeOption = Annotated[
Optional[License], typer.Option(help="License type.", show_default=False)
]

IsPublicOption = Annotated[
bool,
Expand Down
15 changes: 10 additions & 5 deletions modelconverter/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def format_date(date_str):
)

console.print(main_panel)
console.rule()
return model


Expand Down Expand Up @@ -258,14 +257,20 @@ def slug_to_id(
raise ValueError(f"Model with slug '{slug}' not found.")


def get_resource_id(
identifier: str,
endpoint: Literal["models", "modelVersions", "modelInstances"],
) -> str:
if is_valid_uuid(identifier):
return identifier
return slug_to_id(identifier, endpoint)


def request_info(
identifier: str,
endpoint: Literal["models", "modelVersions", "modelInstances"],
) -> Dict[str, Any]:
if is_valid_uuid(identifier):
resource_id = identifier
else:
resource_id = slug_to_id(identifier, endpoint)
resource_id = get_resource_id(identifier, endpoint)

try:
return Request.get(f"{endpoint}/{resource_id}/").json()
Expand Down
Loading

0 comments on commit 0674fce

Please sign in to comment.