import os
from dotenv import load_dotenv
from simplismart import Simplismart, ModelRepoCompileCreate, ModelRepoListParams, DeploymentCreate
load_dotenv()
from time import sleep
client = Simplismart(pg_token=os.getenv("SIMPLISMART_PG_TOKEN"))
org_id = os.getenv("ORG_ID")
MODEL_REPO_NAME = "llama-3.2-1b-instruct-SDK"
# model compile
payload = ModelRepoCompileCreate(
name=MODEL_REPO_NAME,
description="llama-model - A model deployed using Simplismart",
source_type="huggingface",
source_url="meta-llama/Llama-3.2-1B-Instruct",
model_class="LlamaForCausalLM",
accelerator_type="nvidia-h100",
use_simplismart_infrastructure=True,
)
data = client.create_model_repo_private_compile(payload)
print(
f"Model compilation initiated: {data['name']} | "
f"uuid={data['uuid']} | status={data['status']} | source={data['source_url']}"
)
# Fetch the compiled model repo and wait until it's ready
list_params = ModelRepoListParams(org_id=org_id, offset=0, count=1, name=MODEL_REPO_NAME)
model_repo_id = None
prev_status = None
while True:
repos = client.list_model_repos(list_params)
result = repos["results"][0]
model_repo_id = result["uuid"]
status = result["status"]
if status != prev_status:
print(f"Model Repo {model_repo_id}: {status}")
prev_status = status
if status == "SUCCESS":
break
sleep(10)
# create deployment
deployment = client.create_deployment(
DeploymentCreate(
org=org_id,
model_repo=model_repo_id,
gpu_id="nvidia-h100",
name="llama-3.2-1b-instruct-SDK", # should be unique
min_pod_replicas=1,
max_pod_replicas=2,
autoscale_config={"targets": [{"metric": "gpu", "target": 80}]},
)
)
deployment_id = deployment["deployment_id"]
model_endpoint = deployment.get("model_endpoint", "")
print(
f"Deployment created: id={deployment_id} \n Name={deployment.get('name')} \n "
f"Model Endpoint=https://{model_endpoint}"
)
deployment_detail = client.get_model_deployment(
deployment_id=os.getenv("DEPLOYMENT_ID", deployment_id)
)
print(f"Status: {deployment_detail.get('status', 'unknown')}")
health = client.fetch_deployment_health(deployment_id=deployment_id)
health_status = health.get("data", "unknown")
if health.get("messages"):
msg = health["messages"][0].get("message", "")
print(f"Health: {health_status} — {msg}")
else:
print(f"Health: {health_status}")
if health_status == "Healthy":
print("Deployment is ready.")
else:
print("Deployment is still in progress.")