mirror of
https://github.com/YFGaia/dify-plus.git
synced 2026-06-12 18:11:42 +08:00
feat(bedrock): 支持 bedrock_proxy_url 代理配置
从 Dify provider_credentials 的 encrypted_config 中读取 bedrock_proxy_url 字段, 若非空则将 HTTP 请求经该代理(host:port 或 http://host:port)转发到 AWS Bedrock, 不再强制直连 bedrock-runtime.{region}.amazonaws.com。 变更: - ProviderCredentials 新增 BedrockProxyURL 字段 - ConfigKeyBedrockProxyURL 常量 - GetDifyProviderCredentials 提取 bedrock_proxy_url(明文,不解密) - proxyBedrockRequest 根据 BedrockProxyURL 配置 http.Transport.Proxy
This commit is contained in:
@@ -28,6 +28,7 @@ const (
|
||||
ConfigKeyAWSSecretAccessKey = "aws_secret_access_key"
|
||||
ConfigKeyAWSSessionToken = "aws_session_token"
|
||||
ConfigKeyAWSRegion = "aws_region"
|
||||
ConfigKeyBedrockProxyURL = "bedrock_proxy_url" // 可选:HTTP 代理地址,格式 host:port 或 http://host:port
|
||||
)
|
||||
|
||||
// SupportedProviders 列表展示的提供商顺序
|
||||
|
||||
@@ -11,6 +11,8 @@ type ProviderCredentials struct {
|
||||
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
|
||||
AWSSessionToken string `json:"aws_session_token,omitempty"`
|
||||
AWSRegion string `json:"aws_region,omitempty"`
|
||||
// Bedrock 可选代理地址(host:port 或 http://host:port),非空时请求经该代理转发到 AWS
|
||||
BedrockProxyURL string `json:"bedrock_proxy_url,omitempty"`
|
||||
}
|
||||
|
||||
// ModelInfo 模型信息
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -100,9 +101,19 @@ func (s *ModelProviderService) proxyBedrockRequest(
|
||||
return fmt.Errorf("Bedrock SigV4 签名失败:%w", err)
|
||||
}
|
||||
|
||||
// 5) 发起请求
|
||||
// 5) 发起请求(若配置了 bedrock_proxy_url 则经 HTTP 代理转发)
|
||||
startTime := time.Now()
|
||||
client := &http.Client{Timeout: 5 * time.Minute}
|
||||
transport := http.DefaultTransport
|
||||
if creds.BedrockProxyURL != "" {
|
||||
proxyAddr := creds.BedrockProxyURL
|
||||
if !strings.HasPrefix(proxyAddr, "http://") && !strings.HasPrefix(proxyAddr, "https://") {
|
||||
proxyAddr = "http://" + proxyAddr
|
||||
}
|
||||
if proxyURL, parseErr := url.Parse(proxyAddr); parseErr == nil {
|
||||
transport = &http.Transport{Proxy: http.ProxyURL(proxyURL)}
|
||||
}
|
||||
}
|
||||
client := &http.Client{Timeout: 5 * time.Minute, Transport: transport}
|
||||
resp, err := client.Do(httpReq)
|
||||
if err != nil {
|
||||
s.logBedrock(userID, modelID, "error", err.Error(), startTime, 0, 0)
|
||||
@@ -271,3 +282,6 @@ func (s *ModelProviderService) logBedrock(userID, modelID, status, errMsg string
|
||||
global.GVA_LOG.Warn("logBedrock 写日志失败", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user