mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 14:14:57 +08:00
6bd80cb915
Cache GET /models, merge with config ids for Tab and choose; free-form model ids allowed.
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from plyngent.cli.models_source import (
|
|
client_supports_models,
|
|
config_model_ids,
|
|
fetch_remote_model_ids,
|
|
merge_model_choices,
|
|
model_choices_for_provider,
|
|
)
|
|
from plyngent.config.models import ModelConfig, OpenAICompatibleProvider
|
|
|
|
|
|
def test_merge_model_choices_union() -> None:
|
|
assert merge_model_choices(["b", "a"], ["a", "c"]) == ["a", "b", "c"]
|
|
assert merge_model_choices(["a"], None) == ["a"]
|
|
assert merge_model_choices([], ["z"]) == ["z"]
|
|
|
|
|
|
def test_model_choices_for_provider() -> None:
|
|
provider = OpenAICompatibleProvider(
|
|
access_key_or_token="sk",
|
|
url="https://x/v1",
|
|
models={"cfg": ModelConfig()},
|
|
)
|
|
assert config_model_ids(provider) == ["cfg"]
|
|
assert model_choices_for_provider(provider, remote_ids=["remote", "cfg"]) == ["cfg", "remote"]
|
|
|
|
|
|
def test_client_supports_models() -> None:
|
|
class Ok:
|
|
async def models(self) -> list[str]:
|
|
return ["m"]
|
|
|
|
class No:
|
|
pass
|
|
|
|
assert client_supports_models(Ok())
|
|
assert not client_supports_models(No())
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_fetch_remote_model_ids() -> None:
|
|
class Ok:
|
|
async def models(self) -> list[str]:
|
|
return ["z", "a"]
|
|
|
|
assert await fetch_remote_model_ids(Ok()) == ["z", "a"]
|
|
|
|
with pytest.raises(TypeError, match="does not support"):
|
|
_ = await fetch_remote_model_ids(object())
|