import streamlit as st from app_config import SYSTEM_PROMPT from langchain_groq import ChatGroq from dotenv import load_dotenv from pathlib import Path import os import session_manager from langchain_community.utilities import GoogleSerperAPIWrapper env_path = Path('.') / '.env' load_dotenv(dotenv_path=env_path) st.markdown( """ """, unsafe_allow_html=True, ) # Intialize chat history print("SYSTEM MESSAGE") if "messages" not in st.session_state: st.session_state.messages = [{"role": "system", "content": SYSTEM_PROMPT}] print("SYSTEM MODEL") if "llm" not in st.session_state: st.session_state.llm = ChatGroq( model="llama-3.3-70b-versatile", temperature=0, max_tokens=None, timeout=None, max_retries=2, api_key=str(os.getenv('GROQ_API')) ) if "search_tool" not in st.session_state: st.session_state.search_tool = GoogleSerperAPIWrapper( serper_api_key=str(os.getenv('SERPER_API'))) def get_answer(query): new_search_query = st.session_state.llm.invoke( f"Convert below query to english for Ahmedabad Municipal Corporation (AMC) You just need to give translated query. Don't add any additional details.\n Query: {query}").content search_result = st.session_state.search_tool.run( f"{new_search_query} site:https://ahmedabadcity.gov.in/") system_prompt = """You are a helpful assistance for The Ahmedabad Municipal Corporation (AMC). which asnwer user query from given context only. Output language should be as same as `original_query_from_user`. context: {context} original_query_from_user: {original_query} query: {query}""" return st.session_state.llm.invoke(system_prompt.format(context=search_result, query=new_search_query, original_query=query)).content session_manager.set_session_state(st.session_state) print("container") # Display chat messages from history st.markdown("