feat: Add model alias resolution and provider-based prefix mapping for LiteLLM#313
feat: Add model alias resolution and provider-based prefix mapping for LiteLLM#313weidonglian wants to merge 5 commits intoHKUDS:mainfrom
Conversation
a8612a2 to
17913b7
Compare
|
Thanks for fixing this! |
But that doesn't fix for example if I am trying to use GLM 4.7 Flash locally with vLLM, it tries to get me to connect to Z.ai API. I think this solution for explicit provider/model structure is better |
|
Actually I'm still not able to use zai even in latest version. |
|
In the latest, it adds a new ProviderConfig to specify more metadata which is a good. The challeging is till to figure out the Provider from |
I can help you improve the PR if you would like, I am heavy investing my efforts on this nanobot repo, I think this is a great approach at agentic AI bots. Hit me up if you need help with this please. |
b416239 to
2afd237
Compare
|
Just based the PR relative to latest main, briefly tested, it seems to be working fine! |
|
Thanks for the PR! I will check this soon. This is important. |
|
Thanks for the PR and the great idea! Model aliases would be really useful. A heads-up: we recently refactored provider prefixing into a central registry ( The cleanest fix would be to check aliases inside Happy to help if you'd like to iterate on this, or I can pick it up from here if you prefer. Either way works — the core idea (alias dict per provider) is solid! 👍 |
|
I can fix and improve as you mentioned to fetch the prefix from provider definition. |
|
I take a look the new changes, I think the ProviderConfig could be passed to LiteLLMProvider - one object contains all provider data and easily figure out for this PR as well, right now: the default model may not be compatible with provider_name and also the provider should be able to figure out the api_key and api_base, it seems to be convoluted. |
|
This should be useful for all providers and models. |
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v5...v6) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary
This PR adds model alias support with automatic provider prefixing. Users can now define short, memorable names for complex model identifiers. The provider prefix is automatically added based on which provider section the alias is configured under - no more guessing from URLs or model names.
The Problem
The old approach had several issues:
z-ai/glm4.7(NVIDIA NIM) failed because "zai" substring incorrectly matched Zhipu providerThe Solution
Automatic provider prefixing based on config structure:
"nvgm": "z-ai/glm4.7"underproviders.vllmresolve_model()detects it's under vllm providerhosted_vllm/prefix →hosted_vllm/z-ai/glm4.7is_resolved=Truetells LiteLLMProvider to skip all prefixing (model already has prefix)Why this works:
Changes
1. Model Alias Configuration (
nanobot/config/schema.py)Added
modelsfield toProviderConfig:Added
resolve_model()that returns resolved model with prefix:2. Simplified Provider Logic (
nanobot/providers/litellm_provider.py)Renamed parameter from
provider_nametois_resolved:Simplified
chat()prefixing logic:3. CLI Integration (
nanobot/cli/commands.py)Updated to use 2-tuple and
is_resolved:4. Documentation (
README.md)Added model aliases documentation with examples.
Usage Example: NVIDIA NIM
Config (prefix added automatically):
{ "providers": { "vllm": { "apiKey": "nvapi-xxx", "apiBase": "https://integrate.api.nvidia.com/v1", "models": { "nvgm": "z-ai/glm4.7", "llama": "meta-llama/Llama-3.1-8B-Instruct", "mistral": "mistralai/Mistral-7B-Instruct-v0.3" } } }, "agents": { "defaults": { "model": "nvgm" } } }Flow:
"model": "nvgm"resolve_model("nvgm")→ found inproviders.vllm.modelshosted_vllm/prefix →"hosted_vllm/z-ai/glm4.7"is_resolved=True→ LiteLLMProvider skips all prefixinghosted_vllm/z-ai/glm4.7More Examples
Example 1: OpenRouter with Business-Friendly Aliases
{ "providers": { "openrouter": { "apiKey": "sk-or-xxx", "models": { "fast": "anthropic/claude-haiku-3.5", "smart": "anthropic/claude-opus-4-5", "code": "openai/gpt-4-turbo" } } }, "agents": { "defaults": { "model": "smart" } } }Flow:
"smart"→resolve_model()→"openrouter/anthropic/claude-opus-4-5"→ ✅Example 2: Multiple Providers
{ "providers": { "vllm": { "apiKey": "nvapi-xxx", "apiBase": "https://integrate.api.nvidia.com/v1", "models": { "nvgm": "z-ai/glm4.7" } }, "openrouter": { "apiKey": "sk-or-xxx", "models": { "best": "anthropic/claude-opus-4-5" } } } }"nvgm"→hosted_vllm/z-ai/glm4.7(from vllm provider)"best"→openrouter/anthropic/claude-opus-4-5(from openrouter provider)Backward Compatibility
✅ 100% Backward Compatible
Example: Direct model (no alias) still works:
{ "providers": { "zhipu": { "apiKey": "xxx" } }, "agents": { "defaults": { "model": "glm4" } } }This continues to work with keyword prefixing →
zai/glm4Files Changed
nanobot/config/schema.py- Addedmodelsfield andresolve_model()methodnanobot/providers/litellm_provider.py- Changed tois_resolvedboolean, simplified prefixingnanobot/cli/commands.py- Updated to use 2-tuple fromresolve_model()README.md- Added model aliases documentationType of Change
Checklist