Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files- app.py +23 -14
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,11 +1,22 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
st.
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
if "openai_model" not in st.session_state:
|
8 |
-
st.session_state["openai_model"] =
|
9 |
|
10 |
if "messages" not in st.session_state:
|
11 |
st.session_state.messages = []
|
@@ -20,16 +31,14 @@ if prompt := st.chat_input("What is up?"):
|
|
20 |
st.markdown(prompt)
|
21 |
|
22 |
with st.chat_message("assistant"):
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
st.write(prompt)
|
33 |
-
response = prompt
|
34 |
st.session_state.messages.append(
|
35 |
{"role": "assistant", "content": response})
|
|
|
1 |
import streamlit as st
|
2 |
+
import os
|
3 |
+
from openai import OpenAI
|
4 |
|
5 |
+
st.set_page_config(
|
6 |
+
page_title="Taiwan Smol Chat",
|
7 |
+
page_icon="🦉",
|
8 |
+
layout="centered"
|
9 |
+
)
|
10 |
|
11 |
+
st.title("🦉Taiwan Smol Chat")
|
12 |
+
|
13 |
+
client = OpenAI(
|
14 |
+
api_key=st.secrets['API_KEY'],
|
15 |
+
base_url=st.secrets['API_BASE_URL']
|
16 |
+
)
|
17 |
|
18 |
if "openai_model" not in st.session_state:
|
19 |
+
st.session_state["openai_model"] = st.secrets['MODEL']
|
20 |
|
21 |
if "messages" not in st.session_state:
|
22 |
st.session_state.messages = []
|
|
|
31 |
st.markdown(prompt)
|
32 |
|
33 |
with st.chat_message("assistant"):
|
34 |
+
stream = client.chat.completions.create(
|
35 |
+
model=st.session_state["openai_model"],
|
36 |
+
messages=[
|
37 |
+
{"role": m["role"], "content": m["content"]}
|
38 |
+
for m in st.session_state.messages
|
39 |
+
],
|
40 |
+
stream=True,
|
41 |
+
)
|
42 |
+
response = st.write_stream(stream)
|
|
|
|
|
43 |
st.session_state.messages.append(
|
44 |
{"role": "assistant", "content": response})
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
streamlit==1.36.0
|
|
|
|
1 |
streamlit==1.36.0
|
2 |
+
openai==1.55.3
|