From fd19798c92efc17b926062d4f1c3ff3890ae7b08 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Mon, 13 May 2024 14:32:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=B8=A0=E9=81=93=E5=87=BA=E9=94=99=20#243?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/channel-test.go | 2 +- controller/model.go | 4 ++-- relay/common/relay_info.go | 2 +- relay/constant/api_type.go | 15 +++++---------- web/src/helpers/render.js | 5 ++--- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index f37f309..7474cb4 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -53,7 +53,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr } meta := relaycommon.GenRelayInfo(c) - apiType := constant.ChannelType2APIType(channel.Type) + apiType, _ := constant.ChannelType2APIType(channel.Type) adaptor := relay.GetAdaptor(apiType) if adaptor == nil { return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil diff --git a/controller/model.go b/controller/model.go index 890b260..c9c50db 100644 --- a/controller/model.go +++ b/controller/model.go @@ -138,8 +138,8 @@ func init() { } channelId2Models = make(map[int][]string) for i := 1; i <= common.ChannelTypeDummy; i++ { - apiType := relayconstant.ChannelType2APIType(i) - if apiType == -1 || apiType == relayconstant.APITypeAIProxyLibrary { + apiType, success := relayconstant.ChannelType2APIType(i) + if !success || apiType == relayconstant.APITypeAIProxyLibrary { continue } meta := &relaycommon.RelayInfo{ChannelType: i} diff --git a/relay/common/relay_info.go b/relay/common/relay_info.go index 7ae9dd4..b40352e 100644 --- a/relay/common/relay_info.go +++ b/relay/common/relay_info.go @@ -38,7 +38,7 @@ func GenRelayInfo(c *gin.Context) *RelayInfo { tokenUnlimited := c.GetBool("token_unlimited_quota") startTime := time.Now() - apiType := constant.ChannelType2APIType(channelType) + apiType, _ := constant.ChannelType2APIType(channelType) info := &RelayInfo{ RelayMode: constant.Path2RelayMode(c.Request.URL.Path), diff --git a/relay/constant/api_type.go b/relay/constant/api_type.go index 1bc8b47..8a1dbd6 100644 --- a/relay/constant/api_type.go +++ b/relay/constant/api_type.go @@ -24,19 +24,11 @@ const ( APITypeDummy // this one is only for count, do not add any channel after this ) -func ChannelType2APIType(channelType int) int { +func ChannelType2APIType(channelType int) (int, bool) { apiType := -1 switch channelType { case common.ChannelTypeOpenAI: apiType = APITypeOpenAI - case common.ChannelTypeAzure: - apiType = APITypeOpenAI - case common.ChannelTypeMoonshot: - apiType = APITypeOpenAI - case common.ChannelTypeLingYiWanWu: - apiType = APITypeOpenAI - case common.ChannelType360: - apiType = APITypeOpenAI case common.ChannelTypeAnthropic: apiType = APITypeAnthropic case common.ChannelTypeBaidu: @@ -66,5 +58,8 @@ func ChannelType2APIType(channelType int) int { case common.ChannelTypeCohere: apiType = APITypeCohere } - return apiType + if apiType == -1 { + return APITypeOpenAI, false + } + return apiType, true } diff --git a/web/src/helpers/render.js b/web/src/helpers/render.js index 9d36682..44bc004 100644 --- a/web/src/helpers/render.js +++ b/web/src/helpers/render.js @@ -1,4 +1,3 @@ -import { Label } from 'semantic-ui-react'; import { Tag } from '@douyinfe/semi-ui'; export function renderText(text, limit) { @@ -152,9 +151,9 @@ export function renderModelPrice( let completionRatioPrice = modelRatio * completionRatio * 0.002 * groupRatio; return ( - '输入:$' + + '输入 $' + inputRatioPrice.toFixed(3) + - '/1K tokens,补全:$' + + '/1K tokens,补全 $' + completionRatioPrice.toFixed(3) + '/1K tokens' );