from functions import * # set the title st.sidebar.title(DASHBOARD_TITLE) info_section = st.empty() # add an explanation of what is NER and why it is important for medical tasks st.sidebar.markdown( f""" Meta Llama 3 8B Instruct is part of a family of large language models (LLMs) optimized for dialogue tasks. This project uses Streamlit to create a simple chatbot interface that allows you to chat with the model using the Hugging Face Inference API. Ask the model marketing-related questions and see how it responds. Have fun! Model used: [{MODEL_PATH}]({MODEL_LINK}) """ ) first_assistant_message = "Hello! I am Marketing expert. What can I help you with today?" # clear conversation if st.sidebar.button("Clear conversation"): chat_history = [{'role':'assistant', 'content':first_assistant_message}] st.session_state['chat_history'] = chat_history st.rerun() # Get the chat history if "chat_history" not in st.session_state: chat_history = [{'role':'assistant', 'content':first_assistant_message}] st.session_state['chat_history'] = chat_history else: chat_history = st.session_state['chat_history'] # print the conversation for message in chat_history: with st.chat_message(message['role']): st.write(message['content']) # keep only last 50 messages short_history = [message for message in chat_history[-50:] if 'content' in message] # include a system prompt to explain the bot what to do short_history = [{'role': 'system', 'content': SYSTEM_PROMPT}] + short_history # get the input from user user_input = st.chat_input("Write something...") if user_input: with st.chat_message("user"): st.write(user_input) # make the request with st.spinner("Generating the response..."): # create a shorter_history to avoid to keep a fair usage of the API short_history = short_history + [{'role': 'user', 'content': user_input}] # get the fill history for the next iteration chat_history = make_request(user_input, short_history, chat_history) st.session_state['chat_history'] = chat_history st.rerun()