# 配套文章：06-models-in-applications.md
# 本轮新增示例未执行；环境和运行方式见上级 GUIDE.md。

# 教学候选：通过质量门槛后，才进入这里的能力与成本筛选。
models = [
    {"name": "A", "vision": False, "structured": True, "window": 8000, "cost": 1.0},
    {"name": "B", "vision": True, "structured": True, "window": 16000, "cost": 2.0},
    {"name": "C", "vision": False, "structured": False, "window": 4000, "cost": 0.6},
]

def choose_model(has_image, needs_structure, token_requirements):
    eligible = []
    for model in models:
        if has_image and not model["vision"]:
            continue
        if needs_structure and not model["structured"]:
            continue
        # 不同 Tokenizer 计数不同，因此预算按候选分别提供，并包含输出余量。
        required = token_requirements[model["name"]]
        if required > model["window"]:
            continue
        eligible.append(model)
    # 没有合格候选时明确失败，不偷偷丢掉图片或截断政策来强行调用。
    if not eligible:
        raise ValueError("没有满足本次任务约束的模型")
    return min(eligible, key=lambda model: model["cost"])["name"]

print(choose_model(True, True, {"A": 6000, "B": 6500, "C": 6200}))
