adding support for Qwen models and fixed issue with passing PATH vari… (#583)

* adding support for Qwen models and fixed issue with passing PATH variable

* don't need to have qwen in the model alias routing example

* fixed base_url for qwen

---------

Co-authored-by: Salman Paracha <salmanparacha@MacBook-Pro-288.local>
This commit is contained in:
Adil Hafeez 2025-10-02 19:01:57 -07:00
parent fd03a099ef
commit 0bc087c78d
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
6 changed files with 47 additions and 3 deletions

View file

@ -22,6 +22,7 @@ SUPPORTED_PROVIDERS = [
"ollama", "ollama",
"moonshotai", "moonshotai",
"zhipu", "zhipu",
"qwen",
] ]
@ -187,7 +188,7 @@ def validate_and_render_schema():
# Validate azure_openai and ollama provider requires base_url # Validate azure_openai and ollama provider requires base_url
if ( if (
provider == "azure_openai" or provider == "ollama" provider == "azure_openai" or provider == "ollama" or provider == "qwen"
) and model_provider.get("base_url") is None: ) and model_provider.get("base_url") is None:
raise Exception( raise Exception(
f"Provider '{provider}' requires 'base_url' to be set for model {model_name}" f"Provider '{provider}' requires 'base_url' to be set for model {model_name}"

View file

@ -205,6 +205,8 @@ def up(file, path, service, foreground):
"MODEL_SERVER_PORT": os.getenv("MODEL_SERVER_PORT", "51000"), "MODEL_SERVER_PORT": os.getenv("MODEL_SERVER_PORT", "51000"),
} }
env = os.environ.copy() env = os.environ.copy()
# Remove PATH variable if present
env.pop("PATH", None)
# check if access_keys are preesnt in the config file # check if access_keys are preesnt in the config file
access_keys = get_llm_provider_access_keys(arch_config_file=arch_config_file) access_keys = get_llm_provider_access_keys(arch_config_file=arch_config_file)

View file

@ -204,6 +204,8 @@ pub enum LlmProviderType {
Moonshotai, Moonshotai,
#[serde(rename = "zhipu")] #[serde(rename = "zhipu")]
Zhipu, Zhipu,
#[serde(rename = "qwen")]
Qwen,
} }
impl Display for LlmProviderType { impl Display for LlmProviderType {
@ -222,6 +224,7 @@ impl Display for LlmProviderType {
LlmProviderType::Ollama => write!(f, "ollama"), LlmProviderType::Ollama => write!(f, "ollama"),
LlmProviderType::Moonshotai => write!(f, "moonshotai"), LlmProviderType::Moonshotai => write!(f, "moonshotai"),
LlmProviderType::Zhipu => write!(f, "zhipu"), LlmProviderType::Zhipu => write!(f, "zhipu"),
LlmProviderType::Qwen => write!(f, "qwen"),
} }
} }
} }

View file

@ -87,6 +87,13 @@ impl SupportedAPIs {
default_endpoint default_endpoint
} }
} }
ProviderId::Qwen => {
if request_path.starts_with("/v1/") {
"/compatible-mode/v1/chat/completions".to_string()
} else {
default_endpoint
}
}
ProviderId::AzureOpenAI => { ProviderId::AzureOpenAI => {
if request_path.starts_with("/v1/") { if request_path.starts_with("/v1/") {
format!("/openai/deployments/{}/chat/completions?api-version=2025-01-01-preview", model_id) format!("/openai/deployments/{}/chat/completions?api-version=2025-01-01-preview", model_id)

View file

@ -19,6 +19,7 @@ pub enum ProviderId {
Ollama, Ollama,
Moonshotai, Moonshotai,
Zhipu, Zhipu,
Qwen, // alias for Qwen
} }
impl From<&str> for ProviderId { impl From<&str> for ProviderId {
@ -38,6 +39,7 @@ impl From<&str> for ProviderId {
"ollama" => ProviderId::Ollama, "ollama" => ProviderId::Ollama,
"moonshotai" => ProviderId::Moonshotai, "moonshotai" => ProviderId::Moonshotai,
"zhipu" => ProviderId::Zhipu, "zhipu" => ProviderId::Zhipu,
"qwen" => ProviderId::Qwen, // alias for Zhipu
_ => panic!("Unknown provider: {}", value), _ => panic!("Unknown provider: {}", value),
} }
} }
@ -64,7 +66,8 @@ impl ProviderId {
| ProviderId::TogetherAI | ProviderId::TogetherAI
| ProviderId::Ollama | ProviderId::Ollama
| ProviderId::Moonshotai | ProviderId::Moonshotai
| ProviderId::Zhipu, | ProviderId::Zhipu
| ProviderId::Qwen,
SupportedAPIs::AnthropicMessagesAPI(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions), SupportedAPIs::AnthropicMessagesAPI(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
(ProviderId::OpenAI (ProviderId::OpenAI
@ -79,7 +82,8 @@ impl ProviderId {
| ProviderId::TogetherAI | ProviderId::TogetherAI
| ProviderId::Ollama | ProviderId::Ollama
| ProviderId::Moonshotai | ProviderId::Moonshotai
| ProviderId::Zhipu, | ProviderId::Zhipu
| ProviderId::Qwen,
SupportedAPIs::OpenAIChatCompletions(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions), SupportedAPIs::OpenAIChatCompletions(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
} }
} }
@ -102,6 +106,7 @@ impl Display for ProviderId {
ProviderId::Ollama => write!(f, "ollama"), ProviderId::Ollama => write!(f, "ollama"),
ProviderId::Moonshotai => write!(f, "moonshotai"), ProviderId::Moonshotai => write!(f, "moonshotai"),
ProviderId::Zhipu => write!(f, "zhipu"), ProviderId::Zhipu => write!(f, "zhipu"),
ProviderId::Qwen => write!(f, "qwen"),
} }
} }
} }

View file

@ -517,6 +517,32 @@ Azure OpenAI
access_key: $AZURE_OPENAI_API_KEY access_key: $AZURE_OPENAI_API_KEY
base_url: https://your-resource.openai.azure.com base_url: https://your-resource.openai.azure.com
Azure OpenAI
~~~~~~~~~~~~
**Provider Prefix:** ``qwen/``
**API Endpoint:** ``/v1/chat/completions``
**Authentication:** API Key + Base URL - Get your Qwen API key from `Qwen Portal <https://modelstudio.console.alibabacloud.com/>`_ → Your Qwen Resource → Keys and Endpoint.
**Supported Chat Models:** All Qwen chat models including Qwen3, Qwen3-Coder and all future releases.
.. code-block:: yaml
llm_providers:
# Single deployment
- model: qwen/qwen3
access_key: $DASHSCOPE_API_KEY
base_url: https://dashscope.aliyuncs.com
# Multiple deployments
- model: qwen/qwen3-coder
access_key: $DASHSCOPE_API_KEY
base_url: "https://dashscope-intl.aliyuncs.com",
Ollama Ollama
~~~~~~ ~~~~~~