Spaces:
Runtime error
Runtime error
File size: 1,690 Bytes
f06ec84 731addc fb78408 1ad30a4 d644174 fb78408 7c25492 1ad30a4 7c25492 1ad30a4 7c25492 1ad30a4 fb78408 1ad30a4 fb78408 a5cfe8c fb78408 1ad30a4 aca6f48 1ad30a4 a772a89 1ad30a4 aca6f48 1ad30a4 aca6f48 1ad30a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#import dependacies
from groq import Groq
import streamlit as st
import os
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.completions.create(
messages=[
{"role":"system","content":"You are MATH LEARN, a math assistant chatbot. 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,
stop=None
)
return response.choices[0].message.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}) |