diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-09 14:06:01 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-09 14:06:01 +0200 |
| commit | 7246d07dda18c07278cc9df122071f523f697be3 (patch) | |
| tree | ec064c38383e76dde34e905a4f0c81e4d6216d57 /test_llamachat.py | |
| parent | 573c04262e814ac1d72c56487ac95300758af8e8 (diff) | |
| download | llamachat-7246d07dda18c07278cc9df122071f523f697be3.tar.gz llamachat-7246d07dda18c07278cc9df122071f523f697be3.zip | |
feat: parse provider definitions from config
Providers come from a [providers.*] table. A bare top-level base_url
synthesizes the local provider so existing configs keep working, and an
explicit [providers.local] wins over it. Unset numbers stay None so
'unknown' never collapses into zero.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'test_llamachat.py')
| -rwxr-xr-x | test_llamachat.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py index a06d737..6a5c0e6 100755 --- a/test_llamachat.py +++ b/test_llamachat.py @@ -905,6 +905,62 @@ def test_config_defaults(): print("ok config defaults") +def test_provider_parsing(): + """Providers come from [providers.*]; a bare base_url synthesizes local.""" + from llamachat import providers + + # A modern config with two providers. + parsed = providers.parse( + { + "providers": { + "local": {"base_url": "http://localhost:8181/"}, + "together": { + "base_url": "https://api.example.org", + "api_key": "env:TEST_KEY_NAME", + "filter": ["qwen", "deepseek"], + "ctx_size": 32768, + "price_in": 0.6, + "price_out": 0.9, + }, + } + } + ) + assert set(parsed) == {"local", "together"} + # Trailing slashes are stripped so URL joining stays predictable. + assert parsed["local"].base_url == "http://localhost:8181" + assert parsed["local"].api_key == "" + assert parsed["together"].filter == ["qwen", "deepseek"] + assert parsed["together"].ctx_size == 32768 + assert parsed["together"].price_in == 0.6 + assert parsed["together"].price_out == 0.9 + + # An old config: bare base_url, no providers table at all. + legacy = providers.parse({"base_url": "http://localhost:8181"}) + assert set(legacy) == {"local"} + assert legacy["local"].base_url == "http://localhost:8181" + + # Both present: the explicit entry wins over the bare key. + both = providers.parse( + { + "base_url": "http://ignored.example.org", + "providers": {"local": {"base_url": "http://explicit.example.org"}}, + } + ) + assert both["local"].base_url == "http://explicit.example.org" + + # A provider with no base_url is skipped rather than half-configured. + broken = providers.parse( + {"providers": {"local": {"base_url": "http://x.example.org"}, + "bad": {"api_key": "literal"}}} + ) + assert set(broken) == {"local"} + + # Unset numbers stay None so "unknown" is distinguishable from zero. + assert parsed["local"].ctx_size is None + assert parsed["local"].price_in is None + print("ok provider config parsing") + + class _FakeResponse: """Enough of an http.client response for urlopen's context manager.""" @@ -1642,6 +1698,7 @@ if __name__ == "__main__": test_version_matches_changelog() test_venv_discovery() test_config_defaults() + test_provider_parsing() test_search_tool_schema() test_search_results_sanitising() test_tool_call_accumulation() |
