Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from openai import OpenAI
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
st.title("Trillion-7B-Preview")
|
7 |
+
|
8 |
+
client = OpenAI(
|
9 |
+
api_key=os.getenv("API_KEY"),
|
10 |
+
base_url=os.getenv("BASE_URL"),
|
11 |
+
)
|
12 |
+
|
13 |
+
if "openai_model" not in st.session_state:
|
14 |
+
st.session_state["openai_model"] = "trillionlabs/Trillion-7B-preview"
|
15 |
+
|
16 |
+
if "messages" not in st.session_state:
|
17 |
+
st.session_state.messages = []
|
18 |
+
|
19 |
+
for message in st.session_state.messages:
|
20 |
+
with st.chat_message(message["role"]):
|
21 |
+
st.markdown(message["content"])
|
22 |
+
|
23 |
+
if prompt := st.chat_input("Message"):
|
24 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
25 |
+
with st.chat_message("user"):
|
26 |
+
st.markdown(prompt)
|
27 |
+
|
28 |
+
with st.chat_message("assistant"):
|
29 |
+
stream = client.chat.completions.create(
|
30 |
+
model=st.session_state["openai_model"],
|
31 |
+
messages=[
|
32 |
+
{"role": m["role"], "content": m["content"]}
|
33 |
+
for m in st.session_state.messages
|
34 |
+
],
|
35 |
+
stream=True,
|
36 |
+
extra_body={
|
37 |
+
"topP": 0.95,
|
38 |
+
"maxTokens": 3072,
|
39 |
+
"temperature": 0.6,
|
40 |
+
},
|
41 |
+
)
|
42 |
+
response = st.write_stream(stream)
|
43 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|