mirror of
https://github.com/coaidev/coai.git
synced 2025-05-26 00:10:15 +09:00
fix retries error
This commit is contained in:
parent
c65051b1d9
commit
5cfd8a7118
@ -33,19 +33,18 @@ func NewChatRequest(props *ChatProps, hook globals.Hook) error {
|
||||
|
||||
retries := getRetries(props.MaxRetries)
|
||||
props.Current++
|
||||
if props.Current > 1 {
|
||||
fmt.Println(fmt.Sprintf("retrying chat request for %s (attempt %d/%d, error: %s)", props.Model, props.Current, retries, err.Error()))
|
||||
}
|
||||
|
||||
if IsAvailableError(err) {
|
||||
if isQPSOverLimit(props.Model, err) {
|
||||
// sleep for 0.5s to avoid qps limit
|
||||
|
||||
fmt.Println(fmt.Sprintf("qps limit for %s, sleep and retry (times: %d)", props.Model, props.Current))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
return NewChatRequest(props, hook)
|
||||
}
|
||||
|
||||
if props.Current < retries {
|
||||
fmt.Println(fmt.Sprintf("retrying chat request for %s (attempt %d/%d, error: %s)", props.Model, props.Current+1, retries, err.Error()))
|
||||
return NewChatRequest(props, hook)
|
||||
}
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ func CreateGenerationWorker(c *gin.Context, user *auth.User, model string, promp
|
||||
titles := ParseTitle(title)
|
||||
result := make(chan Response, len(titles))
|
||||
|
||||
for _, title := range titles {
|
||||
for _, name := range titles {
|
||||
go func(title string) {
|
||||
result <- GenerateArticle(c, user, model, hash, title, prompt, enableWeb)
|
||||
}(title)
|
||||
}(name)
|
||||
}
|
||||
|
||||
return len(titles), result
|
||||
|
Loading…
Reference in New Issue
Block a user