@@ -166,7 +166,7 @@ func ChatForOpenAI(c *gin.Context) {
166166 return
167167 }
168168
169- sendChannelId , calledCozeBotId , isNewChannel , err := getSendChannelIdAndCozeBotId (c , request .ChannelId , request .Model , true )
169+ sendChannelId , calledCozeBotId , maxToken , isNewChannel , err := getSendChannelIdAndCozeBotId (c , request .ChannelId , request .Model , true )
170170
171171 if err != nil {
172172 response := model.OpenAIErrorResponse {
@@ -275,7 +275,7 @@ loop:
275275 content = string (jsonData )
276276 }
277277
278- sentMsg , userAuth , err := discord .SendMessage (c , sendChannelId , calledCozeBotId , content )
278+ sentMsg , userAuth , err := discord .SendMessage (c , sendChannelId , calledCozeBotId , content , maxToken )
279279 if err != nil {
280280 c .JSON (http .StatusInternalServerError , model.OpenAIErrorResponse {
281281 OpenAIError : model.OpenAIError {
@@ -517,7 +517,7 @@ func ImagesForOpenAI(c *gin.Context) {
517517 return
518518 }
519519
520- sendChannelId , calledCozeBotId , isNewChannel , err := getSendChannelIdAndCozeBotId (c , request .ChannelId , request .Model , true )
520+ sendChannelId , calledCozeBotId , maxToken , isNewChannel , err := getSendChannelIdAndCozeBotId (c , request .ChannelId , request .Model , true )
521521 if err != nil {
522522 common .LogError (c .Request .Context (), err .Error ())
523523 c .JSON (http .StatusInternalServerError , model.OpenAIErrorResponse {
@@ -547,7 +547,7 @@ func ImagesForOpenAI(c *gin.Context) {
547547 }()
548548 }
549549
550- sentMsg , userAuth , err := discord .SendMessage (c , sendChannelId , calledCozeBotId , common .ImgGeneratePrompt + request .Prompt )
550+ sentMsg , userAuth , err := discord .SendMessage (c , sendChannelId , calledCozeBotId , common .ImgGeneratePrompt + request .Prompt , maxToken )
551551 if err != nil {
552552 c .JSON (http .StatusInternalServerError , model.OpenAIErrorResponse {
553553 OpenAIError : model.OpenAIError {
@@ -651,7 +651,7 @@ func ImagesForOpenAI(c *gin.Context) {
651651
652652}
653653
654- func getSendChannelIdAndCozeBotId (c * gin.Context , channelId * string , model string , isOpenAIAPI bool ) (sendChannelId string , calledCozeBotId string , isNewChannel bool , err error ) {
654+ func getSendChannelIdAndCozeBotId (c * gin.Context , channelId * string , model string , isOpenAIAPI bool ) (sendChannelId string , calledCozeBotId string , maxToken string , isNewChannel bool , err error ) {
655655 secret := ""
656656 if isOpenAIAPI {
657657 if secret = c .Request .Header .Get ("Authorization" ); secret != "" {
@@ -669,50 +669,50 @@ func getSendChannelIdAndCozeBotId(c *gin.Context, channelId *string, model strin
669669 // 有值则随机一个
670670 botConfig , err := common .RandomElement (botConfigs )
671671 if err != nil {
672- return "" , "" , false , err
672+ return "" , "" , "" , false , err
673673 }
674674
675675 if channelId != nil && * channelId != "" {
676- return * channelId , botConfig .CozeBotId , false , nil
676+ return * channelId , botConfig .CozeBotId , discord . MessageMaxToken , false , nil
677677 }
678678
679679 if discord .DefaultChannelEnable == "1" {
680- return botConfig .ChannelId , botConfig .CozeBotId , false , nil
680+ return botConfig .ChannelId , botConfig .CozeBotId , botConfig . MessageMaxToken , false , nil
681681 } else {
682682 var sendChannelId string
683683 sendChannelId , err := discord .CreateChannelWithRetry (c , discord .GuildId , fmt .Sprintf ("cdp-chat-%s" , c .Request .Context ().Value (common .RequestIdKey )), 0 )
684684 if err != nil {
685685 common .LogError (c , err .Error ())
686- return "" , "" , false , err
686+ return "" , "" , "" , false , err
687687 }
688- return sendChannelId , botConfig .CozeBotId , true , nil
688+ return sendChannelId , botConfig .CozeBotId , botConfig . MessageMaxToken , true , nil
689689 }
690690
691691 }
692692 // 没有值抛出异常
693- return "" , "" , false , & myerr.ModelNotFoundError {
693+ return "" , "" , "" , false , & myerr.ModelNotFoundError {
694694 ErrCode : 500 ,
695695 Message : fmt .Sprintf ("[proxy-secret:%s]+[model:%s]未匹配到有效bot" , secret , model ),
696696 }
697697 } else {
698698
699699 if discord .BotConfigExist || discord .CozeBotId == "" {
700- return "" , "" , false , myerr .ErrNoBotId
700+ return "" , "" , "" , false , myerr .ErrNoBotId
701701 }
702702
703703 if channelId != nil && * channelId != "" {
704- return * channelId , discord .CozeBotId , false , nil
704+ return * channelId , discord .CozeBotId , discord . MessageMaxToken , false , nil
705705 }
706706
707707 if discord .DefaultChannelEnable == "1" {
708- return discord .ChannelId , discord .CozeBotId , false , nil
708+ return discord .ChannelId , discord .CozeBotId , discord . MessageMaxToken , false , nil
709709 } else {
710710 sendChannelId , err := discord .CreateChannelWithRetry (c , discord .GuildId , fmt .Sprintf ("cdp-chat-%s" , c .Request .Context ().Value (common .RequestIdKey )), 0 )
711711 if err != nil {
712712 //common.LogError(c, myerr.Error())
713- return "" , "" , false , err
713+ return "" , "" , "" , false , err
714714 }
715- return sendChannelId , discord .CozeBotId , true , nil
715+ return sendChannelId , discord .CozeBotId , discord . MessageMaxToken , true , nil
716716 }
717717 }
718718}
0 commit comments