File size: 5,238 Bytes
4714e0f d29db6e 0d0f0f9 0602b26 4714e0f 79f99c4 3d8524a 79f99c4 4714e0f 79f99c4 3d8524a 79f99c4 4714e0f 79f99c4 4714e0f 0ff89da 4714e0f 0602b26 4714e0f 0602b26 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f 3d8524a 4714e0f 0602b26 79f99c4 0602b26 79f99c4 0602b26 79f99c4 0602b26 79f99c4 0602b26 79f99c4 684eaa9 0602b26 684eaa9 0602b26 684eaa9 0602b26 684eaa9 0602b26 4714e0f 0602b26 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f 1fdea9f 4714e0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | from fastapi.testclient import TestClient
from free_claude_code.application.model_metadata import ProviderModelInfo
from free_claude_code.config.settings import Settings
from tests.api.support import create_test_app, provider_manager_for_app
def _settings(
*,
model: str = "deepseek/deepseek-chat",
model_fable: str | None = None,
model_opus: str | None = "open_router/anthropic/claude-opus",
model_haiku: str | None = "deepseek/deepseek-chat",
) -> Settings:
return Settings.model_construct(
model=model,
model_fable=model_fable,
model_opus=model_opus,
model_sonnet=None,
model_haiku=model_haiku,
anthropic_auth_token="",
deepseek_api_key="deepseek-key",
open_router_api_key="open-router-key",
wafer_api_key="wafer-key",
)
def _cache_models(app, provider_id: str, *model_ids: str) -> None:
provider_manager_for_app(app).cache_model_infos(
provider_id,
{ProviderModelInfo(model_id) for model_id in model_ids},
)
def test_models_list_includes_configured_refs_cached_provider_models_and_aliases():
app = create_test_app(_settings())
_cache_models(app, "deepseek", "deepseek-chat")
_cache_models(
app,
"open_router",
"meta/llama-3.3",
"anthropic/claude-opus",
)
response = TestClient(app).get("/v1/models")
assert response.status_code == 200
data = response.json()
ids = [item["id"] for item in data["data"]]
assert ids[:6] == [
"anthropic/deepseek/deepseek-chat",
"claude-3-freecc-no-thinking/deepseek/deepseek-chat",
"anthropic/open_router/anthropic/claude-opus",
"claude-3-freecc-no-thinking/open_router/anthropic/claude-opus",
"anthropic/open_router/meta/llama-3.3",
"claude-3-freecc-no-thinking/open_router/meta/llama-3.3",
]
assert ids.count("anthropic/deepseek/deepseek-chat") == 1
assert ids.count("anthropic/open_router/anthropic/claude-opus") == 1
display_names = {item["id"]: item["display_name"] for item in data["data"]}
assert (
display_names["anthropic/open_router/meta/llama-3.3"]
== "open_router/meta/llama-3.3"
)
assert (
display_names["claude-3-freecc-no-thinking/open_router/meta/llama-3.3"]
== "open_router/meta/llama-3.3 (no thinking)"
)
assert "claude-sonnet-4-20250514" in ids
assert "claude-fable-5" in ids
assert data["first_id"] == ids[0]
assert data["last_id"] == ids[-1]
assert data["has_more"] is False
def test_models_list_uses_thinking_metadata_for_cached_models():
app = create_test_app(_settings(model_opus=None))
manager = provider_manager_for_app(app)
_cache_models(app, "deepseek", "deepseek-chat")
manager.cache_model_infos(
"open_router",
{
ProviderModelInfo("reasoning-model", supports_thinking=True),
ProviderModelInfo("plain-model", supports_thinking=False),
},
)
response = TestClient(app).get("/v1/models")
assert response.status_code == 200
ids = [item["id"] for item in response.json()["data"]]
assert "anthropic/open_router/reasoning-model" in ids
assert "claude-3-freecc-no-thinking/open_router/reasoning-model" in ids
assert "anthropic/open_router/plain-model" not in ids
assert "claude-3-freecc-no-thinking/open_router/plain-model" in ids
def test_models_list_uses_cached_metadata_for_configured_refs():
app = create_test_app(
_settings(
model="open_router/plain-model",
model_opus=None,
model_haiku=None,
)
)
provider_manager_for_app(app).cache_model_infos(
"open_router",
{ProviderModelInfo("plain-model", supports_thinking=False)},
)
response = TestClient(app).get("/v1/models")
ids = [item["id"] for item in response.json()["data"]]
assert "anthropic/open_router/plain-model" not in ids
assert ids[0] == "claude-3-freecc-no-thinking/open_router/plain-model"
def test_models_list_includes_cached_wafer_models():
app = create_test_app(
_settings(
model="wafer/DeepSeek-V4-Pro",
model_opus=None,
model_haiku=None,
)
)
_cache_models(app, "wafer", "DeepSeek-V4-Pro", "MiniMax-M2.7")
response = TestClient(app).get("/v1/models")
ids = [item["id"] for item in response.json()["data"]]
assert "anthropic/wafer/DeepSeek-V4-Pro" in ids
assert "claude-3-freecc-no-thinking/wafer/DeepSeek-V4-Pro" in ids
assert "anthropic/wafer/MiniMax-M2.7" in ids
assert "claude-3-freecc-no-thinking/wafer/MiniMax-M2.7" in ids
def test_models_list_works_with_empty_discovery_catalog():
app = create_test_app(_settings())
response = TestClient(app).get("/v1/models")
assert response.status_code == 200
ids = [item["id"] for item in response.json()["data"]]
assert ids[:4] == [
"anthropic/deepseek/deepseek-chat",
"claude-3-freecc-no-thinking/deepseek/deepseek-chat",
"anthropic/open_router/anthropic/claude-opus",
"claude-3-freecc-no-thinking/open_router/anthropic/claude-opus",
]
assert "claude-sonnet-4-20250514" in ids
|