Rathapoom commited on
Commit
a9cc308
·
verified ·
1 Parent(s): 1b2ef9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -35,12 +35,18 @@ if st.session_state["story_started"]:
35
  # กล่องให้เด็กแต่งประโยค
36
  user_input = st.text_input("Add your sentence:")
37
  if st.button("Submit"):
38
- response = openai.Completion.create(
 
39
  model="gpt-4o-mini",
40
- prompt=st.session_state["story_text"] + " " + user_input,
 
 
 
 
41
  max_tokens=50
42
  )
43
- ai_text = response.choices[0].text.strip()
 
44
 
45
  # อัปเดตเรื่องราวที่กำลังดำเนินอยู่
46
  st.session_state["story_text"] += " " + user_input + " " + ai_text
 
35
  # กล่องให้เด็กแต่งประโยค
36
  user_input = st.text_input("Add your sentence:")
37
  if st.button("Submit"):
38
+ # การเรียกใช้ API ตามโครงสร้างใหม่
39
+ response = openai.ChatCompletion.create(
40
  model="gpt-4o-mini",
41
+ messages=[
42
+ {"role": "system", "content": "You are a storytelling assistant who helps children write fun and imaginative stories."},
43
+ {"role": "user", "content": st.session_state["story_text"] + " " + user_input}
44
+ ],
45
+ temperature=0.7,
46
  max_tokens=50
47
  )
48
+
49
+ ai_text = response.choices[0].message["content"].strip()
50
 
51
  # อัปเดตเรื่องราวที่กำลังดำเนินอยู่
52
  st.session_state["story_text"] += " " + user_input + " " + ai_text