mirror of
https://github.com/alibaba/higress.git
synced 2026-02-06 23:21:08 +08:00
fix(ai-proxy): restrict the stream_options parameter to be effective only in the openai/v1/chatcompletions (#2524)
Signed-off-by: Xijun Dai <daixijun1990@gmail.com>
This commit is contained in:
@@ -161,7 +161,8 @@ func onHttpRequestBody(ctx wrapper.HttpContext, pluginConfig config.PluginConfig
|
||||
if settingErr != nil {
|
||||
log.Errorf("failed to replace request body by custom settings: %v", settingErr)
|
||||
}
|
||||
if providerConfig.IsOpenAIProtocol() {
|
||||
// 仅 /v1/chat/completions 和 /v1/completions 接口支持 stream_options 参数
|
||||
if providerConfig.IsOpenAIProtocol() && (apiName == provider.ApiNameChatCompletion || apiName == provider.ApiNameCompletion) {
|
||||
newBody = normalizeOpenAiRequestBody(newBody)
|
||||
}
|
||||
log.Debugf("[onHttpRequestBody] newBody=%s", newBody)
|
||||
@@ -315,7 +316,7 @@ func onHttpResponseBody(ctx wrapper.HttpContext, pluginConfig config.PluginConfi
|
||||
func normalizeOpenAiRequestBody(body []byte) []byte {
|
||||
var err error
|
||||
// Default setting include_usage.
|
||||
if gjson.GetBytes(body, "stream").Bool() {
|
||||
if gjson.GetBytes(body, "stream").Bool() && (!gjson.GetBytes(body, "stream_options").Exists() || !gjson.GetBytes(body, "stream_options.include_usage").Exists()) {
|
||||
body, err = sjson.SetBytes(body, "stream_options.include_usage", true)
|
||||
if err != nil {
|
||||
log.Errorf("set include_usage failed, err:%s", err)
|
||||
|
||||
@@ -82,7 +82,7 @@ func (m *doubaoProvider) TransformRequestBody(ctx wrapper.HttpContext, apiName A
|
||||
// 移除火山 responses 接口暂时不支持的参数
|
||||
// 参考: https://www.volcengine.com/docs/82379/1569618
|
||||
// TODO: 这里应该用 DTO 处理
|
||||
for _, param := range []string{"parallel_tool_calls", "tool_choice", "stream_options"} {
|
||||
for _, param := range []string{"parallel_tool_calls", "tool_choice"} {
|
||||
body, err = sjson.DeleteBytes(body, param)
|
||||
if err != nil {
|
||||
log.Warnf("[doubao] failed to delete %s in request body, err: %v", param, err)
|
||||
|
||||
Reference in New Issue
Block a user