"""Time the endpoint through the official SDK: one cold request, then warm ones. just smoke [app] """ import json import os import statistics import time from typesafe_sdk import TypeSafeClient STATE = { "from": "user@acme.com", "subject": "Duplicate charge on invoice #4411", "body": "Hi, we were billed twice for March. Please refund the duplicate today or we will cancel our plan.", } QUESTIONS = { "department": { "type": "choice", "instructions": "Which department should handle this request?", "criteria": { "billing": "invoices, payments, refunds", "technical": "bugs, outages, system errors", "sales": "pricing, new contracts", "other": "everything else", }, }, "urgency": { "type": "score", "instructions": "How urgent is this request?", "criteria": ["not urgent", "soon", "critical deadline or blocking issue"], }, "churn_risk": { "type": "noul", "instructions": "Does the user threaten to cancel or leave?", }, } def main() -> None: client = TypeSafeClient( api_key=os.environ["SYSTEMONE_API_KEY"], base_url=os.environ["SYSTEMONE_URL"], model="kev-latest", timeout=600, ) with client: t = time.perf_counter() first = client.system_one(state=STATE, questions=QUESTIONS) cold = time.perf_counter() - t warm = [] for _ in range(5): t = time.perf_counter() client.system_one(state=STATE, questions=QUESTIONS) warm.append(time.perf_counter() - t) print(json.dumps(first.model_dump(), indent=1, default=str)) print( f"first request {cold:.1f}s, warm median {statistics.median(warm) * 1000:.0f}ms, warm max {max(warm) * 1000:.0f}ms" ) if __name__ == "__main__": main()