feat(weknoracloud): implement credential management and status checks
- Introduced a new WeKnoraCloudSettings component for managing APPID and APPSECRET. - Added functionality to save WeKnoraCloud credentials without automatically creating models. - Implemented credential status checks across various components to provide user feedback on configuration status. - Updated API endpoints to handle credential saving and status retrieval. - Enhanced UI elements to guide users in configuring WeKnoraCloud settings. This update improves the integration of WeKnoraCloud by allowing users to manage their credentials more effectively and receive real-time feedback on their configuration status.
This commit is contained in:
@@ -1508,15 +1508,28 @@ func (h *InitializationHandler) CheckRemoteModel(c *gin.Context) {
|
||||
c.Error(errors.NewBadRequestError(fmt.Sprintf("Base URL 未通过安全校验: %v", err)))
|
||||
return
|
||||
}
|
||||
tenantInfo, ok := types.TenantInfoFromContext(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
c.Error(errors.NewBadRequestError("租户信息未找到"))
|
||||
return
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
}
|
||||
|
||||
// 创建模型配置进行测试
|
||||
modelConfig := &types.Model{
|
||||
Name: req.ModelName,
|
||||
Source: "remote",
|
||||
Parameters: types.ModelParameters{
|
||||
BaseURL: req.BaseURL,
|
||||
APIKey: req.APIKey,
|
||||
Provider: req.Provider,
|
||||
BaseURL: req.BaseURL,
|
||||
APIKey: req.APIKey,
|
||||
Provider: req.Provider,
|
||||
AppID: appID,
|
||||
AppSecret: appSecret,
|
||||
},
|
||||
Type: "llm", // 默认类型,实际检查时不区分具体类型
|
||||
}
|
||||
@@ -1592,6 +1605,17 @@ func (h *InitializationHandler) TestEmbeddingModel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
tenantInfo, ok := types.TenantInfoFromContext(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
c.Error(errors.NewBadRequestError("租户信息未找到"))
|
||||
return
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
}
|
||||
|
||||
// 构造 embedder 配置
|
||||
cfg := embedding.Config{
|
||||
@@ -1603,6 +1627,8 @@ func (h *InitializationHandler) TestEmbeddingModel(c *gin.Context) {
|
||||
Dimensions: req.Dimension,
|
||||
ModelID: "",
|
||||
Provider: req.Provider,
|
||||
AppID: appID,
|
||||
AppSecret: appSecret,
|
||||
}
|
||||
|
||||
emb, err := embedding.NewEmbedder(cfg, h.pooler, h.ollamaService)
|
||||
@@ -1647,6 +1673,8 @@ func (h *InitializationHandler) checkRemoteModelConnection(ctx context.Context,
|
||||
APIKey: model.Parameters.APIKey,
|
||||
ModelID: model.Name,
|
||||
Provider: model.Parameters.Provider,
|
||||
AppID: model.Parameters.AppID,
|
||||
AppSecret: model.Parameters.AppSecret,
|
||||
}
|
||||
|
||||
// 创建聊天实例
|
||||
@@ -1706,6 +1734,18 @@ func (h *InitializationHandler) checkRerankModelConnection(ctx context.Context,
|
||||
ModelName: modelName,
|
||||
Source: types.ModelSourceRemote, // 默认值,实际会根据URL判断
|
||||
}
|
||||
tenantInfo, ok := types.TenantInfoFromContext(ctx)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Tenant info not found")
|
||||
return false, "租户信息未找到"
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
}
|
||||
config.AppID = appID
|
||||
config.AppSecret = appSecret
|
||||
|
||||
// 创建Reranker实例
|
||||
reranker, err := rerank.NewReranker(config)
|
||||
|
||||
@@ -1038,7 +1038,7 @@ func (h *SystemHandler) ResolveDocumentReader(ctx context.Context, addr string)
|
||||
if creds == nil {
|
||||
return nil
|
||||
}
|
||||
reader, err := docparser.NewWeKnoraCloudSignedDocumentReader(addr, creds.AppID, creds.APIKey)
|
||||
reader, err := docparser.NewWeKnoraCloudSignedDocumentReader(creds.AppID, creds.APIKey)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// WeKnoraCloudHandler 处理 WeKnoraCloud 初始化请求
|
||||
// WeKnoraCloudHandler 处理 WeKnoraCloud 凭证管理
|
||||
type WeKnoraCloudHandler struct {
|
||||
svc interfaces.WeKnoraCloudService
|
||||
}
|
||||
@@ -17,26 +17,26 @@ func NewWeKnoraCloudHandler(svc interfaces.WeKnoraCloudService) *WeKnoraCloudHan
|
||||
return &WeKnoraCloudHandler{svc: svc}
|
||||
}
|
||||
|
||||
type initializeWeKnoraCloudRequest struct {
|
||||
type weKnoraCloudCredentialsRequest struct {
|
||||
AppID string `json:"app_id" binding:"required"`
|
||||
AppSecret string `json:"app_secret" binding:"required"`
|
||||
}
|
||||
|
||||
// Initialize POST /api/v1/models/weknoracloud/initialize
|
||||
func (h *WeKnoraCloudHandler) Initialize(c *gin.Context) {
|
||||
var req initializeWeKnoraCloudRequest
|
||||
// SaveCredentials POST /api/v1/weknoracloud/credentials
|
||||
// 仅保存 APPID/APPSECRET 凭证到租户配置,不自动创建模型
|
||||
func (h *WeKnoraCloudHandler) SaveCredentials(c *gin.Context) {
|
||||
var req weKnoraCloudCredentialsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.Initialize(c.Request.Context(), req.AppID, req.AppSecret)
|
||||
if err != nil {
|
||||
if err := h.svc.SaveCredentials(c.Request.Context(), req.AppID, req.AppSecret); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "凭证保存成功"})
|
||||
}
|
||||
|
||||
// Status GET /api/v1/models/weknoracloud/status
|
||||
|
||||
Reference in New Issue
Block a user