fix retries->wait times

This commit is contained in:
2024-03-17 00:07:39 -06:00
parent 917c00c23a
commit d7598e7c90
2 changed files with 18 additions and 2 deletions

View File

@ -68,7 +68,7 @@ func singlePromptInteraction(systemPrompt, prompt string, retries int) (openai.C
if err != nil { if err != nil {
// if 429, wait and try again // if 429, wait and try again
if strings.Contains(err.Error(), "429") && retries > 0 { if strings.Contains(err.Error(), "429") && retries > 0 {
seconds := (1 / retries) * 60 // back off for each retry e.g. 12, 15, 20, 30, 60 seconds := (1 / float64(retries)) * 60 // back off for each retry e.g. 12, 15, 20, 30, 60
fmt.Printf("429 error, waiting %v seconds...\n", seconds) fmt.Printf("429 error, waiting %v seconds...\n", seconds)
time.Sleep(time.Duration(seconds) * time.Second) time.Sleep(time.Duration(seconds) * time.Second)
return singlePromptInteraction(systemPrompt, prompt, retries-1) // TODO: establish base case to prevent forever retrying return singlePromptInteraction(systemPrompt, prompt, retries-1) // TODO: establish base case to prevent forever retrying
@ -122,7 +122,7 @@ func sendPrompt(messages []openai.ChatCompletionMessage, retries int) (openai.Ch
if err != nil { if err != nil {
// if 429, wait and try again // if 429, wait and try again
if strings.Contains(err.Error(), "429") && retries > 0 { if strings.Contains(err.Error(), "429") && retries > 0 {
seconds := (1 / retries) * 60 // back off for each retry e.g. 12, 15, 20, 30, 60 seconds := (1 / float64(retries)) * 60 // back off for each retry e.g. 12, 15, 20, 30, 60
fmt.Printf("429 error, waiting %v seconds...\n", seconds) fmt.Printf("429 error, waiting %v seconds...\n", seconds)
time.Sleep(time.Duration(seconds) * time.Second) time.Sleep(time.Duration(seconds) * time.Second)
return sendPrompt(messages, retries-1) // TODO: establish base case to prevent forever retrying return sendPrompt(messages, retries-1) // TODO: establish base case to prevent forever retrying

View File

@ -0,0 +1,16 @@
package LLMMapper
import (
"fmt"
"testing"
)
func Test_retryMath(t *testing.T) {
retries := 5
for retries > 0 {
seconds := (1 / float64(retries)) * 60
fmt.Println(seconds, retries)
retries = retries - 1
}
}