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

This commit is contained in:
Salman Paracha 2025-10-01 17:24:32 -07:00
parent dbeaa51aa7
commit e6ad85f041
7 changed files with 54 additions and 5 deletions

View file

@ -20,6 +20,7 @@ SUPPORTED_PROVIDERS = [
"ollama", "ollama",
"moonshotai", "moonshotai",
"zhipu", "zhipu",
"qwen",
] ]
@ -128,9 +129,9 @@ def validate_and_render_schema():
) )
provider = model_name_tokens[0] provider = model_name_tokens[0]
# Validate azure_openai and ollama provider requires base_url # Validate azure_openai and ollama provider requires base_url
if (provider == "azure_openai" or provider == "ollama") and llm_provider.get( if (
"base_url" provider == "azure_openai" or provider == "ollama" or provider == "qwen"
) is None: ) and llm_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

@ -179,6 +179,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 {
@ -197,6 +199,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

@ -35,6 +35,11 @@ llm_providers:
access_key: $AZURE_API_KEY access_key: $AZURE_API_KEY
base_url: https://katanemo.openai.azure.com base_url: https://katanemo.openai.azure.com
# Azure OpenAI Models
- model: qwen/qwen3-coder-480b-a35b-instruct
access_key: $DASHSCOPE_API_KEY
base_url: https://dashscope-intl.aliyuncs.com
# Ollama Models # Ollama Models
- model: ollama/llama3.1 - model: ollama/llama3.1
base_url: http://host.docker.internal:11434 base_url: http://host.docker.internal:11434

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/compatible-mode
# Multiple deployments
- model: qwen/qwen3-coder
access_key: $DASHSCOPE_API_KEY
base_url: "https://dashscope-intl.aliyuncs.com/compatible-mode",
Ollama Ollama
~~~~~~ ~~~~~~