Rathapoom commited on
Commit
54ba6a8
·
verified ·
1 Parent(s): d8f8ded

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -70,14 +70,17 @@ def generate_questions_with_retry(knowledge_material, question_type, cognitive_l
70
  retries = 0
71
  while retries < max_retries:
72
  try:
73
- # Use the correct method to call the API
74
- response = openai.Completion.create(
75
- model="text-davinci-003", # Updated model (use one of the latest models)
76
- prompt=prompt, # The prompt for generating the questions
77
- max_tokens=1000, # Adjust this based on how long the questions might be
78
- temperature=0.7 # Controls randomness
 
 
 
79
  )
80
- return response.choices[0].text # Extract the text from the API response
81
  except openai.APIConnectionError as e:
82
  retries += 1
83
  time.sleep(2) # Wait for 2 seconds before retrying
 
70
  retries = 0
71
  while retries < max_retries:
72
  try:
73
+ # Use the new method `ChatCompletion.create`
74
+ response = openai.ChatCompletion.create(
75
+ model="gpt-3.5-turbo", # You can use "gpt-4" if available
76
+ messages=[
77
+ {"role": "system", "content": "You are a helpful assistant for generating exam questions."},
78
+ {"role": "user", "content": prompt}
79
+ ],
80
+ max_tokens=1000,
81
+ temperature=0.7
82
  )
83
+ return response.choices[0].message["content"] # Get the response text
84
  except openai.APIConnectionError as e:
85
  retries += 1
86
  time.sleep(2) # Wait for 2 seconds before retrying