From bcba9bf3a19754f17c34565dd530abae88e9a8db Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Sun, 26 Jan 2025 08:21:51 +0000 Subject: [PATCH] feat: only allow gpt-audio stream mode when EnforceIncludeUsage is true --- common/config/config.go | 1 + relay/adaptor/openai/adaptor.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index 2eb894ef..a2a74139 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -161,4 +161,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 21966262..e688d5fa 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -97,10 +97,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