|
import streamlit as st |
|
from groq import Groq |
|
|
|
|
|
client = Groq(api_key="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") |
|
|
|
|
|
st.set_page_config(page_title="π° Finance & Banking Chatbot", layout="wide") |
|
|
|
|
|
SYSTEM_PROMPT = ( |
|
"You are an expert financial assistant. Your role is to answer ONLY finance-related topics, including banking, investments, " |
|
"loans, credit cards, budgeting, and economic trends. " |
|
"If a user asks a question unrelated to finance, you MUST respond with: " |
|
"'I'm here to assist with financial topics only. Please ask me something related to banking, investments, or finance. π°'" |
|
) |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [ |
|
{"role": "assistant", "content": "Hello! I can help you with financial questions. How can I assist? π³"} |
|
] |
|
|
|
|
|
st.title("π³ Finance & Banking Chatbot π€΅") |
|
|
|
|
|
for msg in st.session_state.messages: |
|
with st.chat_message(msg["role"], avatar=("π¦π»" if msg["role"] == "user" else "π€΅")): |
|
st.markdown(msg["content"]) |
|
|
|
|
|
user_input = st.chat_input("Ask me about finance, banking, investments, etc. π") |
|
|
|
if user_input: |
|
|
|
st.session_state.messages.append({"role": "user", "content": user_input}) |
|
with st.chat_message("user", avatar="π¦π»"): |
|
st.markdown(user_input) |
|
|
|
|
|
response = client.chat.completions.create( |
|
messages=[{"role": "system", "content": SYSTEM_PROMPT}] + st.session_state.messages, |
|
model="llama-3.3-70b-versatile", |
|
max_tokens=200, |
|
) |
|
|
|
bot_reply = response.choices[0].message.content |
|
|
|
|
|
st.session_state.messages.append({"role": "assistant", "content": bot_reply}) |
|
with st.chat_message("assistant", avatar="π€΅"): |
|
st.markdown(bot_reply) |
|
|