From b843bb8286d591b7ac2eb2bab98419e2171f9cbd Mon Sep 17 00:00:00 2001 From: CaIon Date: Fri, 8 Aug 2025 10:43:07 +0800 Subject: [PATCH] feat: add support for gpt-5 models and adjust temperature settings - Updated the model list to include various gpt-5 variants. - Enhanced the ConvertOpenAIRequest function to handle gpt-5 model temperature settings based on specific model prefixes. - Adjusted default cache and model ratios for new gpt-5 models. --- relay/channel/openai/adaptor.go | 13 +++++++++++-- relay/channel/openai/constant.go | 3 +++ setting/ratio_setting/cache_ratio.go | 10 ++++++++++ setting/ratio_setting/model_ratio.go | 7 +++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index 4d99a76c..01a5fa97 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -206,12 +206,21 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn } } } - if strings.HasPrefix(request.Model, "o") { + if strings.HasPrefix(request.Model, "o") || strings.HasPrefix(request.Model, "gpt-5") { if request.MaxCompletionTokens == 0 && request.MaxTokens != 0 { request.MaxCompletionTokens = request.MaxTokens request.MaxTokens = 0 } - request.Temperature = nil + + if strings.HasPrefix(request.Model, "o") { + request.Temperature = nil + } + + if strings.HasPrefix(request.Model, "gpt-5") { + if request.Model != "gpt-5-chat-latest" { + request.Temperature = nil + } + } // 转换模型推理力度后缀 effort, originModel := parseReasoningEffortFromModelSuffix(request.Model) diff --git a/relay/channel/openai/constant.go b/relay/channel/openai/constant.go index c703e414..85a8ed17 100644 --- a/relay/channel/openai/constant.go +++ b/relay/channel/openai/constant.go @@ -18,6 +18,9 @@ var ModelList = []string{ "o3-mini-high", "o3-mini-2025-01-31-high", "o3-mini-low", "o3-mini-2025-01-31-low", "o3-mini-medium", "o3-mini-2025-01-31-medium", + "gpt-5", "gpt-5-2025-08-07", "gpt-5-chat-latest", + "gpt-5-mini", "gpt-5-mini-2025-08-07", + "gpt-5-nano", "gpt-5-nano-2025-08-07", "o1", "o1-2024-12-17", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-realtime-preview", "gpt-4o-realtime-preview-2024-10-01", "gpt-4o-realtime-preview-2024-12-17", diff --git a/setting/ratio_setting/cache_ratio.go b/setting/ratio_setting/cache_ratio.go index 8b87cb86..3f223bc3 100644 --- a/setting/ratio_setting/cache_ratio.go +++ b/setting/ratio_setting/cache_ratio.go @@ -25,6 +25,16 @@ var defaultCacheRatio = map[string]float64{ "gpt-4o-mini-realtime-preview": 0.5, "gpt-4.5-preview": 0.5, "gpt-4.5-preview-2025-02-27": 0.5, + "gpt-4.1": 0.25, + "gpt-4.1-mini": 0.25, + "gpt-4.1-nano": 0.25, + "gpt-5": 0.1, + "gpt-5-2025-08-07": 0.1, + "gpt-5-chat-latest": 0.1, + "gpt-5-mini": 0.1, + "gpt-5-mini-2025-08-07": 0.1, + "gpt-5-nano": 0.1, + "gpt-5-nano-2025-08-07": 0.1, "deepseek-chat": 0.25, "deepseek-reasoner": 0.25, "deepseek-coder": 0.25, diff --git a/setting/ratio_setting/model_ratio.go b/setting/ratio_setting/model_ratio.go index c9a9521f..4a19895e 100644 --- a/setting/ratio_setting/model_ratio.go +++ b/setting/ratio_setting/model_ratio.go @@ -73,6 +73,13 @@ var defaultModelRatio = map[string]float64{ "gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens "gpt-4.5-preview": 37.5, "gpt-4.5-preview-2025-02-27": 37.5, + "gpt-5": 0.625, + "gpt-5-2025-08-07": 0.625, + "gpt-5-chat-latest": 0.625, + "gpt-5-mini": 0.125, + "gpt-5-mini-2025-08-07": 0.125, + "gpt-5-nano": 0.025, + "gpt-5-nano-2025-08-07": 0.025, //"gpt-3.5-turbo-0301": 0.75, //deprecated "gpt-3.5-turbo": 0.25, "gpt-3.5-turbo-0613": 0.75,