INNER CODE UNIT · Python

stream_round

skyportal/skyportal · services/assistant/app.py:175

def stream_round(endpoint, messages, tools, budget):
    """One streamed round from one endpoint, given up on as soon as it falls silent."""
    headers = {"Content-Type": "application/json"}
    if endpoint.get("api_key"):
        headers["Authorization"] = f"Bearer {endpoint['api_key']}"
    payload = chat_payload(endpoint.get("model") or "", messages, tools, THINKING)
    payload["stream"] = True
    deadline = time.monotonic() + budget

    with requests.post(
        f"{endpoint['base_url'].rstrip('/')}/chat/completions",
        headers=headers,
        json=payload,
        stream=True,
        timeout=min(STALL_TIMEOUT, budget),
    ) as response:
        if response.status_code >= 400:
            # The status alone says nothing: a refused request looks identical

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…