Koomemartin's picture
Update app.py
1ad30a4 verified
raw
history blame
1.66 kB
#import dependacies
from groq import Groq
import streamlit as st
groq_api_key=os.getenv("GROQ_API_KEY")
#initialize the a groq model
client=Groq(api_key=groq_api_key)
def get_response(query):
response=client.chat.compeletions.create(
messages=[
{"role":"system","content":"You are a math assistant. Your role is to solve math problems with a detailed, step-by-step solution. Be clear and concise in each step. If there are multiple approaches, select the most efficient method. Include any formulas or key concepts used, and provide the final answer at the end."},
{"role":"user","content": query}
],
model='gemma2-9b-it',
temperature=0.4,
stream=False,
max_tokens=1024,
stope=None
)
return response.choices[0].delta.content
st.title('📚🔗 Welcome to MathLearn♾ ')
# Streamlit session state to manage chat messages
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat history
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input and process response
if user_input := st.chat_input():
st.session_state.messages.append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response_text = get_response(user_input)
st.write(response_text)
# Save assistant's response to chat history
st.session_state.messages.append({"role": "assistant", "content": response_text})