Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
3 |
|
4 |
# การตั้งค่า API Key สำหรับ OpenAI
|
5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
|
|
6 |
|
7 |
# ชื่อโปรเจกต์
|
8 |
st.title("Welcome to JoyStory! 🎉")
|
@@ -36,15 +38,16 @@ if st.session_state["story_started"]:
|
|
36 |
user_input = st.text_input("Add your sentence:")
|
37 |
if st.button("Submit"):
|
38 |
# การเรียกใช้ API ตามโครงสร้างใหม่
|
39 |
-
|
40 |
-
|
|
|
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 |
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
from openai import OpenAI
|
4 |
|
5 |
# การตั้งค่า API Key สำหรับ OpenAI
|
6 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
7 |
+
client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
|
8 |
|
9 |
# ชื่อโปรเจกต์
|
10 |
st.title("Welcome to JoyStory! 🎉")
|
|
|
38 |
user_input = st.text_input("Add your sentence:")
|
39 |
if st.button("Submit"):
|
40 |
# การเรียกใช้ API ตามโครงสร้างใหม่
|
41 |
+
|
42 |
+
response = client.chat.completions.create(
|
43 |
+
model="gpt-4o-mini",
|
44 |
messages=[
|
45 |
{"role": "system", "content": "You are a storytelling assistant who helps children write fun and imaginative stories."},
|
46 |
{"role": "user", "content": st.session_state["story_text"] + " " + user_input}
|
47 |
],
|
48 |
temperature=0.7,
|
49 |
+
max_tokens=50 # Increased to accommodate answers and explanations
|
50 |
+
)
|
51 |
|
52 |
ai_text = response.choices[0].message["content"].strip()
|
53 |
|