From c8a29251ac9ba0e84107975c1e52b58a79749b05 Mon Sep 17 00:00:00 2001 From: iszcz <74706321+iszcz@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:20:24 +0800 Subject: [PATCH] 1 --- relay/channel/openai/adaptor.go | 14 +++++++++----- service/quota.go | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index bb483670..9c4369dc 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -32,11 +32,15 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) { func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { if info.RelayMode == constant.RelayModeRealtime { - // trim https - baseUrl := strings.TrimPrefix(info.BaseUrl, "https://") - baseUrl = strings.TrimPrefix(baseUrl, "http://") - baseUrl = "wss://" + baseUrl - info.BaseUrl = baseUrl + if strings.HasPrefix(info.BaseUrl, "https://") { + baseUrl := strings.TrimPrefix(info.BaseUrl, "https://") + baseUrl = "wss://" + baseUrl + info.BaseUrl = baseUrl + } else if strings.HasPrefix(info.BaseUrl, "http://") { + baseUrl := strings.TrimPrefix(info.BaseUrl, "http://") + baseUrl = "ws://" + baseUrl + info.BaseUrl = baseUrl + } } switch info.ChannelType { case common.ChannelTypeAzure: diff --git a/service/quota.go b/service/quota.go index 70913306..83af772f 100644 --- a/service/quota.go +++ b/service/quota.go @@ -53,7 +53,7 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag return errors.New(fmt.Sprintf("用户额度不足,剩余额度为 %d", userQuota)) } - if token.RemainQuota < quota { + if !token.UnlimitedQuota && token.RemainQuota < quota { return errors.New(fmt.Sprintf("令牌额度不足,剩余额度为 %d", token.RemainQuota)) }