Update app.py
Browse files- app.py +7 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -3,6 +3,8 @@ from openai import OpenAI, AzureOpenAI
|
|
3 |
from typing import Iterator
|
4 |
import os
|
5 |
from phoenix.otel import register
|
|
|
|
|
6 |
|
7 |
PHOENIX_API_KEY=st.secrets['PHOENIX_API_KEY']
|
8 |
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={PHOENIX_API_KEY}"
|
@@ -57,13 +59,14 @@ if prompt := st.chat_input("What is up?"):
|
|
57 |
with st.chat_message("user"):
|
58 |
st.markdown(prompt)
|
59 |
|
|
|
|
|
|
|
|
|
60 |
with st.chat_message("assistant"):
|
61 |
stream = client.chat.completions.create(
|
62 |
model=st.session_state["openai_model"],
|
63 |
-
messages=
|
64 |
-
{"role": m["role"], "content": m["content"]}
|
65 |
-
for m in st.session_state.messages
|
66 |
-
],
|
67 |
stream=True,
|
68 |
)
|
69 |
response = st.write_stream(stream)
|
|
|
3 |
from typing import Iterator
|
4 |
import os
|
5 |
from phoenix.otel import register
|
6 |
+
from opencc import OpenCC
|
7 |
+
cc = OpenCC('s2twp')
|
8 |
|
9 |
PHOENIX_API_KEY=st.secrets['PHOENIX_API_KEY']
|
10 |
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={PHOENIX_API_KEY}"
|
|
|
59 |
with st.chat_message("user"):
|
60 |
st.markdown(prompt)
|
61 |
|
62 |
+
messages = [{"role": "system", "content": "如果使用者使用繁體中文,請用繁體中文回答使用者,並以台灣社會的場景為主。"}]
|
63 |
+
for m in st.session_state.messages:
|
64 |
+
messages.append({"role": m["role"], "content": m["content"]})
|
65 |
+
|
66 |
with st.chat_message("assistant"):
|
67 |
stream = client.chat.completions.create(
|
68 |
model=st.session_state["openai_model"],
|
69 |
+
messages=messages,
|
|
|
|
|
|
|
70 |
stream=True,
|
71 |
)
|
72 |
response = st.write_stream(stream)
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ streamlit==1.36.0
|
|
2 |
openai==1.55.3
|
3 |
arize-phoenix==5.12.0
|
4 |
openinference-instrumentation==0.1.18
|
5 |
-
openinference-instrumentation-openai==0.1.18
|
|
|
|
2 |
openai==1.55.3
|
3 |
arize-phoenix==5.12.0
|
4 |
openinference-instrumentation==0.1.18
|
5 |
+
openinference-instrumentation-openai==0.1.18
|
6 |
+
opencc-python-reimplemented
|