feat: aws client supports proxy settings
Signed-off-by: iwu <iwu@tencent.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/relay/channel/claude"
|
"github.com/QuantumNous/new-api/relay/channel/claude"
|
||||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||||
"github.com/QuantumNous/new-api/relay/helper"
|
"github.com/QuantumNous/new-api/relay/helper"
|
||||||
|
"github.com/QuantumNous/new-api/service"
|
||||||
"github.com/QuantumNous/new-api/types"
|
"github.com/QuantumNous/new-api/types"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -25,6 +26,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func newAwsClient(c *gin.Context, info *relaycommon.RelayInfo) (*bedrockruntime.Client, error) {
|
func newAwsClient(c *gin.Context, info *relaycommon.RelayInfo) (*bedrockruntime.Client, error) {
|
||||||
|
var (
|
||||||
|
httpClient *http.Client
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if info.ChannelSetting.Proxy != "" {
|
||||||
|
httpClient, err = service.NewProxyHttpClient(info.ChannelSetting.Proxy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("new proxy http client failed: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
httpClient = service.GetHttpClient()
|
||||||
|
}
|
||||||
|
|
||||||
awsSecret := strings.Split(info.ApiKey, "|")
|
awsSecret := strings.Split(info.ApiKey, "|")
|
||||||
var client *bedrockruntime.Client
|
var client *bedrockruntime.Client
|
||||||
switch len(awsSecret) {
|
switch len(awsSecret) {
|
||||||
@@ -34,6 +48,7 @@ func newAwsClient(c *gin.Context, info *relaycommon.RelayInfo) (*bedrockruntime.
|
|||||||
client = bedrockruntime.New(bedrockruntime.Options{
|
client = bedrockruntime.New(bedrockruntime.Options{
|
||||||
Region: region,
|
Region: region,
|
||||||
BearerAuthTokenProvider: bearer.StaticTokenProvider{Token: bearer.Token{Value: apiKey}},
|
BearerAuthTokenProvider: bearer.StaticTokenProvider{Token: bearer.Token{Value: apiKey}},
|
||||||
|
HTTPClient: httpClient,
|
||||||
})
|
})
|
||||||
case 3:
|
case 3:
|
||||||
ak := awsSecret[0]
|
ak := awsSecret[0]
|
||||||
@@ -42,6 +57,7 @@ func newAwsClient(c *gin.Context, info *relaycommon.RelayInfo) (*bedrockruntime.
|
|||||||
client = bedrockruntime.New(bedrockruntime.Options{
|
client = bedrockruntime.New(bedrockruntime.Options{
|
||||||
Region: region,
|
Region: region,
|
||||||
Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(ak, sk, "")),
|
Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(ak, sk, "")),
|
||||||
|
HTTPClient: httpClient,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("invalid aws secret key")
|
return nil, errors.New("invalid aws secret key")
|
||||||
|
|||||||
Reference in New Issue
Block a user