mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
30 lines
692 B
Go
30 lines
692 B
Go
package channel
|
|
|
|
import (
|
|
"chat/adapter"
|
|
"chat/globals"
|
|
"chat/utils"
|
|
"fmt"
|
|
)
|
|
|
|
func NewChatRequest(props *adapter.ChatProps, hook globals.Hook) error {
|
|
if !ManagerInstance.HasChannel(props.Model) {
|
|
return fmt.Errorf("cannot find channel for model %s", props.Model)
|
|
}
|
|
|
|
ticker := ManagerInstance.GetTicker(props.Model)
|
|
|
|
var err error
|
|
for !ticker.IsDone() {
|
|
if channel := ticker.Next(); channel != nil {
|
|
props.MaxRetries = utils.ToPtr(channel.GetRetry())
|
|
if err = adapter.NewChatRequest(channel, props, hook); err == nil {
|
|
return nil
|
|
}
|
|
fmt.Println(fmt.Sprintf("[channel] hit error %s for model %s, goto next channel", err.Error(), props.Model))
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|