Skip to content
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.3
colorama==0.4.6
coverage==7.2.7
coverage==7.5
exceptiongroup==1.2.2
idna==3.10
importlib_metadata==8.5.0
Expand All @@ -26,3 +26,5 @@ zipp==3.20.2
pre_commit==4.0.1
rich==13.9.4
pyfiglet==1.0.2
click-spinner==0.1.10
pytest-cov==6.0.0
80 changes: 79 additions & 1 deletion src/api/machine_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,93 @@ class MachineAPI:
def __init__(self):
self.client = APIClient()

"""FPGA REQUESTS"""

@handle_api_errors
def create_machine(self, machine_name: str, machine_type: str) -> Dict[str, str]:
def create_fpga_machine(
self, machine_name: str, machine_type: str
) -> Dict[str, str]:
data = {
"machine_name": machine_name,
"machine_type": machine_type,
}
response = self.client.post("machine/fpga", data=data)
return response

@handle_api_errors
def get_fpga_inference_url(self, machine_id: str) -> Dict[str, str]:
return self.client.get(f"machine/fpga/{machine_id}/inference_url")

"""GPU REQUESTS"""

@handle_api_errors
def create_gpu_machine(
self, machine_name: str, machine_type: str
) -> Dict[str, str]:
data = {
"machine_name": machine_name,
"machine_type": machine_type,
}
response = self.client.post("machine/gpu", data=data)
return response

@handle_api_errors
def pull_gpu_model(self, machine_id: str, model_name: str) -> Dict[str, str]:
data = {
"machine_id": machine_id,
"model_name": model_name,
}
response = self.client.post("machine/gpu/pull_model", data=data)
return response

@handle_api_errors
def delete_gpu_model(self, machine_id: str, model_name: str) -> Dict[str, str]:
data = {
"machine_id": machine_id,
"model_name": model_name,
}
response = self.client.delete("machine/gpu/model", data=data)
return response

@handle_api_errors
def get_gpu_inference_url(self, machine_id: str) -> Dict[str, str]:
return self.client.get(f"machine/gpu/{machine_id}/inference_url")

"""CPU REQUESTS"""

@handle_api_errors
def create_cpu_machine(
self, machine_name: str, machine_type: str
) -> Dict[str, str]:
data = {
"machine_name": machine_name,
"machine_type": machine_type,
}
response = self.client.post("machine/cpu", data=data)
return response

@handle_api_errors
def pull_cpu_model(self, machine_id: str, model_name: str) -> Dict[str, str]:
data = {
"machine_id": machine_id,
"model_name": model_name,
}
response = self.client.post("machine/cpu/pull_model", data=data)
return response

@handle_api_errors
def delete_cpu_model(self, machine_id: str, model_name: str) -> Dict[str, str]:
data = {
"machine_id": machine_id,
"model_name": model_name,
}
response = self.client.delete("machine/cpu/model", data=data)
return response

@handle_api_errors
def get_cpu_inference_url(self, machine_id: str) -> Dict[str, str]:
return self.client.get(f"machine/cpu/{machine_id}/inference_url")

@handle_api_errors
def list_user_machines(self):
return self.client.get("machines")
Expand Down
16 changes: 11 additions & 5 deletions src/commands/key.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import click_spinner

from src.api.api_client import APIClient
from src.api.auth_api import AuthAPI
Expand All @@ -12,14 +13,16 @@ def __init__(self):
self.endpoint = AuthAPI(self.client)

def create_api_key(self, validity):
result = self.endpoint.create_api_key(ValidityEnum[validity])
with click_spinner.spinner():
result = self.endpoint.create_api_key(ValidityEnum[validity])
if result["success"]:
click.echo(f"API key created successfully: {result['data']}")
else:
click.echo(f"Failed to create API key. {result['message']}")

def list_api_keys(self):
result = self.endpoint.list_api_keys()
with click_spinner.spinner():
result = self.endpoint.list_api_keys()
if result["success"]:
click.echo("API Keys:")
for key in result["data"]:
Expand All @@ -30,19 +33,22 @@ def list_api_keys(self):
click.echo(f"Failed to retrieve API keys. {result['message']}")

def delete_api_key(self, token):
result = self.endpoint.delete_api_key(token)
with click_spinner.spinner():
result = self.endpoint.delete_api_key(token)
if result["success"]:
click.echo(f"API key deleted successfully. {result['data']}")
else:
click.echo(f"Failed to delete API key. {result['message']}")

def set_api_key(self, api_key):
result = self.endpoint.set_api_key(api_key)
with click_spinner.spinner():
result = self.endpoint.set_api_key(api_key)
if result:
click.echo("API key set successfully.")

def remove_api_key(self):
result = self.endpoint.clear_api_key()
with click_spinner.spinner():
result = self.endpoint.clear_api_key()
if result:
click.echo("API key removed successfully.")
else:
Expand Down
Loading
Loading