mirror of
https://github.com/alibaba/higress.git
synced 2026-06-10 05:07:30 +08:00
fix(ai-proxy): bedrock support additional request fields (#2480)
This commit is contained in:
@@ -279,11 +279,12 @@ Google Vertex AI 所对应的 type 为 vertex。它特有的配置字段如下
|
|||||||
|
|
||||||
AWS Bedrock 所对应的 type 为 bedrock。它特有的配置字段如下:
|
AWS Bedrock 所对应的 type 为 bedrock。它特有的配置字段如下:
|
||||||
|
|
||||||
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||||
|----------------|--------|------|-----|------------------------------|
|
|---------------------------|--------|------|-----|------------------------------|
|
||||||
| `awsAccessKey` | string | 必填 | - | AWS Access Key,用于身份认证 |
|
| `awsAccessKey` | string | 必填 | - | AWS Access Key,用于身份认证 |
|
||||||
| `awsSecretKey` | string | 必填 | - | AWS Secret Access Key,用于身份认证 |
|
| `awsSecretKey` | string | 必填 | - | AWS Secret Access Key,用于身份认证 |
|
||||||
| `awsRegion` | string | 必填 | - | AWS 区域,例如:us-east-1 |
|
| `awsRegion` | string | 必填 | - | AWS 区域,例如:us-east-1 |
|
||||||
|
| `bedrockAdditionalFields` | map | 非必填 | - | Bedrock 额外模型请求参数 |
|
||||||
|
|
||||||
## 用法示例
|
## 用法示例
|
||||||
|
|
||||||
@@ -1724,6 +1725,8 @@ provider:
|
|||||||
awsAccessKey: "YOUR_AWS_ACCESS_KEY_ID"
|
awsAccessKey: "YOUR_AWS_ACCESS_KEY_ID"
|
||||||
awsSecretKey: "YOUR_AWS_SECRET_ACCESS_KEY"
|
awsSecretKey: "YOUR_AWS_SECRET_ACCESS_KEY"
|
||||||
awsRegion: "YOUR_AWS_REGION"
|
awsRegion: "YOUR_AWS_REGION"
|
||||||
|
bedrockAdditionalFields:
|
||||||
|
top_k: 200
|
||||||
```
|
```
|
||||||
|
|
||||||
**请求示例**
|
**请求示例**
|
||||||
|
|||||||
@@ -224,11 +224,12 @@ For Vertex, the corresponding `type` is `vertex`. Its unique configuration field
|
|||||||
|
|
||||||
For AWS Bedrock, the corresponding `type` is `bedrock`. Its unique configuration field is:
|
For AWS Bedrock, the corresponding `type` is `bedrock`. Its unique configuration field is:
|
||||||
|
|
||||||
| Name | Data Type | Requirement | Default | Description |
|
| Name | Data Type | Requirement | Default | Description |
|
||||||
|----------------|-----------|-------------|---------|-----------------------------------------------|
|
|---------------------------|-----------|-------------|---------|---------------------------------------------------------|
|
||||||
| `awsAccessKey` | string | Required | - | AWS Access Key used for authentication |
|
| `awsAccessKey` | string | Required | - | AWS Access Key used for authentication |
|
||||||
| `awsSecretKey` | string | Required | - | AWS Secret Access Key used for authentication |
|
| `awsSecretKey` | string | Required | - | AWS Secret Access Key used for authentication |
|
||||||
| `awsRegion` | string | Required | - | AWS region, e.g., us-east-1 |
|
| `awsRegion` | string | Required | - | AWS region, e.g., us-east-1 |
|
||||||
|
| `bedrockAdditionalFields` | map | Optional | - | Additional inference parameters that the model supports |
|
||||||
|
|
||||||
## Usage Examples
|
## Usage Examples
|
||||||
|
|
||||||
@@ -1499,6 +1500,8 @@ provider:
|
|||||||
awsAccessKey: "YOUR_AWS_ACCESS_KEY_ID"
|
awsAccessKey: "YOUR_AWS_ACCESS_KEY_ID"
|
||||||
awsSecretKey: "YOUR_AWS_SECRET_ACCESS_KEY"
|
awsSecretKey: "YOUR_AWS_SECRET_ACCESS_KEY"
|
||||||
awsRegion: "YOUR_AWS_REGION"
|
awsRegion: "YOUR_AWS_REGION"
|
||||||
|
bedrockAdditionalFields:
|
||||||
|
top_k: 200
|
||||||
```
|
```
|
||||||
|
|
||||||
**Request Example**
|
**Request Example**
|
||||||
|
|||||||
@@ -733,11 +733,16 @@ func (b *bedrockProvider) buildBedrockTextGenerationRequest(origRequest *chatCom
|
|||||||
Temperature: origRequest.Temperature,
|
Temperature: origRequest.Temperature,
|
||||||
TopP: origRequest.TopP,
|
TopP: origRequest.TopP,
|
||||||
},
|
},
|
||||||
AdditionalModelRequestFields: map[string]interface{}{},
|
AdditionalModelRequestFields: make(map[string]interface{}),
|
||||||
PerformanceConfig: PerformanceConfiguration{
|
PerformanceConfig: PerformanceConfiguration{
|
||||||
Latency: "standard",
|
Latency: "standard",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for key, value := range b.config.bedrockAdditionalFields {
|
||||||
|
request.AdditionalModelRequestFields[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
requestBytes, err := json.Marshal(request)
|
requestBytes, err := json.Marshal(request)
|
||||||
b.setAuthHeaders(requestBytes, headers)
|
b.setAuthHeaders(requestBytes, headers)
|
||||||
return requestBytes, err
|
return requestBytes, err
|
||||||
|
|||||||
@@ -296,6 +296,9 @@ type ProviderConfig struct {
|
|||||||
// @Title zh-CN Amazon Bedrock Region
|
// @Title zh-CN Amazon Bedrock Region
|
||||||
// @Description zh-CN 仅适用于Amazon Bedrock服务访问
|
// @Description zh-CN 仅适用于Amazon Bedrock服务访问
|
||||||
awsRegion string `required:"false" yaml:"awsRegion" json:"awsRegion"`
|
awsRegion string `required:"false" yaml:"awsRegion" json:"awsRegion"`
|
||||||
|
// @Title zh-CN Amazon Bedrock 额外模型请求参数
|
||||||
|
// @Description zh-CN 仅适用于Amazon Bedrock服务,用于设置模型特定的推理参数
|
||||||
|
bedrockAdditionalFields map[string]interface{} `required:"false" yaml:"bedrockAdditionalFields" json:"bedrockAdditionalFields"`
|
||||||
// @Title zh-CN minimax API type
|
// @Title zh-CN minimax API type
|
||||||
// @Description zh-CN 仅适用于 minimax 服务。minimax API 类型,v2 和 pro 中选填一项,默认值为 v2
|
// @Description zh-CN 仅适用于 minimax 服务。minimax API 类型,v2 和 pro 中选填一项,默认值为 v2
|
||||||
minimaxApiType string `required:"false" yaml:"minimaxApiType" json:"minimaxApiType"`
|
minimaxApiType string `required:"false" yaml:"minimaxApiType" json:"minimaxApiType"`
|
||||||
@@ -424,6 +427,12 @@ func (c *ProviderConfig) FromJson(json gjson.Result) {
|
|||||||
c.awsAccessKey = json.Get("awsAccessKey").String()
|
c.awsAccessKey = json.Get("awsAccessKey").String()
|
||||||
c.awsSecretKey = json.Get("awsSecretKey").String()
|
c.awsSecretKey = json.Get("awsSecretKey").String()
|
||||||
c.awsRegion = json.Get("awsRegion").String()
|
c.awsRegion = json.Get("awsRegion").String()
|
||||||
|
if c.typ == providerTypeBedrock {
|
||||||
|
c.bedrockAdditionalFields = make(map[string]interface{})
|
||||||
|
for k, v := range json.Get("bedrockAdditionalFields").Map() {
|
||||||
|
c.bedrockAdditionalFields[k] = v.Value()
|
||||||
|
}
|
||||||
|
}
|
||||||
c.minimaxApiType = json.Get("minimaxApiType").String()
|
c.minimaxApiType = json.Get("minimaxApiType").String()
|
||||||
c.minimaxGroupId = json.Get("minimaxGroupId").String()
|
c.minimaxGroupId = json.Get("minimaxGroupId").String()
|
||||||
c.cloudflareAccountId = json.Get("cloudflareAccountId").String()
|
c.cloudflareAccountId = json.Get("cloudflareAccountId").String()
|
||||||
|
|||||||
Reference in New Issue
Block a user