-
Notifications
You must be signed in to change notification settings - Fork 7
/
chat.py
35 lines (21 loc) · 1.03 KB
/
chat.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
import streamlit as st
from dotenv import load_dotenv
from llm import get_ai_response
st.set_page_config(page_title="소득세 챗봇", page_icon="🤖")
st.title("🤖 소득세 챗봇")
st.caption("소득세에 관련된 모든것을 답해드립니다!")
load_dotenv()
if 'message_list' not in st.session_state:
st.session_state.message_list = []
for message in st.session_state.message_list:
with st.chat_message(message["role"]):
st.write(message["content"])
if user_question := st.chat_input(placeholder="소득세에 관련된 궁금한 내용들을 말씀해주세요!"):
with st.chat_message("user"):
st.write(user_question)
st.session_state.message_list.append({"role": "user", "content": user_question})
with st.spinner("답변을 생성하는 중입니다"):
ai_response = get_ai_response(user_question)
with st.chat_message("ai"):
ai_message = st.write_stream(ai_response)
st.session_state.message_list.append({"role": "ai", "content": ai_message})