-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
54 lines (42 loc) · 1.81 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
from cmugpt_assistant import CMUGPTAssistant
st.title("CMUGPT Chat Assistant")
# Initialize CMUGPTAssistant in session state
if 'assistant' not in st.session_state:
st.session_state['assistant'] = CMUGPTAssistant()
st.session_state['messages'] = []
st.session_state['functions_called'] = []
# Display the conversation
for message in st.session_state['messages']:
if message['role'] == 'user':
with st.chat_message('user'):
st.write(message['content'])
elif message['role'] == 'assistant':
with st.chat_message('assistant'):
st.write(message['content'])
# Chat input
prompt = st.chat_input("Ask me anything about Carnegie Mellon University")
if prompt:
# Add user's message to session state
st.session_state['messages'].append({"role": "user", "content": prompt})
# Display user's message
with st.chat_message('user'):
st.write(prompt)
# Process user input
assistant_response = st.session_state['assistant'].process_user_input(prompt)
# Add assistant's message to session state
st.session_state['messages'].append({"role": "assistant", "content": assistant_response})
# Display assistant's message
with st.chat_message('assistant'):
st.write(assistant_response)
# Get functions called
functions_called = st.session_state['assistant'].get_functions_called()
# Update functions_called in session state
st.session_state['functions_called'] = functions_called
# Display functions called in the sidebar
st.sidebar.title("Functions Called")
for func in st.session_state['functions_called']:
st.sidebar.subheader(f"Function: {func['function_name']}")
st.sidebar.write(f"**Arguments:** {func['arguments']}")
st.sidebar.write(f"**Result:** {func['result']}")
st.sidebar.write("---")