import streamlit as st import os import chatFromLangchain from chatFromLangchain import LLm from dotenv import load_dotenv from langchain_core.messages import HumanMessage from langchain_core.messages import AIMessage import re import actions import pandas as pd # Load environment variables from the .env file load_dotenv() token = os.getenv('AZURE_OPENAI_KEY') llm_model = 'gpt-3.5-turbo-1106' temperature = 1.0 # Add the logo beside the title st.image("logo.png") st.title("Metaminds") # Add custom CSS for chat bubbles with alignment to the right and left st.markdown(""" """, unsafe_allow_html=True) # Dev Mode Checkbox dev_mode = st.checkbox("Dev Mode") # Setting the LLM if dev_mode: with st.expander("Setting the LLM"): st.markdown("This page is used to have a chat with the uploaded documents") with st.form("setting"): row_1 = st.columns(3) with row_1[0]: token = st.text_input("Open AI Key", type="password") with row_1[1]: llm_model = st.text_input("LLM model", value="openai-gpt-4o") with row_1[2]: temperature = st.number_input("Temperature", value=1.0, step=0.1) create_chatbot = st.form_submit_button("Create chatbot") with st.expander("Chat History LLm"): chathistplace = st.empty() # Prepare the LLM model if "conversation" not in st.session_state: st.session_state.conversation = None if token: st.session_state.conversation = LLm() # Chat history if "history" not in st.session_state: st.session_state.history = [] # Chat messages if "messages" not in st.session_state: st.session_state.messages = [{'role': 'system', 'content': '''You are a Helpful chatbot also a truthful one who will be chatting with user Ragrding some connections to the database . You have access to these tools tableFindinRedshift, this tools find if the table is present in the Redshift database, this tools takes only one input 'tableName': str, and returns either None or a list representing multiple tables present in table or a list of tuples where each tuple representing column name and the column type tableFindinImpala, this tools find if the table is present in the Impala database, this tools takes only one input 'tableName': str, and returns either None or a list representing multiple tables present in table or a list of tuples where each tuple representing column name and the column type if a user have not mentioned the Database connection in his connection confirm it from the user. Here is as example user: Hi as: Hi I am an assistant who can help you with details of any table in Datalake. user: Ok tell about the Mara table in Redshift assistant: ```{'action': 'tableFindinRedshift', 'input': 'Mara'}``` function: ['Mara1', 'Mara2', 'Maraxyz'] assistant: There Are multiple table present in the Reshift similar to Mara please Provide which one to choose user: Mara1 assistant: ```{'action': 'tableFindinRedshift', 'input': 'Mara1'}``` function: [('client_id', int), ('purchase', int)] assistant: Mara1 has 2 columns client_id: int, purchase: int user: Thank you now write a Query which will give me all the clients which has purchase value more than 500 assistant: Certainly ```SELECT client_id FROM Mara1 WHERE purchase > 500``` Refuse to answer any query from user where it deviates from the above mentioned capabilites Example: user: Tell me about the weather. assistant: Hi I am still MetaMinds 1.0 maybe I can answer your questions better when I am MetaMinds 2.0 I can only answer related to Datalakes. '''}] def getAction(text): # Regular expression to extract the content within the backticks pattern = r"```(.*?)```" # Search for the pattern match = re.search(pattern, text) # Extract the matched content if found if match: extracted_content = match.group(1) return eval(extracted_content) else: return None # Display chats - OLD st.markdown('