feat(lkeap): integrate Tencent Cloud LKEAP Rerank support
- Added support for Tencent Cloud LKEAP Rerank, including new configuration options for SecretId and SecretKey. - Updated frontend components to handle LKEAP-specific fields and enhance user experience with appropriate labels and placeholders. - Enhanced backend logic to manage LKEAP credentials and integrate with the new rerank API. - Improved localization for LKEAP-related terms across multiple languages, ensuring clarity and consistency in user-facing messages. - Introduced tests for LKEAP Reranker functionality to ensure reliability and correctness in handling requests.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/Tencent/WeKnora/internal/models/asr"
|
||||
"github.com/Tencent/WeKnora/internal/models/chat"
|
||||
"github.com/Tencent/WeKnora/internal/models/embedding"
|
||||
"github.com/Tencent/WeKnora/internal/models/provider"
|
||||
"github.com/Tencent/WeKnora/internal/models/rerank"
|
||||
"github.com/Tencent/WeKnora/internal/models/utils/ollama"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
@@ -1537,6 +1538,8 @@ type ModelTestRequest struct {
|
||||
Dimension int `json:"dimension,omitempty"`
|
||||
CustomHeaders map[string]string `json:"customHeaders,omitempty"`
|
||||
ExtraConfig map[string]string `json:"extraConfig,omitempty"`
|
||||
// AppSecret 用于 LKEAP Rerank 等需要第二段密钥的场景(对应模型 Parameters.AppSecret)。
|
||||
AppSecret string `json:"appSecret,omitempty"`
|
||||
// ModelID, when set, instructs the handler to substitute any missing
|
||||
// secrets (APIKey, AppSecret via ExtraConfig) from the stored model
|
||||
// record before assembling the test client. This lets the "Test
|
||||
@@ -1559,10 +1562,7 @@ func (h *InitializationHandler) fillSecretsFromStoredModel(ctx context.Context,
|
||||
if req == nil || req.ModelID == "" {
|
||||
return
|
||||
}
|
||||
if req.APIKey != "" {
|
||||
// Already supplied — nothing to merge. (We don't need to look up
|
||||
// AppSecret separately since the WeKnoraCloud path resolves it
|
||||
// from the tenant, not the model record.)
|
||||
if req.APIKey != "" && req.AppSecret != "" {
|
||||
return
|
||||
}
|
||||
stored, err := h.modelService.GetModelByID(ctx, req.ModelID)
|
||||
@@ -1574,6 +1574,9 @@ func (h *InitializationHandler) fillSecretsFromStoredModel(ctx context.Context,
|
||||
if req.APIKey == "" {
|
||||
req.APIKey = stored.Parameters.APIKey
|
||||
}
|
||||
if req.AppSecret == "" {
|
||||
req.AppSecret = stored.Parameters.AppSecret
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteModelCheckRequest 兼容旧 swagger 定义。
|
||||
@@ -1581,6 +1584,19 @@ func (h *InitializationHandler) fillSecretsFromStoredModel(ctx context.Context,
|
||||
// Deprecated: 保留是为了不破坏已生成的 API 文档,新代码请直接使用 ModelTestRequest。
|
||||
type RemoteModelCheckRequest = ModelTestRequest
|
||||
|
||||
// decryptModelAppSecret 解密模型 Parameters 中的 AppSecret(与 modelService 行为一致)。
|
||||
func decryptModelAppSecret(encrypted string) string {
|
||||
if encrypted == "" {
|
||||
return encrypted
|
||||
}
|
||||
if key := utils.GetAESKey(); key != nil {
|
||||
if plain, err := utils.DecryptAESGCM(encrypted, key); err == nil {
|
||||
return plain
|
||||
}
|
||||
}
|
||||
return encrypted
|
||||
}
|
||||
|
||||
// buildTestModel 把测试连接请求转成一个临时的 *types.Model(不落库),
|
||||
// 供 ConfigFromModel 使用。source 为空时按 defaultSource 兜底(chat/rerank/asr
|
||||
// 默认 remote,embedding 会根据前端传入的 source 决定)。
|
||||
@@ -1598,6 +1614,7 @@ func (h *InitializationHandler) buildTestModel(
|
||||
Parameters: types.ModelParameters{
|
||||
BaseURL: req.BaseURL,
|
||||
APIKey: req.APIKey,
|
||||
AppSecret: req.AppSecret,
|
||||
Provider: req.Provider,
|
||||
InterfaceType: req.InterfaceType,
|
||||
ExtraConfig: req.ExtraConfig,
|
||||
@@ -1896,6 +1913,10 @@ func (h *InitializationHandler) CheckRerankModel(c *gin.Context) {
|
||||
}
|
||||
|
||||
model := h.buildTestModel(&req, types.ModelTypeRerank, types.ModelSourceRemote)
|
||||
if provider.ProviderName(model.Parameters.Provider) == provider.ProviderLKEAP {
|
||||
appID = ""
|
||||
appSecret = decryptModelAppSecret(model.Parameters.AppSecret)
|
||||
}
|
||||
available, message := h.checkRerankModelConnection(ctx, model, appID, appSecret)
|
||||
|
||||
logger.Infof(ctx, "Rerank model check completed, available: %v, message: %s", available, message)
|
||||
|
||||
Reference in New Issue
Block a user