fix retries->wait times
This commit is contained in:
@ -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
|
||||||
|
16
LLMMapper/llmMapper_test.go
Normal file
16
LLMMapper/llmMapper_test.go
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user