add basic chat loop

This commit is contained in:
2024-02-25 20:17:48 -07:00
parent d102e52dfc
commit 1ed6023a14
2 changed files with 32 additions and 2 deletions

View File

@ -106,8 +106,9 @@ 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 {
fmt.Println("429 error, waiting 5 seconds...")
time.Sleep(5 * time.Second)
seconds := (1 / 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
}
return openai.ChatCompletionResponse{}, fmt.Errorf("ChatCompletion request error: %w", err)