Skip to content

Commit 4d5cd55

Browse files
author
1bcMax
committed
fix: resolve circular import for User-Agent version string
1 parent 69c3385 commit 4d5cd55

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

blockrun_llm/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@
6060
validate_resource_url,
6161
)
6262

63-
from . import __version__
64-
6563
# Load environment variables
6664
load_dotenv()
6765

6866
# User-Agent for client identification in server logs
69-
USER_AGENT = f"blockrun-python/{__version__}"
67+
# Version read lazily to avoid circular import with __init__.py
68+
def _get_user_agent() -> str:
69+
from . import __version__
70+
return f"blockrun-python/{__version__}"
7071

7172

7273
# =============================================================================
@@ -408,7 +409,7 @@ def _request_with_payment(self, endpoint: str, body: Dict[str, Any]) -> ChatResp
408409
response = self._client.post(
409410
url,
410411
json=body,
411-
headers={"Content-Type": "application/json", "User-Agent": USER_AGENT},
412+
headers={"Content-Type": "application/json", "User-Agent": _get_user_agent()},
412413
)
413414

414415
# Handle 402 Payment Required
@@ -505,7 +506,7 @@ def _handle_payment_and_retry(
505506
json=body,
506507
headers={
507508
"Content-Type": "application/json",
508-
"User-Agent": USER_AGENT,
509+
"User-Agent": _get_user_agent(),
509510
"PAYMENT-SIGNATURE": payment_payload,
510511
},
511512
timeout=request_timeout,
@@ -832,7 +833,7 @@ async def _request_with_payment(self, endpoint: str, body: Dict[str, Any]) -> Ch
832833
response = await self._client.post(
833834
url,
834835
json=body,
835-
headers={"Content-Type": "application/json", "User-Agent": USER_AGENT},
836+
headers={"Content-Type": "application/json", "User-Agent": _get_user_agent()},
836837
)
837838

838839
if response.status_code == 402:
@@ -909,7 +910,7 @@ async def _handle_payment_and_retry(
909910
json=body,
910911
headers={
911912
"Content-Type": "application/json",
912-
"User-Agent": USER_AGENT,
913+
"User-Agent": _get_user_agent(),
913914
"PAYMENT-SIGNATURE": payment_payload,
914915
},
915916
)

0 commit comments

Comments
 (0)