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:
wizardchen
2026-04-14 17:13:16 +08:00
committed by lyingbug
parent 0ce9dc056a
commit 0eff63b308
26 changed files with 808 additions and 541 deletions
+11 -2
View File
@@ -312,7 +312,6 @@ func (c *RemoteAPIChat) Chat(ctx context.Context, messages []Message, opts *Chat
}
c.logRequest(ctx, req, false)
resp, err := c.client.CreateChatCompletion(ctx, req)
if err != nil {
if isMultimodalNotSupportedError(err) {
@@ -342,13 +341,15 @@ func (c *RemoteAPIChat) chatWithRawHTTP(ctx context.Context, endpoint string, cu
return nil, fmt.Errorf("marshal request: %w", err)
}
logger.Infof(ctx, "[LLM Request] model=%s, raw HTTP request:\n%s", c.modelName, secutils.CompactImageDataURLForLog(string(jsonData)))
if endpoint == "" {
endpoint = c.baseURL + "/chat/completions"
}
if err := secutils.ValidateURLForSSRF(endpoint); err != nil {
return nil, fmt.Errorf("endpoint SSRF check failed: %w", err)
}
logger.Infof(ctx, "[LLM Request] Remote HTTP, endpoint=%s, model=%s, raw HTTP request:\n%s",
endpoint, c.modelName, secutils.CompactImageDataURLForLog(string(jsonData)))
httpReq, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewBuffer(jsonData))
if err != nil {
return nil, fmt.Errorf("create request: %w", err)
@@ -366,6 +367,14 @@ func (c *RemoteAPIChat) chatWithRawHTTP(ctx context.Context, endpoint string, cu
httpReq.Header.Set("Authorization", "Bearer "+c.apiKey)
}
// print headers
headers, err := json.Marshal(httpReq.Header)
if err != nil {
return nil, fmt.Errorf("marshal headers: %w", err)
}
logger.Infof(ctx, "[LLM Request] Remote HTTP, endpoint=%s, model=%s, headers: %s",
endpoint, c.modelName, string(headers))
resp, err := rawHTTPClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("send request: %w", err)
+3 -1
View File
@@ -65,6 +65,7 @@ const (
func AllProviders() []ProviderName {
return []ProviderName{
ProviderGeneric,
ProviderWeKnoraCloud,
ProviderAliyun,
ProviderZhipu,
ProviderVolcengine,
@@ -87,7 +88,6 @@ func AllProviders() []ProviderName {
ProviderNvidia,
ProviderNovita,
ProviderAzureOpenAI,
ProviderWeKnoraCloud,
}
}
@@ -259,6 +259,8 @@ func DetectProvider(baseURL string) ProviderName {
return ProviderNvidia
case containsAny(baseURL, "api.novita.ai", "novita.ai"):
return ProviderNovita
case containsAny(baseURL, "weknora.weixin.qq.com"):
return ProviderWeKnoraCloud
default:
return ProviderGeneric
}
+3 -1
View File
@@ -19,16 +19,18 @@ func (p *WeKnoraCloudProvider) Info() ProviderInfo {
return ProviderInfo{
Name: ProviderWeKnoraCloud,
DisplayName: "WeKnoraCloud",
Description: "WeKnoraCloud 平台,提供 Chat / Embedding / Rerank 模型,使用 APPID + API Key 签名认证",
Description: "WeKnora云服务,模型:chat, embedding, rerank, vlm",
DefaultURLs: map[types.ModelType]string{
types.ModelTypeKnowledgeQA: WeKnoraCloudBaseURL,
types.ModelTypeEmbedding: WeKnoraCloudBaseURL,
types.ModelTypeRerank: WeKnoraCloudBaseURL,
types.ModelTypeVLLM: WeKnoraCloudBaseURL,
},
ModelTypes: []types.ModelType{
types.ModelTypeKnowledgeQA,
types.ModelTypeEmbedding,
types.ModelTypeRerank,
types.ModelTypeVLLM,
},
RequiresAuth: true,
}