mirror of
https://github.com/thinking-machines-lab/tinker.git
synced 2026-04-19 12:58:01 +00:00
Sync contents
This commit is contained in:
parent
f3c0b1f179
commit
07bd3c2dd3
5 changed files with 18 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"last_synced_sha": "2138c60c730c51b7bc19146a38320d631c38e0cc",
|
||||
"last_sync_time": "2026-03-19T00:10:49.917056"
|
||||
"last_synced_sha": "db025e90079a19c36090a13aa88e4b2494d5a502",
|
||||
"last_sync_time": "2026-03-19T02:39:30.785199"
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "tinker"
|
||||
version = "0.16.0"
|
||||
version = "0.16.1"
|
||||
description = "The official Python SDK for the tinker API"
|
||||
readme = "README.md"
|
||||
license = "Apache-2.0"
|
||||
|
|
|
|||
|
|
@ -731,7 +731,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|||
|
||||
# Retry internal errors.
|
||||
if response.status_code >= 500:
|
||||
log.warning(
|
||||
log.debug(
|
||||
"Retrying due to status code %i. text=%s", response.status_code, response.text
|
||||
)
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ class _APIFuture(APIFuture[T]): # pyright: ignore[reportUnusedClass]
|
|||
}
|
||||
if not should_retry:
|
||||
event_data["response_headers"] = dict(e.response.headers)
|
||||
event_data["request_headers"] = dict(e.request.headers)
|
||||
event_data["response_body"] = e.body
|
||||
event_data["bad_request_retries"] = bad_request_retries
|
||||
telemetry.log(
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ logger = logging.getLogger(__name__)
|
|||
T = TypeVar("T")
|
||||
|
||||
MAX_REQUESTS_PER_HTTPX_CLIENT = 50
|
||||
MAX_CONNECTION_ERROR_RETRIES = 16
|
||||
|
||||
|
||||
class ClientConnectionPool:
|
||||
|
|
@ -46,6 +47,7 @@ class ClientConnectionPool:
|
|||
self._constructor_kwargs = constructor_kwargs
|
||||
self._clients: list[AsyncTinker] = []
|
||||
self._client_active_refcount: list[int] = []
|
||||
self._connection_error_retries_remaining: int = MAX_CONNECTION_ERROR_RETRIES
|
||||
|
||||
@contextmanager
|
||||
def aclient(self) -> Generator[AsyncTinker, None, None]:
|
||||
|
|
@ -63,6 +65,17 @@ class ClientConnectionPool:
|
|||
self._client_active_refcount[client_idx] += 1
|
||||
try:
|
||||
yield self._clients[client_idx]
|
||||
if self._connection_error_retries_remaining < MAX_CONNECTION_ERROR_RETRIES:
|
||||
self._connection_error_retries_remaining += 1
|
||||
except APIStatusError as e:
|
||||
# This indicates request rejected by Cloudflare. Reset the connection and retry
|
||||
if e.status_code == 400 and e.response.headers.get("content-length", "0") == "0":
|
||||
# Ensure a new connection gets opened
|
||||
self._clients[client_idx] = AsyncTinker(**self._constructor_kwargs)
|
||||
if self._connection_error_retries_remaining > 0:
|
||||
self._connection_error_retries_remaining -= 1
|
||||
raise APIConnectionError(request=e.request) from e
|
||||
raise e
|
||||
finally:
|
||||
self._client_active_refcount[client_idx] -= 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue