Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

refa: remove provider-specific Bedrock validation (#20308)

buua4363f1a0a119093
diff --git a/conf/models/xiaomi.json b/conf/models/xiaomi.json
index 538c9b3590..cbf07a4fe5 100644
--- a/conf/models/xiaomi.json
+++ b/conf/models/xiaomi.json
@@ -1,7 +1,8 @@
{
"name": "Xiaomi",
"url": {
- "default": "https://api.xiaomimimo.com/v1"
+ "default": "https://api.xiaomimimo.com/v1",
+ "plan": "https://token-plan-cn.xiaomimimo.com/v1"
},
"url_suffix": {
"chat": "chat/completions",
diff --git a/internal/service/model_service.go b/internal/service/model_service.go
index c801a64857..8b9673b15e 100644
--- a/internal/service/model_service.go
+++ b/internal/service/model_service.go
@@ -560,45 +560,6 @@ type CreateInstanceModelInfo struct {
Extra map[string]interface{} `json:"extra"`
}
-func validateBedrockAPIKeyAuth(providerName, apiKey string) (bool, string, error) {
- if !strings.EqualFold(providerName, "Bedrock") {
- return false, apiKey, nil
- }
- var rawConfig map[string]json.RawMessage
- if json.Unmarshal([]byte(apiKey), &rawConfig) != nil {
- return false, apiKey, nil
- }
- var authMode string
- if json.Unmarshal(rawConfig["auth_mode"], &authMode) != nil || authMode != "bedrock_api_key" {
- return false, apiKey, nil
- }
- var config struct {
- APIKey string `json:"bedrock_api_key"`
- Region string `json:"bedrock_region"`
- }
- if json.Unmarshal([]byte(apiKey), &config) != nil {
- return true, apiKey, errors.New("invalid Bedrock API-key configuration")
- }
- config.APIKey = strings.TrimSpace(config.APIKey)
- if config.APIKey == "" {
- return true, apiKey, errors.New("Bedrock API key must be provided")
- }
- config.Region = strings.TrimSpace(config.Region)
- if config.Region == "" {
- return true, apiKey, errors.New("AWS region must be provided")
- }
- if err := modelModule.ValidateBedrockRegion(config.Region); err != nil {
- return true, apiKey, err
- }
- rawConfig["bedrock_api_key"], _ = json.Marshal(config.APIKey)
- rawConfig["bedrock_region"], _ = json.Marshal(config.Region)
- normalizedAPIKey, err := json.Marshal(rawConfig)
- if err != nil {
- return true, apiKey, errors.New("invalid Bedrock API-key configuration")
- }
- return true, string(normalizedAPIKey), nil
-}
-
func (m *ModelProviderService) getProviderByIDOrName(ctx context.Context, tenantID, providerIDOrName string) (*entity.TenantModelProvider, error) {
provider, err := m.modelProviderDAO.GetByID(ctx, dao.DB, providerIDOrName)
if err == nil && provider.TenantID == tenantID {
@@ -631,26 +592,6 @@ func (m *ModelProviderService) CreateProviderInstance(ctx context.Context, provi
}
providerName := provider.ProviderName
- // Normalize api_key: VLLM with empty api_key defaults to "x".
- // Mirrors Python's _normalize_provider_api_key.
- if strings.EqualFold(providerName, "VLLM") && apiKey == "" {
- apiKey = "x"
- }
-
- bedrockAPIKeyAuth, apiKey, err := validateBedrockAPIKeyAuth(providerName, apiKey)
- if err != nil {
- return common.CodeBadRequest, err
- }
- if bedrockAPIKeyAuth {
- if len(modelInfo) == 0 {
- return common.CodeBadRequest, errors.New("at least one Bedrock model must be selected")
- }
- for _, model := range modelInfo {
- if strings.TrimSpace(model.ModelName) == "" {
- return common.CodeBadRequest, errors.New("Bedrock model name must be provided")
- }
- }
- }
instanceID := utility.GenerateToken()
extra := make(map[string]string)
@@ -679,7 +620,7 @@ func (m *ModelProviderService) CreateProviderInstance(ctx context.Context, provi
// (TenantModelInstanceDAO.Create owns its own transaction), so a failure
// here has to be undone explicitly or the tenant keeps a half-populated
// instance and can no longer reuse the instance name.
- if err = m.addModelsToNewInstance(ctx, tenantID, providerName, instanceName, region, modelInfo, bedrockAPIKeyAuth); err != nil {
+ if err = m.addModelsToNewInstance(ctx, tenantID, providerName, instanceName, region, modelInfo); err != nil {
if rollbackErr := m.rollbackCreatedInstance(ctx, instanceID); rollbackErr != nil {
common.Logger.Error("failed to roll back model instance after model creation failure",
zap.String("instance_id", instanceID), zap.Error(rollbackErr))
@@ -692,7 +633,7 @@ func (m *ModelProviderService) CreateProviderInstance(ctx context.Context, provi
// addModelsToNewInstance creates the models of a freshly created provider
// instance, either the requested ones or the provider's factory defaults.
-func (m *ModelProviderService) addModelsToNewInstance(ctx context.Context, tenantID, providerName, instanceName, region string, modelInfo []CreateInstanceModelInfo, bedrockAPIKeyAuth bool) error {
+func (m *ModelProviderService) addModelsToNewInstance(ctx context.Context, tenantID, providerName, instanceName, region string, modelInfo []CreateInstanceModelInfo) error {
if len(modelInfo) > 0 {
for _, model := range modelInfo {
if err := m.addModelToInstance(ctx, tenantID, providerName, instanceName, model); err != nil {
@@ -701,9 +642,6 @@ func (m *ModelProviderService) addModelsToNewInstance(ctx context.Context, tenan
}
return nil
}
- if bedrockAPIKeyAuth {
- return nil
- }
// model_info not provided — add all factory default models.
// Mirrors Python's create_provider_instance
// (api/apps/services/provider_api_service.py:506-531).
@@ -2068,15 +2006,6 @@ func (m *ModelProviderService) AlterProviderInstance(ctx context.Context, userID
return common.CodeNotFound, fmt.Errorf("no instance found for provider '%s' and instance '%s'", providerName, instanceIDOrName)
}
- // Normalize api_key: VLLM with empty api_key defaults to "x".
- if strings.EqualFold(providerName, "vllm") && apiKey == "" {
- apiKey = "x"
- }
-
- _, apiKey, err = validateBedrockAPIKeyAuth(providerName, apiKey)
- if err != nil {
- return common.CodeBadRequest, err
- }
// Update instance record.
instanceUpdates := map[string]interface{}{
"api_key": apiKey,
diff --git a/internal/service/model_service_test.go b/internal/service/model_service_test.go
index 1227fa6437..f5b89b058e 100644
--- a/internal/service/model_service_test.go
+++ b/internal/service/model_service_test.go
@@ -2,7 +2,6 @@ package service
import (
"context"
- "encoding/json"
"errors"
"strings"
"testing"
@@ -38,51 +37,6 @@ func (d *remoteModelProbeDriver) CheckConnection(context.Context, *modelModule.A
return d.checkErr
}
-func TestValidateBedrockAPIKeyAuth(t *testing.T) {
- tests := []struct {
- name string
- apiKey string
- wantErr string
- }{
- {
- name: "rejects non-string API key",
- apiKey: `{"auth_mode":"bedrock_api_key","bedrock_api_key":[],"bedrock_region":"us-east-1"}`,
- wantErr: "invalid Bedrock API-key configuration",
- },
- {
- name: "rejects invalid region",
- apiKey: `{"auth_mode":"bedrock_api_key","bedrock_api_key":"test-key","bedrock_region":"us east 1"}`,
- wantErr: "invalid region",
- },
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- authenticated, _, err := validateBedrockAPIKeyAuth("Bedrock", test.apiKey)
- if !authenticated || err == nil || !strings.Contains(err.Error(), test.wantErr) {
- t.Fatalf("validateBedrockAPIKeyAuth() = (%v, %v), want API-key mode error containing %q", authenticated, err, test.wantErr)
- }
- })
- }
-
- nonAPIKey := `{"auth_mode":"access_key_secret","bedrock_region":"us-east-1"}`
- authenticated, normalized, err := validateBedrockAPIKeyAuth("Bedrock", nonAPIKey)
- if authenticated || err != nil || normalized != nonAPIKey {
- t.Fatalf("non-API-key mode = (%v, %q, %v), want unchanged", authenticated, normalized, err)
- }
-
- authenticated, normalized, err = validateBedrockAPIKeyAuth("Bedrock", `{"auth_mode":"bedrock_api_key","bedrock_api_key":" test-key ","bedrock_region":" us-east-1 ","custom":"value"}`)
- if !authenticated || err != nil {
- t.Fatalf("valid API-key mode = (%v, %v), want success", authenticated, err)
- }
- var config map[string]string
- if err = json.Unmarshal([]byte(normalized), &config); err != nil {
- t.Fatalf("decode normalized API key: %v", err)
- }
- if config["bedrock_api_key"] != "test-key" || config["bedrock_region"] != "us-east-1" || config["custom"] != "value" {
- t.Fatalf("normalized API key = %#v", config)
- }
-}
-
func TestMonkeyOCRv2EnvConfig(t *testing.T) {
t.Setenv(common.EnvMonkeyOCRv2ServerURL, "http://monkeyocrv2:8000")
t.Setenv(common.EnvMonkeyOCRv2Timeout, "120")
@@ -420,40 +374,6 @@ func TestBedrockAPIKeyInstancePersistsDiscoveredModelsWithoutRuntimeVerification
t.Fatalf("CheckConnection calls after alter = %d, want 0", probe.checkCalls)
}
- code, err = NewModelProviderService().CreateProviderInstance(
- t.Context(),
- "Bedrock",
- "empty-api-key-instance",
- apiKey,
- "",
- "default",
- "user-1",
- nil,
- )
- if code != common.CodeBadRequest || err == nil {
- t.Fatalf("empty model list returned (%v, %v), want bad request", code, err)
- }
-
- code, err = NewModelProviderService().CreateProviderInstance(
- t.Context(),
- "Bedrock",
- "empty-model-name-instance",
- apiKey,
- "",
- "default",
- "user-1",
- []CreateInstanceModelInfo{{}},
- )
- if code != common.CodeBadRequest || err == nil {
- t.Fatalf("empty model name returned (%v, %v), want bad request", code, err)
- }
- var instanceCount int64
- if err = db.Model(&entity.TenantModelInstance{}).Where("instance_name = ?", "empty-model-name-instance").Count(&instanceCount).Error; err != nil {
- t.Fatalf("count instances: %v", err)
- }
- if instanceCount != 0 {
- t.Fatalf("empty model name created %d instances, want 0", instanceCount)
- }
}
func TestCreateProviderInstanceRollsBackInstanceWhenModelCreationFails(t *testing.T) {