-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (32 loc) · 949 Bytes
/
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
40
41
42
43
import os
import openai
import streamlit as st
openai.api_key = os.getenv("OPENAI_KEY")
st.set_page_config(
page_title="ChatGpt-4o",
page_icon="🤖",
layout="centered"
)
st.title('ChatGpt-4o')
prompt = st.chat_input('Ask anything...')
if "chats" not in st.session_state:
st.session_state.chats = []
if prompt:
st.session_state.chats.append({
"role": "user",
"content": prompt
})
assistant = openai.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are the world's best social media marketing person."},
*st.session_state.chats,
{"role": "user", "content": prompt}
]
)
st.session_state.chats.append({
"role": "assistant",
"content": assistant.choices[0].message.content
})
for chat in st.session_state.chats:
st.chat_message(chat['role']).markdown(chat['content'])