-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_bot.py
More file actions
62 lines (50 loc) · 1.85 KB
/
chat_bot.py
File metadata and controls
62 lines (50 loc) · 1.85 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# ECHO BOT
import openai
import streamlit as st
st.title("Echo Bot")
# if "openai_model" not in st.session_state:
# st.session_state["openai_model"] = "gpt-3.5-turbo"
# Chat History
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
prompt = st.chat_input("Hello!")
if prompt:
# Display user message
with st.chat_message("user"):
st.markdown(prompt)
# Add user message to history
st.session_state.messages.append({"role": "user", "content": prompt})
response = f"Echo: {prompt}"
# Display assistant response
with st.chat_message("assistant"):
st.markdown(response)
# Add assistant
st.session_state.messages.append({"role": "assistant", "content": response})
# FOR OPEN AI
#_________________________________________________
# import streamlit as st
# from openai import OpenAI
# st.title("Wish me luck")
# client = OpenAI(api_key=st.secrets["ACE"])
# if "messages" not in st.session_state:
# st.session_state.messages = []
# for message in st.session_state.messages:
# with st.chat_message(message["role"]):
# st.markdown(message["content"])
# prompt = st.chat_input("Say something")
# if prompt:
# with st.chat_message("user"):
# st.markdown(prompt)
# st.session_state.messages.append({"role": "user", "content": prompt})
# response = client.chat.completions.create(
# model="gpt-3.5-turbo",
# messages=st.session_state.messages
# ).choices[0].message.content
# with st.chat_message("assistant"):
# st.markdown(response)
# st.session_state.messages.append({"role": "assisstant", "content": response})