Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,18 +10,18 @@ st.title("Test OpenAI API in Streamlit")
|
|
10 |
# User input
|
11 |
user_input = st.text_area("Enter prompt to generate questions:")
|
12 |
|
13 |
-
if st.button("Generate
|
14 |
if user_input:
|
15 |
-
#
|
16 |
-
|
17 |
-
model="gpt-
|
18 |
messages=[
|
19 |
-
{"role": "system", "content": "You are a helpful assistant
|
20 |
-
{"role": "user", "content":
|
21 |
]
|
22 |
)
|
23 |
-
# Display the
|
24 |
-
st.write("
|
25 |
-
st.write(
|
26 |
else:
|
27 |
st.warning("Please enter a prompt.")
|
|
|
10 |
# User input
|
11 |
user_input = st.text_area("Enter prompt to generate questions:")
|
12 |
|
13 |
+
if st.button("Generate Response"):
|
14 |
if user_input:
|
15 |
+
# Create a chat completion
|
16 |
+
completion = openai.ChatCompletion.create(
|
17 |
+
model="gpt-3.5-turbo", # Or use "gpt-4" if available to you
|
18 |
messages=[
|
19 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
20 |
+
{"role": "user", "content": user_input}
|
21 |
]
|
22 |
)
|
23 |
+
# Display the assistant's reply
|
24 |
+
st.write("Assistant's response:")
|
25 |
+
st.write(completion.choices[0].message['content'])
|
26 |
else:
|
27 |
st.warning("Please enter a prompt.")
|