From d7e1b2a2318e4f32cdc200ad013c2a94eb16d116 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Sun, 5 Jan 2025 02:42:37 +0000 Subject: [PATCH 1/3] fix: o1 do not support system prompt and max_tokens --- relay/adaptor/openai/adaptor.go | 15 +++++++++++++++ relay/billing/ratio/model.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 6946e402..ede9fc13 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -82,6 +82,21 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G } request.StreamOptions.IncludeUsage = true } + + // o1/o1-mini/o1-preview do not support system prompt and max_tokens + if strings.HasPrefix(request.Model, "o1") { + request.MaxTokens = 0 + request.Messages = func(raw []model.Message) (filtered []model.Message) { + for i := range raw { + if raw[i].Role != "system" { + filtered = append(filtered, raw[i]) + } + } + + return + }(request.Messages) + } + return request, nil } diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index f83aa70c..e7c89ca7 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -466,7 +466,7 @@ func GetCompletionRatio(name string, channelType int) float64 { } return 2 } - // including o1, o1-preview, o1-mini + // including o1/o1-preview/o1-mini if strings.HasPrefix(name, "o1") { return 4 } From 3e17184c1e36135fe951ab302cb9eedd4275fd64 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Sat, 25 Jan 2025 07:20:07 +0000 Subject: [PATCH 2/3] fix: update o1 model handling to include temperature support --- relay/adaptor/openai/adaptor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index ede9fc13..050070c9 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -83,8 +83,10 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G request.StreamOptions.IncludeUsage = true } - // o1/o1-mini/o1-preview do not support system prompt and max_tokens + // o1/o1-mini/o1-preview do not support system prompt/max_tokens/temperature if strings.HasPrefix(request.Model, "o1") { + temperature := float64(1) + 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 { From dabaa795b9f86aa23417737404c4f3a47a9a8fe9 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Fri, 7 Feb 2025 01:36:14 +0000 Subject: [PATCH 3/3] feat: update API version handling for Azure channel in Adaptor --- relay/adaptor/openai/adaptor.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 050070c9..a068ecf2 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -29,16 +29,24 @@ func (a *Adaptor) Init(meta *meta.Meta) { func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) { switch meta.ChannelType { case channeltype.Azure: + defaultVersion := meta.Config.APIVersion + + // https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python#api--feature-support + if strings.HasPrefix(meta.ActualModelName, "o1") || + strings.HasPrefix(meta.ActualModelName, "o3") { + defaultVersion = "2024-12-01-preview" + } + if meta.Mode == relaymode.ImagesGenerations { // https://learn.microsoft.com/en-us/azure/ai-services/openai/dall-e-quickstart?tabs=dalle3%2Ccommand-line&pivots=rest-api // https://{resource_name}.openai.azure.com/openai/deployments/dall-e-3/images/generations?api-version=2024-03-01-preview - fullRequestURL := fmt.Sprintf("%s/openai/deployments/%s/images/generations?api-version=%s", meta.BaseURL, meta.ActualModelName, meta.Config.APIVersion) + fullRequestURL := fmt.Sprintf("%s/openai/deployments/%s/images/generations?api-version=%s", meta.BaseURL, meta.ActualModelName, defaultVersion) return fullRequestURL, nil } // https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=rest-api&tabs=command-line#rest-api requestURL := strings.Split(meta.RequestURLPath, "?")[0] - requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, meta.Config.APIVersion) + requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, defaultVersion) task := strings.TrimPrefix(requestURL, "/v1/") model_ := meta.ActualModelName model_ = strings.Replace(model_, ".", "", -1)