From d7598e7c904f56972eeb37d58d5643130bbd42e7 Mon Sep 17 00:00:00 2001 From: Mason Payne Date: Sun, 17 Mar 2024 00:07:39 -0600 Subject: [PATCH] fix retries->wait times --- LLMMapper/llmMapper.go | 4 ++-- LLMMapper/llmMapper_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 LLMMapper/llmMapper_test.go diff --git a/LLMMapper/llmMapper.go b/LLMMapper/llmMapper.go index 95e8beb..29f51c8 100644 --- a/LLMMapper/llmMapper.go +++ b/LLMMapper/llmMapper.go @@ -68,7 +68,7 @@ func singlePromptInteraction(systemPrompt, prompt string, retries int) (openai.C if err != nil { // if 429, wait and try again 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) time.Sleep(time.Duration(seconds) * time.Second) 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 429, wait and try again 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) time.Sleep(time.Duration(seconds) * time.Second) return sendPrompt(messages, retries-1) // TODO: establish base case to prevent forever retrying diff --git a/LLMMapper/llmMapper_test.go b/LLMMapper/llmMapper_test.go new file mode 100644 index 0000000..17a7b67 --- /dev/null +++ b/LLMMapper/llmMapper_test.go @@ -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 + } + +}