aliabid94 HF staff commited on
Commit
dfd2ecb
1 Parent(s): c6ca805

Update game_manager.py

Browse files
Files changed (1) hide show
  1. game_manager.py +9 -3
game_manager.py CHANGED
@@ -27,9 +27,15 @@ def ai_response(question):
27
  prompt = PROMPT.format(
28
  question,
29
  )
30
- completions = openai.Completion.create(
31
- engine="text-davinci-003", prompt=prompt, max_tokens=200, n=1, temperature=0.5
32
- )
 
 
 
 
 
 
33
  response = completions["choices"][0]["text"].strip()
34
 
35
  return response
 
27
  prompt = PROMPT.format(
28
  question,
29
  )
30
+ completions = None
31
+ while completions is None:
32
+ try:
33
+ completions = openai.Completion.create(
34
+ engine="text-davinci-003", prompt=prompt, max_tokens=200, n=1, temperature=0.5
35
+ )
36
+ except:
37
+ print("OpenAI connection error")
38
+ time.sleep(1)
39
  response = completions["choices"][0]["text"].strip()
40
 
41
  return response