fix retries error

This commit is contained in:
Zhang Minghan 2023-11-23 21:01:01 +08:00
parent c65051b1d9
commit 5cfd8a7118
2 changed files with 4 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -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