ankitpatil3003/Basic-AI-Chatbot-using-Langgraph
1
1import streamlit as st2import json3from src.langgraphagenticai.ui.streamlitui.loadui import LoadStreamlitUI4from src.langgraphagenticai.LLMS.groqllm import GroqLLM5from src.langgraphagenticai.graph.graph_builder import GraphBuilder6from src.langgraphagenticai.ui.streamlitui.display_result import DisplayResultStreamlit7 8# MAIN Function START9def load_langgraph_agenticai_app():10 """11 Loads and runs the LangGraph AgenticAI application with Streamlit UI.12 This function initializes the UI, handles user input, configures the LLM model,13 sets up the graph based on the selected use case, and displays the output while 14 implementing exception handling for robustness.15 """16 17 # Load UI18 ui = LoadStreamlitUI()19 user_input = ui.load_streamlit_ui()20 21 if not user_input:22 st.error("Error: Failed to load user input from the UI.")23 return24 25 # Text input for user message26 if st.session_state.IsFetchButtonClicked:27 user_message = st.session_state.timeframe 28 else :29 user_message = st.chat_input("Enter your message:")30 31 if user_message:32 try:33 # Configure LLM34 obj_llm_config = GroqLLM(user_controls_input=user_input)35 model = obj_llm_config.get_llm_model()36 37 if not model:38 st.error("Error: LLM model could not be initialized.")39 return40 41 # Initialize and set up the graph based on use case42 usecase = user_input.get('selected_usecase')43 if not usecase:44 st.error("Error: No use case selected.")45 return46 47 48 ### Graph Builder49 graph_builder=GraphBuilder(model)50 try:51 graph = graph_builder.setup_graph(usecase)52 DisplayResultStreamlit(usecase,graph,user_message).display_result_on_ui()53 except Exception as e:54 st.error(f"Error: Graph setup failed - {e}")55 return56 57 58 except Exception as e:59 raise ValueError(f"Error Occurred with Exception : {e}")