Guiyom commited on
Commit
9645af1
·
1 Parent(s): 0e65a32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -4,6 +4,7 @@ import random
4
  import time
5
  import os
6
  import re
 
7
 
8
  # Set up OpenAI API key
9
  system_message = "You are an assistant simulating the behavior of the participants in a focus group and answer a set of questions. Your first task will be to generate the profiles of the focus group then to simulate their answers to the question for each member."
@@ -419,11 +420,22 @@ Now please provide your results.
419
  return list[0], list[1], list[2], list[3], list[4], list[5], list[6], list[7], list[8], list[9]
420
 
421
  def answer(formmatedprompt):
422
- response = openai.ChatCompletion.create(
423
- model='gpt-3.5-turbo-16k',
424
- messages=formmatedprompt
425
- )
426
- result = response['choices'][0]['message']['content']
 
 
 
 
 
 
 
 
 
 
 
427
  return result
428
 
429
  def init_history(title):
 
4
  import time
5
  import os
6
  import re
7
+ import time
8
 
9
  # Set up OpenAI API key
10
  system_message = "You are an assistant simulating the behavior of the participants in a focus group and answer a set of questions. Your first task will be to generate the profiles of the focus group then to simulate their answers to the question for each member."
 
420
  return list[0], list[1], list[2], list[3], list[4], list[5], list[6], list[7], list[8], list[9]
421
 
422
  def answer(formmatedprompt):
423
+ #Now let's try 10 times
424
+ for attempt in range(10):
425
+ try:
426
+ response = openai.ChatCompletion.create(
427
+ model='gpt-3.5-turbo-16k',
428
+ messages=formmatedprompt
429
+ )
430
+ result = response['choices'][0]['message']['content']
431
+ break
432
+ except Exception as e:
433
+ print(f"Error occurred on attempt {attempt + 1}: {e}")
434
+ if attempt < 10:
435
+ time.sleep(10)
436
+ else:
437
+ raise e
438
+ print(f'result of answer is:{result}')
439
  return result
440
 
441
  def init_history(title):