From 69102d141fc342e233e536446030bd26e6fbf267 Mon Sep 17 00:00:00 2001 From: "1808837298@qq.com" <1808837298@qq.com> Date: Sat, 1 Feb 2025 13:41:25 +0800 Subject: [PATCH] feat: add support for o3-mini models in model ratio and request handling --- common/model-ratio.go | 4 +++- relay/channel/openai/adaptor.go | 4 ++-- relay/channel/openai/constant.go | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/model-ratio.go b/common/model-ratio.go index 1970afad..0cfd82b1 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -56,6 +56,8 @@ var defaultModelRatio = map[string]float64{ "o1-preview-2024-09-12": 7.5, "o1-mini": 1.5, "o1-mini-2024-09-12": 1.5, + "o3-mini": 0.55, + "o3-mini-2025-01-31": 0.55, "gpt-4o-mini": 0.075, "gpt-4o-mini-2024-07-18": 0.075, "gpt-4-turbo": 5, // $0.01 / 1K tokens @@ -366,7 +368,7 @@ func GetCompletionRatio(name string) float64 { } return 2 } - if strings.HasPrefix(name, "o1") { + if strings.HasPrefix(name, "o1") || strings.HasPrefix(name, "o3") { return 4 } if name == "chatgpt-4o-latest" { diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index 230ab55c..05ce227f 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -109,13 +109,13 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re if info.ChannelType != common.ChannelTypeOpenAI && info.ChannelType != common.ChannelTypeAzure { request.StreamOptions = nil } - if strings.HasPrefix(request.Model, "o1") { + if strings.HasPrefix(request.Model, "o1") || strings.HasPrefix(request.Model, "o3") { if request.MaxCompletionTokens == 0 && request.MaxTokens != 0 { request.MaxCompletionTokens = request.MaxTokens request.MaxTokens = 0 } } - if request.Model == "o1" || request.Model == "o1-2024-12-17" { + if request.Model == "o1" || request.Model == "o1-2024-12-17" || strings.HasPrefix(request.Model, "o3") { //修改第一个Message的内容,将system改为developer if len(request.Messages) > 0 && request.Messages[0].Role == "system" { request.Messages[0].Role = "developer" diff --git a/relay/channel/openai/constant.go b/relay/channel/openai/constant.go index 342957ee..0e598fd8 100644 --- a/relay/channel/openai/constant.go +++ b/relay/channel/openai/constant.go @@ -13,6 +13,7 @@ var ModelList = []string{ "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12", + "o3-mini", "o3-mini-2025-01-31", "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",