diff --git a/chatbot.py b/chatbot.py new file mode 100644 index 000000000..06395ba27 --- /dev/null +++ b/chatbot.py @@ -0,0 +1,62 @@ +import streamlit as st +from openai import OpenAI +import json + + +# Set up the Streamlit app +st.title("BuffTeks Chatbot") +st.subheader("Chat with the [DeepSeek](https://www.deepseek.com/)-powered AI assistant!") +st.info("Feel free to chat with the chatbot! Just a heads up, you have 10 messages to use.") +with st.expander("See Source Code"): + with open(__file__, "r") as f: + st.code(f.read(), language="python") + +# Load API credentials from config.json +with open('config.json') as config_file: + config = json.load(config_file) + openai_api_base_url = config["api_url"] + openai_api_key = config["api_key"] + +client = OpenAI(api_key=openai_api_key, base_url=openai_api_base_url) + +# Initialize session state to store chat history and message count +if "messages" not in st.session_state: + st.session_state.messages = [] +if "message_count" not in st.session_state: + st.session_state.message_count = 0 + +# Set the maximum number of user messages +MAX_USER_MESSAGES = 10 + +# Display chat history +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Chat input +if st.session_state.message_count < MAX_USER_MESSAGES: + if prompt := st.chat_input("Type your message..."): + # Add user message to chat history + st.session_state.messages.append({"role": "user", "content": prompt}) + st.session_state.message_count += 1 + with st.chat_message("user"): + st.markdown(prompt) + + # Call DeepSeek for a response + with st.chat_message("assistant"): + stream = client.chat.completions.create( + model="deepseek-chat", + messages=[ + {"role": m["role"], "content": m["content"]} + for m in st.session_state.messages + ], + stream=True, + ) + response = st.write_stream(stream) + st.session_state.messages.append({"role": "assistant", "content": response}) + +else: + st.warning("You have reached the maximum number of messages allowed.") + +if st.button("Clear Chat"): + st.session_state.messages = [] \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 000000000..de439fc2b --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "api_url": "https://api.deepseek.com", + "api_key": "sk-12165b127043441697a8940918e207ac" +} \ No newline at end of file diff --git a/webpages/__pycache__/join_us.cpython-312.pyc b/webpages/__pycache__/join_us.cpython-312.pyc index b82ec2fd0..6f80101f4 100644 Binary files a/webpages/__pycache__/join_us.cpython-312.pyc and b/webpages/__pycache__/join_us.cpython-312.pyc differ diff --git a/webpages/outstanding_members.py b/webpages/outstanding_members.py index 581c03ea9..f99a9c015 100644 --- a/webpages/outstanding_members.py +++ b/webpages/outstanding_members.py @@ -8,7 +8,7 @@ def outstanding_members(): st.image("./images/StudentDarrian.jpg",width= 200 ) with stu1_text: st.header("Darrian Lambert") - st.subheader("Senior Student in CIS") + st.subheader("2024 CIS Graduate") st.markdown(""" "_Bufftek has been a fantastic experience for me. It gave me the opportunity to apply the skills I’ve learned in class to real-world problems and work alongside others to develop effective software solutions. Through this, I gained hands-on experience with skills that are difficult to practice on your own._ @@ -27,7 +27,7 @@ def outstanding_members(): st.image("./images/StudentKim.jpg",width= 200 ) with stu2_text: st.header("Kim Sundblom") - st.subheader("Senior Student in CIS") + st.subheader("2024 CIS Graduate") st.markdown("""