This commit is contained in:
2026-07-19 18:57:43 +02:00
parent 48bb6c2ec2
commit c53e2a3319
179 changed files with 9307 additions and 897 deletions
+15 -2
View File
@@ -5,6 +5,8 @@ from __future__ import annotations
import logging
import time
import httpx
from devplacepy import stealth
from devplacepy.config import INTERNAL_GATEWAY_URL, INTERNAL_MODEL
@@ -13,6 +15,15 @@ logger = logging.getLogger(__name__)
CHAT_TIMEOUT_SECONDS = 120.0
DEFAULT_MAX_TOKENS = 1200
_gateway_client: httpx.AsyncClient | None = None
def gateway_client() -> httpx.AsyncClient:
global _gateway_client
if _gateway_client is None or _gateway_client.is_closed:
_gateway_client = stealth.stealth_async_client(timeout=CHAT_TIMEOUT_SECONDS)
return _gateway_client
async def request_completion(
messages: list[dict],
@@ -33,10 +44,12 @@ async def request_completion(
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"X-App-Reference": "devplace-deepsearch-v-1-0-0",
}
start: float = time.monotonic()
async with stealth.stealth_async_client(timeout=timeout) as client:
response = await client.post(gateway_url, json=payload, headers=headers)
response = await gateway_client().post(
gateway_url, json=payload, headers=headers, timeout=timeout
)
elapsed_ms: int = int((time.monotonic() - start) * 1000)
if response.status_code >= 400:
raise RuntimeError(f"chat gateway returned {response.status_code}")