|
import os |
|
import streamlit as st |
|
from groq import Groq |
|
|
|
|
|
|
|
GROQ_API_KEY = os.environ.get("MY_KEY") |
|
|
|
client = Groq(api_key=GROQ_API_KEY) |
|
|
|
|
|
|
|
st.set_page_config(page_title="Groq Chatbot", page_icon="π€") |
|
|
|
|
|
st.title("π€ Groq Chatbot using LLaMA 3") |
|
|
|
|
|
user_input = st.text_input("You:", placeholder="Type your question here...") |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for msg in st.session_state.messages: |
|
with st.chat_message(msg["role"]): |
|
st.markdown(msg["content"]) |
|
|
|
|
|
if user_input: |
|
|
|
st.session_state.messages.append({"role": "user", "content": user_input}) |
|
with st.chat_message("user"): |
|
st.markdown(user_input) |
|
|
|
|
|
try: |
|
response = client.chat.completions.create( |
|
messages=st.session_state.messages, |
|
model="llama3-70b-8192", |
|
) |
|
reply = response.choices[0].message.content |
|
|
|
|
|
st.session_state.messages.append({"role": "assistant", "content": reply}) |
|
with st.chat_message("assistant"): |
|
st.markdown(reply) |
|
|
|
except Exception as e: |
|
st.error(f"Error: {e}") |
|
|