Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add params of config in create #75

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions hugie/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
import json as json_lib

import requests
import typer
Expand Down Expand Up @@ -72,7 +73,29 @@ def list(

@app.command()
def create(
data: str = typer.Argument(..., help="Path JSON data to create the endpoint"),
data: str = typer.Argument(None, help="Path JSON data to create the endpoint"),
accountId: str = typer.Option(
None, help="ID of the account (for private endpoints)"
),
name: str = typer.Option("hf-endpoint", help="Name of the endpoint"),
type: str = typer.Option(
None, help="Type of endpoint, one of ['public', 'protected', 'private']"
),
accelerator: str = typer.Option(
"cpu", help="Accelerator to use. One of ['CPU','GPU']"
),
instanceType: str = typer.Option("c6i"),
instanceSize: str = typer.Option("small"),
minReplica: int = typer.Option(1, help="Minimum number of replicas"),
maxReplica: int = typer.Option(1, help="Maximum number of replicas"),
framework: str = typer.Option("custom", help="Framework to use"),
repository: str = typer.Option("t5-small", help="Name of the hf model repository"),
revision: str = typer.Option("main", help="Revision of the hf model repository"),
task: str = typer.Option("translation", help="Task of the model"),
vendor: str = typer.Option("aws", help="Vendor to use. One of ['aws','gcp']"),
region: str = typer.Option(
"us-east-1", help="Vendor specific region, e.g. 'us-east-1'"
),
json: Optional[bool] = typer.Option(
None, "--json", help="Prints the full output in JSON."
),
Expand All @@ -84,7 +107,39 @@ def create(
data (str): Path to JSON data to create the endpoint
"""

data = InferenceEndpointConfig.from_json(data).model_dump()
if not data:
data = {
"accountId": None,
"name": name,
"type": type,
"compute": {
"accelerator": accelerator,
"instanceType": instanceType,
"instanceSize": instanceSize,
"scaling": {
"minReplica": minReplica,
"maxReplica": maxReplica,
},
},
"model": {
"repository": repository,
"revision": revision,
"task": task,
"framework": framework,
"image": {
"huggingface": {},
},
},
"provider": {
"vendor": vendor,
"region": region,
},
"type": "protected",
}
data = InferenceEndpointConfig.parse_obj(data).model_dump()
else:
data = InferenceEndpointConfig.from_json(data).model_dump()
ivyleavedtoadflax marked this conversation as resolved.
Show resolved Hide resolved
print(data)
nsorros marked this conversation as resolved.
Show resolved Hide resolved
name = data["name"]
vendor = data["provider"]["vendor"]
repository = data["model"]["repository"]
Expand All @@ -97,7 +152,7 @@ def create(

except (requests.exceptions.HTTPError, requests.exceptions.RequestException) as e:

handle_requests_error(e)
handle_requests_error(e, data)

except Exception as e:

Expand Down
Loading