feat: support NVIDIA model API
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// NvidiaChatBaseURL NVIDIA Chat 的默认 BaseURL
|
||||
NvidiaChatBaseURL = "https://integrate.api.nvidia.com/v1"
|
||||
// NvidiaRerankBaseURL NVIDIA Rerank 的默认 BaseURL
|
||||
NvidiaRerankBaseURL = "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking"
|
||||
)
|
||||
|
||||
// NvidiaProvider 实现NVIDIA AI 的 Provider 接口
|
||||
type NvidiaProvider struct{}
|
||||
|
||||
func init() {
|
||||
Register(&NvidiaProvider{})
|
||||
}
|
||||
|
||||
// Info 返回NVIDIA provider 的元数据
|
||||
func (p *NvidiaProvider) Info() ProviderInfo {
|
||||
return ProviderInfo{
|
||||
Name: ProviderNvidia,
|
||||
DisplayName: "NVIDIA",
|
||||
Description: "deepseek-ai-deepseek-v3_1, nv-embed-v1, rerank-qa-mistral-4b, etc.",
|
||||
DefaultURLs: map[types.ModelType]string{
|
||||
types.ModelTypeKnowledgeQA: NvidiaChatBaseURL,
|
||||
types.ModelTypeEmbedding: NvidiaChatBaseURL,
|
||||
types.ModelTypeRerank: NvidiaRerankBaseURL,
|
||||
types.ModelTypeVLLM: NvidiaChatBaseURL,
|
||||
},
|
||||
ModelTypes: []types.ModelType{
|
||||
types.ModelTypeKnowledgeQA,
|
||||
types.ModelTypeEmbedding,
|
||||
types.ModelTypeRerank,
|
||||
types.ModelTypeVLLM,
|
||||
},
|
||||
RequiresAuth: true,
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateConfig 验证NVIDIA provider 配置
|
||||
func (p *NvidiaProvider) ValidateConfig(config *Config) error {
|
||||
if config.APIKey == "" {
|
||||
return fmt.Errorf("API key is required for NVIDIA")
|
||||
}
|
||||
if config.ModelName == "" {
|
||||
return fmt.Errorf("model name is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -53,6 +53,8 @@ const (
|
||||
ProviderLongCat ProviderName = "longcat"
|
||||
// 腾讯云 LKEAP (知识引擎原子能力)
|
||||
ProviderLKEAP ProviderName = "lkeap"
|
||||
// NVIDIA
|
||||
ProviderNvidia ProviderName = "nvidia"
|
||||
)
|
||||
|
||||
// AllProviders 返回所有注册的提供者名称
|
||||
@@ -78,6 +80,7 @@ func AllProviders() []ProviderName {
|
||||
ProviderLongCat,
|
||||
ProviderLKEAP,
|
||||
ProviderGPUStack,
|
||||
ProviderNvidia,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +246,8 @@ func DetectProvider(baseURL string) ProviderName {
|
||||
return ProviderLongCat
|
||||
case containsAny(baseURL, "lkeap.cloud.tencent.com", "api.lkeap"):
|
||||
return ProviderLKEAP
|
||||
case containsAny(baseURL, "nvidia.com"):
|
||||
return ProviderNvidia
|
||||
default:
|
||||
return ProviderGeneric
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ func TestDetectProvider(t *testing.T) {
|
||||
{"https://api.xiaomimimo.com/v1", ProviderMimo},
|
||||
{"https://custom-endpoint.example.com/v1", ProviderGeneric},
|
||||
{"http://localhost:11434/v1", ProviderGeneric},
|
||||
{"https://integrate.api.nvidia.com/v1", ProviderNvidia},
|
||||
{"https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking", ProviderNvidia},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user