feat: enhance NVIDIA NIM support for Kimi models and fix model ID stripping
This commit is contained in:
parent
8807d8254f
commit
0de60f6933
2 changed files with 27 additions and 1 deletions
|
|
@ -426,6 +426,9 @@ func (c *Config) GetAPIKey() string {
|
||||||
if c.Providers.ShengSuanYun.APIKey != "" {
|
if c.Providers.ShengSuanYun.APIKey != "" {
|
||||||
return c.Providers.ShengSuanYun.APIKey
|
return c.Providers.ShengSuanYun.APIKey
|
||||||
}
|
}
|
||||||
|
if c.Providers.Nvidia.APIKey != "" {
|
||||||
|
return c.Providers.Nvidia.APIKey
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,6 +447,13 @@ func (c *Config) GetAPIBase() string {
|
||||||
if c.Providers.VLLM.APIKey != "" && c.Providers.VLLM.APIBase != "" {
|
if c.Providers.VLLM.APIKey != "" && c.Providers.VLLM.APIBase != "" {
|
||||||
return c.Providers.VLLM.APIBase
|
return c.Providers.VLLM.APIBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Providers.Nvidia.APIKey != "" {
|
||||||
|
if c.Providers.Nvidia.APIBase != "" {
|
||||||
|
return c.Providers.Nvidia.APIBase
|
||||||
|
}
|
||||||
|
return "https://integrate.api.nvidia.com/v1"
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
|
||||||
// Strip provider prefix from model name (e.g., moonshot/kimi-k2.5 -> kimi-k2.5, groq/openai/gpt-oss-120b -> openai/gpt-oss-120b, ollama/qwen2.5:14b -> qwen2.5:14b)
|
// Strip provider prefix from model name (e.g., moonshot/kimi-k2.5 -> kimi-k2.5, groq/openai/gpt-oss-120b -> openai/gpt-oss-120b, ollama/qwen2.5:14b -> qwen2.5:14b)
|
||||||
if idx := strings.Index(model, "/"); idx != -1 {
|
if idx := strings.Index(model, "/"); idx != -1 {
|
||||||
prefix := model[:idx]
|
prefix := model[:idx]
|
||||||
if prefix == "moonshot" || prefix == "nvidia" || prefix == "groq" || prefix == "ollama" {
|
// Don't strip if it's the required namespace for NVIDIA NIM (like moonshotai/)
|
||||||
|
if prefix == "moonshot" || (prefix == "nvidia" && !strings.Contains(model, "moonshotai/")) || prefix == "groq" || prefix == "ollama" {
|
||||||
model = model[idx+1:]
|
model = model[idx+1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -324,6 +325,14 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
|
||||||
model = "deepseek-chat"
|
model = "deepseek-chat"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "nvidia":
|
||||||
|
if cfg.Providers.Nvidia.APIKey != "" {
|
||||||
|
apiKey = cfg.Providers.Nvidia.APIKey
|
||||||
|
apiBase = cfg.Providers.Nvidia.APIBase
|
||||||
|
if apiBase == "" {
|
||||||
|
apiBase = "https://integrate.api.nvidia.com/v1"
|
||||||
|
}
|
||||||
|
}
|
||||||
case "github_copilot", "copilot":
|
case "github_copilot", "copilot":
|
||||||
if cfg.Providers.GitHubCopilot.APIBase != "" {
|
if cfg.Providers.GitHubCopilot.APIBase != "" {
|
||||||
apiBase = cfg.Providers.GitHubCopilot.APIBase
|
apiBase = cfg.Providers.GitHubCopilot.APIBase
|
||||||
|
|
@ -346,6 +355,13 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
|
||||||
if apiBase == "" {
|
if apiBase == "" {
|
||||||
apiBase = "https://api.moonshot.cn/v1"
|
apiBase = "https://api.moonshot.cn/v1"
|
||||||
}
|
}
|
||||||
|
case (strings.Contains(lowerModel, "kimi") || strings.Contains(lowerModel, "k2")) && cfg.Providers.Nvidia.APIKey != "":
|
||||||
|
apiKey = cfg.Providers.Nvidia.APIKey
|
||||||
|
apiBase = cfg.Providers.Nvidia.APIBase
|
||||||
|
proxy = cfg.Providers.Nvidia.Proxy
|
||||||
|
if apiBase == "" {
|
||||||
|
apiBase = "https://integrate.api.nvidia.com/v1"
|
||||||
|
}
|
||||||
|
|
||||||
case strings.HasPrefix(model, "openrouter/") || strings.HasPrefix(model, "anthropic/") || strings.HasPrefix(model, "openai/") || strings.HasPrefix(model, "meta-llama/") || strings.HasPrefix(model, "deepseek/") || strings.HasPrefix(model, "google/"):
|
case strings.HasPrefix(model, "openrouter/") || strings.HasPrefix(model, "anthropic/") || strings.HasPrefix(model, "openai/") || strings.HasPrefix(model, "meta-llama/") || strings.HasPrefix(model, "deepseek/") || strings.HasPrefix(model, "google/"):
|
||||||
apiKey = cfg.Providers.OpenRouter.APIKey
|
apiKey = cfg.Providers.OpenRouter.APIKey
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue