"vscode:/vscode.git/clone" did not exist on "2a622d704a4270c8d6fab057e8a545ed86ac35b7"
utils.py 831 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# SPDX-License-Identifier: Apache-2.0
from openai import APIConnectionError, OpenAI
from openai.pagination import SyncPage
from openai.types.model import Model


def get_first_model(client: OpenAI) -> str:
    """
    Get the first model from the vLLM server.
    """
    try:
        models: SyncPage[Model] = client.models.list()
    except APIConnectionError as e:
        raise RuntimeError(
            "Failed to get the list of models from the vLLM server at "
            f"{client.base_url} with API key {client.api_key}. Check\n"
            "1. the server is running\n"
            "2. the server URL is correct\n"
19
20
            "3. the API key is correct"
        ) from e
21
22

    if len(models.data) == 0:
23
        raise RuntimeError(f"No models found on the vLLM server at {client.base_url}")
24
25

    return models.data[0].id