Rathapoom commited on
Commit
5eb9405
·
verified ·
1 Parent(s): 0a00fe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -70,16 +70,17 @@ def generate_questions_with_retry(knowledge_material, question_type, cognitive_l
70
  retries = 0
71
  while retries < max_retries:
72
  try:
73
- response = openai.ChatCompletion.create(
74
- model="gpt-3.5-turbo",
75
- messages=[
76
- {"role": "system", "content": "You are a helpful assistant for generating exam questions."},
77
- {"role": "user", "content": prompt}
78
- ]
79
  )
80
- return response.choices[0].message["content"]
81
- except OpenAIError as e:
82
  retries += 1
 
83
  st.error(f"Failed to connect to OpenAI API: {str(e)}")
84
  if retries == max_retries:
85
  st.error("Failed to connect to OpenAI API after several attempts.")
 
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.error.APIError as e:
82
  retries += 1
83
+ time.sleep(2) # Wait for 2 seconds before retrying
84
  st.error(f"Failed to connect to OpenAI API: {str(e)}")
85
  if retries == max_retries:
86
  st.error("Failed to connect to OpenAI API after several attempts.")