import os

index = 0


def get_model_name():
    model_name_env_value = os.getenv("JUDY_MODEL", "")
    if not model_name_env_value:
        raise RuntimeError(
            "Please set env var `JUDY_MODEL` (or create a `.env` file) "
            "to a valid litellm model name, e.g. `openai/gpt-4.1` or `vertex_ai/gemini-3-pro`."
        )
    model_names = model_name_env_value.split(",")

    if len(model_names) > 1:
        # import random
        # model_name = random.choice(model_names)
        global index
        if index >= len(model_names):
            index = index % len(model_names)
        model_name = model_names[index]
        index = index + 1
    else:
        model_name = model_name_env_value

    return model_name
