File size: 1,708 Bytes
b9e05b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3de25ad
 
 
b9e05b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

from src.basicchatbot.ui.streamlitui.loadui import StreamlitUILoader
from src.basicchatbot.ui.streamlitui.display_result import DisplayResultStreamlit
from src.basicchatbot.llms import get_llm
from src.basicchatbot.graph.graph_builder import GraphBuilder



def load_basic_chatbot():
    ui = StreamlitUILoader()
    user_input = ui.load_streamlit_ui()

    if not user_input:
        st.error("Error: Failed to load user input from the UI.")
        return
    
    user_message = st.chat_input(placeholder="Enter your message")

    if user_message:
        try:

            llm = get_llm(llm_name=user_input['selected_llm'], user_input=user_input)
            if not llm:
                st.error("Error: LLM model could not be initialized.")
                return
            
            usecase = user_input['selected_usecase']
            if not usecase:
                    st.error("Error: No use case selected.")
                    return
            
            
            try:
                graph_builder = GraphBuilder(model=llm)
                graph = graph_builder.setup_graph(usecase)
                if graph is None:
                    st.error("Error: Graph setup failed.")
                    return
                
                DisplayResultStreamlit(
                    usecase=usecase,
                    graph=graph,
                    user_message=user_message
                ).display_result_on_ui()

            except Exception as e:
                st.error(f"Error: Graph setup failed - {e}")
                return
            
        except Exception as e:
              raise ValueError(f"Error Occurred with Exception : {e}")