From 02c7a41bc8117a4e478019eecbedc35409e1cf7a Mon Sep 17 00:00:00 2001 From: verseon0980 Date: Thu, 9 Apr 2026 09:22:48 +0530 Subject: [PATCH] make Twins.chat() async to prevent event loop blocking Signed-off-by: verseon0980 --- src/opengradient/client/twins.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/opengradient/client/twins.py b/src/opengradient/client/twins.py index 94bafcc2..1c06ee93 100644 --- a/src/opengradient/client/twins.py +++ b/src/opengradient/client/twins.py @@ -18,7 +18,7 @@ class Twins: Usage: twins = og.Twins(api_key="your-api-key") - response = twins.chat( + response = await twins.chat( twin_id="0x1abd463fd6244be4a1dc0f69e0b70cd5", model=og.TEE_LLM.GROK_4_1_FAST_NON_REASONING, messages=[{"role": "user", "content": "What do you think about AI?"}], @@ -30,7 +30,7 @@ class Twins: def __init__(self, api_key: str): self._api_key = api_key - def chat( + async def chat( self, twin_id: str, model: TEE_LLM, @@ -70,7 +70,8 @@ def chat( payload["max_tokens"] = max_tokens try: - response = httpx.post(url, json=payload, headers=headers, timeout=60) + async with httpx.AsyncClient() as client: + response = await client.post(url, json=payload, headers=headers, timeout=60) response.raise_for_status() result = response.json()