-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (28 loc) · 1.1 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import streamlit as st
from openai import OpenAI
st.title('BOT LIKE CHATGPT(Detroit)')
client = OpenAI(
api_key="",
base_url="https://api.aimlapi.com",)
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = "mistralai/Mistral-7B-Instruct-v0.2"
if "history" not in st.session_state:
st.session_state.history = []
for message in st.session_state.history:
with st.chat_message(message["avatar"]):
st.markdown(message["message"])
if prompt := st.chat_input("type something"):
with st.chat_message("user"):
st.markdown(prompt)
st.session_state.history.append({"avatar": "user", "message": prompt})
with st.chat_message("assistant"):
stream = client.chat.completions.create(
model=st.session_state["openai_model"],
messages=[
{"role": m["avatar"], "content": m["message"]}
for m in st.session_state.history
],
stream=True,
)
response = st.write_stream(stream)
st.session_state.history.append({"avatar": "assistant", "message": prompt})