Rathapoom commited on
Commit
5946090
·
verified ·
1 Parent(s): e8ef1e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -12,15 +12,16 @@ user_input = st.text_area("Enter prompt to generate questions:")
12
 
13
  if st.button("Generate Questions"):
14
  if user_input:
15
- # Call OpenAI API
16
- response = openai.Completion.create(
17
- model="gpt-4o-mini",
18
- prompt=f"Generate exam questions from the following material: {user_input}",
19
- max_tokens=1000,
20
- temperature=0.7,
 
21
  )
22
  # Display the generated questions
23
  st.write("Generated Questions:")
24
- st.write(response.choices[0].text)
25
  else:
26
  st.warning("Please enter a prompt.")
 
12
 
13
  if st.button("Generate Questions"):
14
  if user_input:
15
+ # Use the new chat-based API
16
+ response = openai.ChatCompletion.create(
17
+ model="gpt-4o-mini", # You can use "gpt-4" if available
18
+ messages=[
19
+ {"role": "system", "content": "You are a helpful assistant that generates exam questions."},
20
+ {"role": "user", "content": f"Generate exam questions from the following material: {user_input}"}
21
+ ]
22
  )
23
  # Display the generated questions
24
  st.write("Generated Questions:")
25
+ st.write(response['choices'][0]['message']['content'])
26
  else:
27
  st.warning("Please enter a prompt.")