add basic chat loop
This commit is contained in:
5
main.go
5
main.go
@ -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)
|
||||
|
Reference in New Issue
Block a user