|
import streamlit as st, pathlib |
|
from utilities import get_products, aichat |
|
folder = pathlib.Path(__file__).parent.resolve() |
|
|
|
st.set_page_config(page_title="Chatbots", page_icon="🚀",) |
|
st.write("# 👋 Welcome to Receipt Bot!👋") |
|
st.markdown( |
|
""" |
|
|
|
#### 🚀Intelligent Bookkeeping and Document Management Hub🍨 |
|
|
|
|
|
""" |
|
) |
|
|
|
|
|
st.sidebar.image(f"{folder}/resources/sslogo.png", use_column_width=True) |
|
|
|
with st.sidebar: |
|
|
|
openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password") |
|
"[Get an OpenAI API key](https://platform.openai.com/account/api-keys)" |
|
|
|
if "openai_model" not in st.session_state: |
|
st.session_state["openai_model"] = "gpt-3.5-turbo-0125" |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
st.session_state.messages.append({"role": "system", 'content': f""" |
|
You are General Chat Bot, an AI assistant for General Purpose. |
|
"""}) |
|
st.session_state.messages.append({"role": "assistant", "content": "How May I Help You Today💬?"}) |
|
|
|
|
|
|
|
for message in st.session_state.messages[1:]: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if prompt := st.chat_input("💬"): |
|
if not openai_api_key: |
|
st.info("Please add your OpenAI API key to continue.") |
|
else: |
|
try: |
|
|
|
st.session_state.messages.append({"role": "user", "content": prompt}) |
|
|
|
with st.chat_message("user"): |
|
st.markdown(prompt) |
|
|
|
|
|
with st.chat_message("assistant"): |
|
stream = aichat(messages = [ |
|
{"role": m["role"], "content": m["content"]} |
|
for m in st.session_state.messages |
|
],openai_api_key=openai_api_key) |
|
response = st.write_stream(stream) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
except: |
|
st.info("Invalid OpenAI API key. Please enter a valid key to proceed.") |