Sdm0 commited on
Commit
2879153
·
verified ·
1 Parent(s): d910631

Deploy 68c5957b

Browse files
backend/integrations/llm_factory.py CHANGED
@@ -55,7 +55,6 @@ class CloudflareRateLimiter(BaseRateLimiter):
55
  # a conservative application cap, not a measurement of Cloudflare neurons.
56
  _cloudflare_limiter = CloudflareRateLimiter(max(1, int(os.getenv("CLOUDFLARE_DAILY_REQUEST_LIMIT", "50"))))
57
  _cloudflare_routes = ReachableCloudflareRoutes()
58
- _cloudflare_gateway_routes = ReachableCloudflareRoutes("gateway.ai.cloudflare.com")
59
  DEFAULT_TEMPERATURE = 0.0
60
  DEFAULT_REQUEST_TIMEOUT = float(os.getenv("OCR_MODEL_TIMEOUT_SECONDS", "60"))
61
  DEFAULT_OUTPUT_TOKENS = int(os.getenv("OCR_MODEL_MAX_OUTPUT_TOKENS", "2000"))
@@ -143,8 +142,11 @@ def _get_cloudflare_chat(**kwargs: Any) -> Optional[Any]:
143
  headers = dict(kwargs.pop("default_headers", {}) or {})
144
  headers.update({"cf-aig-authorization": f"Bearer {gateway_token or api_key}", "cf-aig-collect-log": "false", "cf-aig-skip-cache": "true"})
145
  kwargs["default_headers"] = headers
146
- kwargs.setdefault("http_client", httpx.Client(transport=CloudflareTransport(_cloudflare_gateway_routes), timeout=timeout))
147
- kwargs.setdefault("http_async_client", httpx.AsyncClient(transport=AsyncCloudflareTransport(_cloudflare_gateway_routes), timeout=timeout))
 
 
 
148
  base_url = f"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat"
149
  else:
150
  kwargs.setdefault("http_client", httpx.Client(transport=CloudflareTransport(_cloudflare_routes), timeout=timeout))
 
55
  # a conservative application cap, not a measurement of Cloudflare neurons.
56
  _cloudflare_limiter = CloudflareRateLimiter(max(1, int(os.getenv("CLOUDFLARE_DAILY_REQUEST_LIMIT", "50"))))
57
  _cloudflare_routes = ReachableCloudflareRoutes()
 
58
  DEFAULT_TEMPERATURE = 0.0
59
  DEFAULT_REQUEST_TIMEOUT = float(os.getenv("OCR_MODEL_TIMEOUT_SECONDS", "60"))
60
  DEFAULT_OUTPUT_TOKENS = int(os.getenv("OCR_MODEL_MAX_OUTPUT_TOKENS", "2000"))
 
142
  headers = dict(kwargs.pop("default_headers", {}) or {})
143
  headers.update({"cf-aig-authorization": f"Bearer {gateway_token or api_key}", "cf-aig-collect-log": "false", "cf-aig-skip-cache": "true"})
144
  kwargs["default_headers"] = headers
145
+ # The gateway's hostname route was reachable with normal TLS/SNI, while
146
+ # pinning its resolved IPs produced intermittent connect errors from HF.
147
+ # Let HTTPX resolve the official hostname and retry connection setup.
148
+ kwargs.setdefault("http_client", httpx.Client(transport=httpx.HTTPTransport(retries=2), timeout=timeout))
149
+ kwargs.setdefault("http_async_client", httpx.AsyncClient(transport=httpx.AsyncHTTPTransport(retries=2), timeout=timeout))
150
  base_url = f"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat"
151
  else:
152
  kwargs.setdefault("http_client", httpx.Client(transport=CloudflareTransport(_cloudflare_routes), timeout=timeout))