INNER CODE UNIT · Python

chat

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

def chat(messages, tools, timeout=None):
    """One chat-completions round, moved to the other endpoint if the first fails."""
    global _main_skipped_until
    deadline = time.monotonic() + (timeout or TIMEOUT)

    last: Exception | None = None
    for endpoint in endpoints():
        if (left := remaining(deadline, floor=1.0)) is None:
            break
        try:
            return stream_round(endpoint, messages, tools, left)
        except requests.exceptions.HTTPError as exc:
            if exc.response.status_code < 500 and exc.response.status_code != 429:
                raise
            last = exc
        except SWITCH_ERRORS as exc:
            last = exc
        log(f"model at {endpoint['base_url']} failed: {last}")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…