mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
core/config+cli: empty models are bad; prompt model on provider switch
Reject providers with no models into bad_providers and warn with reasons on chat/providers. When /provider changes and the current model is not listed, prompt for a new model (keep it when still supported).
This commit is contained in:
@@ -6,6 +6,9 @@ url = ":memory:"
|
||||
preset = "openai"
|
||||
access_key_or_token = "sk-1145141919810"
|
||||
|
||||
[providers.test1.models]
|
||||
"gpt-test" = { text = true }
|
||||
|
||||
[providers.test2]
|
||||
preset = "openai-compatible"
|
||||
url = "https://www.example.com/v1"
|
||||
@@ -18,6 +21,9 @@ access_key_or_token = "sk-1145141919810"
|
||||
preset = "anthropic"
|
||||
access_key_or_token = "sk-1145141919810"
|
||||
|
||||
[providers.test3.models]
|
||||
"claude-test" = { text = true }
|
||||
|
||||
[providers.foo1]
|
||||
preset = "deepseek"
|
||||
access_key_or_token = "sk-1145141919810"
|
||||
|
||||
@@ -81,6 +81,23 @@ def test_read_bad_config() -> None:
|
||||
assert isinstance(config.bad_providers, Mapping)
|
||||
|
||||
|
||||
def test_provider_with_empty_models_is_bad(tmp_path: Path) -> None:
|
||||
path = tmp_path / "empty-models.toml"
|
||||
_ = path.write_text(
|
||||
"""
|
||||
[providers.hollow]
|
||||
preset = "openai-compatible"
|
||||
url = "https://example.com/v1"
|
||||
access_key_or_token = "sk-test"
|
||||
models = {}
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
config = plyngent.config.load(path)
|
||||
assert "hollow" not in config.providers
|
||||
assert "hollow" in config.bad_providers
|
||||
|
||||
|
||||
def test_read_invalid_config() -> None:
|
||||
with pytest.raises(ConfigFormatError):
|
||||
_ = plyngent.config.load(Path(__file__).parent / "plyngent-invalid.toml")
|
||||
@@ -91,8 +108,13 @@ def test_write_new_config() -> None:
|
||||
file.unlink(missing_ok=True)
|
||||
config = plyngent.config.load(file)
|
||||
assert isinstance(config.providers, Mapping)
|
||||
from plyngent.config import ModelConfig
|
||||
|
||||
config.providers = {
|
||||
"foo1": OpenAIProvider(access_key_or_token="sk-00301212"),
|
||||
"foo1": OpenAIProvider(
|
||||
access_key_or_token="sk-00301212",
|
||||
models={"gpt-test": ModelConfig()},
|
||||
),
|
||||
"foo2": DeepseekProvider(access_key_or_token="sk-00301212"),
|
||||
}
|
||||
assert isinstance(config.providers, Mapping)
|
||||
|
||||
Reference in New Issue
Block a user