From 3c3c53051d2b817c5c60e92c2b45800c84afb4fa Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Fri, 8 Mar 2024 20:29:04 +0800 Subject: [PATCH] fix: fix gemini --- common/constants.go | 6 +++--- relay/channel/gemini/adaptor.go | 3 +++ relay/common/relay_info.go | 2 +- relay/common/relay_utils.go | 9 --------- relay/relay-audio.go | 2 +- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/common/constants.go b/common/constants.go index f17de2c..16899b3 100644 --- a/common/constants.go +++ b/common/constants.go @@ -238,7 +238,7 @@ var ChannelBaseURLs = []string{ "https://api.aiproxy.io", // 21 "https://fastgpt.run/api/openapi", // 22 "https://hunyuan.cloud.tencent.com", //23 - "", //24 - "https://api.moonshot.cn", //25 - "https://open.bigmodel.cn", //26 + "https://generativelanguage.googleapis.com", //24 + "https://api.moonshot.cn", //25 + "https://open.bigmodel.cn", //26 } diff --git a/relay/channel/gemini/adaptor.go b/relay/channel/gemini/adaptor.go index a613ae2..0943ef0 100644 --- a/relay/channel/gemini/adaptor.go +++ b/relay/channel/gemini/adaptor.go @@ -20,6 +20,9 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo, request dto.GeneralOpenAIReq func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { version := "v1" + if info.ApiVersion != "" { + version = info.ApiVersion + } action := "generateContent" if info.IsStream { action = "streamGenerateContent" diff --git a/relay/common/relay_info.go b/relay/common/relay_info.go index 8051cec..aea3cc7 100644 --- a/relay/common/relay_info.go +++ b/relay/common/relay_info.go @@ -57,7 +57,7 @@ func GenRelayInfo(c *gin.Context) *RelayInfo { info.BaseUrl = common.ChannelBaseURLs[channelType] } if info.ChannelType == common.ChannelTypeAzure { - info.ApiVersion = GetAzureAPIVersion(c) + info.ApiVersion = GetAPIVersion(c) } return info } diff --git a/relay/common/relay_utils.go b/relay/common/relay_utils.go index 3ee2dfa..f89b8b9 100644 --- a/relay/common/relay_utils.go +++ b/relay/common/relay_utils.go @@ -66,12 +66,3 @@ func GetAPIVersion(c *gin.Context) string { } return apiVersion } - -func GetAzureAPIVersion(c *gin.Context) string { - query := c.Request.URL.Query() - apiVersion := query.Get("api-version") - if apiVersion == "" { - apiVersion = c.GetString("api_version") - } - return apiVersion -} diff --git a/relay/relay-audio.go b/relay/relay-audio.go index 3a0841f..5d43e79 100644 --- a/relay/relay-audio.go +++ b/relay/relay-audio.go @@ -113,7 +113,7 @@ func AudioHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode { fullRequestURL := relaycommon.GetFullRequestURL(baseURL, requestURL, channelType) if relayMode == relayconstant.RelayModeAudioTranscription && channelType == common.ChannelTypeAzure { // https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api - apiVersion := relaycommon.GetAzureAPIVersion(c) + apiVersion := relaycommon.GetAPIVersion(c) fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/transcriptions?api-version=%s", baseURL, audioRequest.Model, apiVersion) }