diff --git a/common/config/config.go b/common/config/config.go index a9e56b07..e98a1129 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -176,4 +176,5 @@ var RelayProxy = env.String("RELAY_PROXY", "") var UserContentRequestProxy = env.String("USER_CONTENT_REQUEST_PROXY", "") var UserContentRequestTimeout = env.Int("USER_CONTENT_REQUEST_TIMEOUT", 30) +// EnforceIncludeUsage is used to determine whether to include usage in the response var EnforceIncludeUsage = env.Bool("ENFORCE_INCLUDE_USAGE", false) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index ea001bee..68bdaeaf 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -91,7 +91,6 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G request.Temperature = &temperature // Only the default (1) value is supported request.MaxTokens = 0 - request.Messages = func(raw []model.Message) (filtered []model.Message) { for i := range raw { if raw[i].Role != "system" { @@ -103,10 +102,10 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G }(request.Messages) } - if request.Stream && strings.HasPrefix(request.Model, "gpt-4o-audio") { + if request.Stream && strings.HasPrefix(request.Model, "gpt-4o-audio") && !config.EnforceIncludeUsage { // TODO: Since it is not clear how to implement billing in stream mode, // it is temporarily not supported - return nil, errors.New("stream mode is not supported for gpt-4o-audio") + return nil, errors.New("set ENFORCE_INCLUDE_USAGE=true to enable stream mode for gpt-4o-audio") } return request, nil