@@ -64,8 +64,8 @@ func geminiRelayHandler(c *gin.Context, info *relaycommon.RelayInfo) *types.NewA
6464func Relay (c * gin.Context , relayFormat types.RelayFormat ) {
6565
6666 requestId := c .GetString (common .RequestIdKey )
67- group := common .GetContextKeyString (c , constant .ContextKeyUsingGroup )
68- originalModel := common .GetContextKeyString (c , constant .ContextKeyOriginalModel )
67+ // group := common.GetContextKeyString(c, constant.ContextKeyUsingGroup)
68+ // originalModel := common.GetContextKeyString(c, constant.ContextKeyOriginalModel)
6969
7070 var (
7171 newAPIError * types.NewAPIError
@@ -158,7 +158,7 @@ func Relay(c *gin.Context, relayFormat types.RelayFormat) {
158158 }()
159159
160160 for i := 0 ; i <= common .RetryTimes ; i ++ {
161- channel , err := getChannel (c , group , originalModel , i )
161+ channel , err := getChannel (c , relayInfo , i )
162162 if err != nil {
163163 logger .LogError (c , err .Error ())
164164 newAPIError = err
@@ -211,7 +211,7 @@ func addUsedChannel(c *gin.Context, channelId int) {
211211 c .Set ("use_channel" , useChannel )
212212}
213213
214- func getChannel (c * gin.Context , group , originalModel string , retryCount int ) (* model.Channel , * types.NewAPIError ) {
214+ func getChannel (c * gin.Context , info * relaycommon. RelayInfo , retryCount int ) (* model.Channel , * types.NewAPIError ) {
215215 if retryCount == 0 {
216216 autoBan := c .GetBool ("auto_ban" )
217217 autoBanInt := 1
@@ -225,14 +225,18 @@ func getChannel(c *gin.Context, group, originalModel string, retryCount int) (*m
225225 AutoBan : & autoBanInt ,
226226 }, nil
227227 }
228- channel , selectGroup , err := service .CacheGetRandomSatisfiedChannel (c , group , originalModel , retryCount )
228+ channel , selectGroup , err := service .CacheGetRandomSatisfiedChannel (c , info .TokenGroup , info .OriginModelName , retryCount )
229+
230+ info .PriceData .GroupRatioInfo = helper .HandleGroupRatio (c , info )
231+
229232 if err != nil {
230- return nil , types .NewError (fmt .Errorf ("获取分组 %s 下模型 %s 的可用渠道失败(retry): %s" , selectGroup , originalModel , err .Error ()), types .ErrorCodeGetChannelFailed , types .ErrOptionWithSkipRetry ())
233+ return nil , types .NewError (fmt .Errorf ("获取分组 %s 下模型 %s 的可用渠道失败(retry): %s" , selectGroup , info . OriginModelName , err .Error ()), types .ErrorCodeGetChannelFailed , types .ErrOptionWithSkipRetry ())
231234 }
232235 if channel == nil {
233- return nil , types .NewError (fmt .Errorf ("分组 %s 下模型 %s 的可用渠道不存在(retry)" , selectGroup , originalModel ), types .ErrorCodeGetChannelFailed , types .ErrOptionWithSkipRetry ())
236+ return nil , types .NewError (fmt .Errorf ("分组 %s 下模型 %s 的可用渠道不存在(retry)" , selectGroup , info . OriginModelName ), types .ErrorCodeGetChannelFailed , types .ErrOptionWithSkipRetry ())
234237 }
235- newAPIError := middleware .SetupContextForSelectedChannel (c , channel , originalModel )
238+
239+ newAPIError := middleware .SetupContextForSelectedChannel (c , channel , info .OriginModelName )
236240 if newAPIError != nil {
237241 return nil , newAPIError
238242 }
@@ -392,8 +396,6 @@ func RelayNotFound(c *gin.Context) {
392396func RelayTask (c * gin.Context ) {
393397 retryTimes := common .RetryTimes
394398 channelId := c .GetInt ("channel_id" )
395- group := c .GetString ("group" )
396- originalModel := c .GetString ("original_model" )
397399 c .Set ("use_channel" , []string {fmt .Sprintf ("%d" , channelId )})
398400 relayInfo , err := relaycommon .GenRelayInfo (c , types .RelayFormatTask , nil , nil )
399401 if err != nil {
@@ -404,7 +406,7 @@ func RelayTask(c *gin.Context) {
404406 retryTimes = 0
405407 }
406408 for i := 0 ; shouldRetryTaskRelay (c , channelId , taskErr , retryTimes ) && i < retryTimes ; i ++ {
407- channel , newAPIError := getChannel (c , group , originalModel , i )
409+ channel , newAPIError := getChannel (c , relayInfo , i )
408410 if newAPIError != nil {
409411 logger .LogError (c , fmt .Sprintf ("CacheGetRandomSatisfiedChannel failed: %s" , newAPIError .Error ()))
410412 taskErr = service .TaskErrorWrapperLocal (newAPIError .Err , "get_channel_failed" , http .StatusInternalServerError )
0 commit comments