Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
)
|
80 |
-
return response.choices[0].
|
81 |
-
except
|
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.")
|