Skip to content

Commit 2c974ea

Browse files
author
balogh.adam@icloud.com
committed
move
1 parent 0eb13c8 commit 2c974ea

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

src/opengradient/client/llm.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def __init__(
108108

109109
self._connect_tee()
110110

111+
# ── TEE resolution and connection ───────────────────────────────────────────
112+
111113
def _connect_tee(self) -> None:
112114
"""Resolve TEE from registry and create a secure HTTP client for it."""
113115
endpoint, tls_cert_der, tee_id, tee_payment_address = self._resolve_tee(
@@ -132,30 +134,6 @@ async def _refresh_tee(self) -> None:
132134
except Exception:
133135
logger.debug("Failed to close previous HTTP client during TEE refresh.", exc_info=True)
134136

135-
async def _call_with_tee_retry(
136-
self,
137-
operation_name: str,
138-
call: Callable[[], Awaitable[T]],
139-
) -> T:
140-
"""Execute *call*; on connection failure, pick a new TEE and retry once.
141-
142-
Only retries when the request never reached the server (no HTTP response).
143-
Server-side errors (4xx/5xx) are not retried.
144-
"""
145-
try:
146-
return await call()
147-
except httpx.HTTPStatusError:
148-
raise
149-
except Exception as exc:
150-
logger.warning(
151-
"Connection failure during %s; refreshing TEE and retrying once: %s",
152-
operation_name,
153-
exc,
154-
)
155-
await self._refresh_tee()
156-
return await call()
157-
158-
# ── TEE resolution ──────────────────────────────────────────────────
159137

160138
@staticmethod
161139
def _resolve_tee(
@@ -224,6 +202,29 @@ def _tee_metadata(self) -> Dict:
224202
tee_payment_address=self._tee_payment_address,
225203
)
226204

205+
async def _call_with_tee_retry(
206+
self,
207+
operation_name: str,
208+
call: Callable[[], Awaitable[T]],
209+
) -> T:
210+
"""Execute *call*; on connection failure, pick a new TEE and retry once.
211+
212+
Only retries when the request never reached the server (no HTTP response).
213+
Server-side errors (4xx/5xx) are not retried.
214+
"""
215+
try:
216+
return await call()
217+
except httpx.HTTPStatusError:
218+
raise
219+
except Exception as exc:
220+
logger.warning(
221+
"Connection failure during %s; refreshing TEE and retrying once: %s",
222+
operation_name,
223+
exc,
224+
)
225+
await self._refresh_tee()
226+
return await call()
227+
227228
# ── Public API ──────────────────────────────────────────────────────
228229

229230
def ensure_opg_approval(self, opg_amount: float) -> Permit2ApprovalResult:

0 commit comments

Comments
 (0)