adding all parameters to run the UI
Browse files- requirements.txt +0 -1
- src/langgraph/UI/streamlit/displayresult.py +24 -0
- src/langgraph/UI/streamlit/loadui.py +59 -0
- src/langgraph/graph/graph_builder.py +38 -0
- src/langgraph/llm/groqllm.py +10 -0
- src/langgraph/main.py +58 -0
- src/langgraph/node/basic_chatbot.py +14 -0
- src/langgraph/state/state.py +11 -0
requirements.txt
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
langchain
|
| 2 |
openai
|
| 3 |
langGraph
|
| 4 |
-
langGraph-community
|
| 5 |
langchain-community
|
| 6 |
langchain-groq
|
| 7 |
langchain-openai
|
|
|
|
| 1 |
langchain
|
| 2 |
openai
|
| 3 |
langGraph
|
|
|
|
| 4 |
langchain-community
|
| 5 |
langchain-groq
|
| 6 |
langchain-openai
|
src/langgraph/UI/streamlit/displayresult.py
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_core.messages import HumanMessage,AIMessage
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class DisplayResultStreamlit:
|
| 7 |
+
def __init__(self,usecase,graph,user_message):
|
| 8 |
+
self.usecase= usecase
|
| 9 |
+
self.graph = graph
|
| 10 |
+
self.user_message = user_message
|
| 11 |
+
|
| 12 |
+
def display_result_on_ui(self):
|
| 13 |
+
usecase= self.usecase
|
| 14 |
+
graph = self.graph
|
| 15 |
+
user_message = self.user_message
|
| 16 |
+
if usecase =="Basic Chatbot":
|
| 17 |
+
for event in graph.stream({'messages':("user",user_message)}):
|
| 18 |
+
print(event.values())
|
| 19 |
+
for value in event.values():
|
| 20 |
+
print(value['messages'])
|
| 21 |
+
with st.chat_message("user"):
|
| 22 |
+
st.write(user_message)
|
| 23 |
+
with st.chat_message("assistant"):
|
| 24 |
+
st.write(value["messages"].content)
|
src/langgraph/UI/streamlit/loadui.py
CHANGED
|
@@ -10,3 +10,62 @@ class LoadStreamlitUI:
|
|
| 10 |
def __init__(self):
|
| 11 |
self.config = Config()
|
| 12 |
self.user_config = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def __init__(self):
|
| 11 |
self.config = Config()
|
| 12 |
self.user_config = {}
|
| 13 |
+
|
| 14 |
+
def initialize_state(self):
|
| 15 |
+
return {
|
| 16 |
+
"timeframe": "",
|
| 17 |
+
"current_step": "requirements",
|
| 18 |
+
"requirements": "",
|
| 19 |
+
"user_stories": "",
|
| 20 |
+
"IsFetchButtonClicked": False,
|
| 21 |
+
"Is_SDLC": False
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# def render_requirements(self):
|
| 25 |
+
# st.markdown("## Requirements Submission")
|
| 26 |
+
# st.session_state.state["requirements"] = st.text_area("Enter Your Requirements", height=100, key="get_requirements")
|
| 27 |
+
|
| 28 |
+
# if st.button("Submit Requirements", key="submit_requirements"):
|
| 29 |
+
# st.session_state["current_step"] = "generate_user_stories"
|
| 30 |
+
# st.session_state.IsSLDC = True
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def load_ui(self):
|
| 34 |
+
st.set_page_config(
|
| 35 |
+
page_title="👁" + self.config.get_page_title(),
|
| 36 |
+
#page_icon=self.config.get_page_icon(),
|
| 37 |
+
layout="wide"
|
| 38 |
+
)
|
| 39 |
+
st.header(self.config.get_page_title())
|
| 40 |
+
st.markdown("---")
|
| 41 |
+
st.session_state.timeframe = ''
|
| 42 |
+
st.session_state.IsFetchButtonClicked = False
|
| 43 |
+
st.session_state.Is_SDLC = False
|
| 44 |
+
|
| 45 |
+
with st.sidebar:
|
| 46 |
+
#Getting sidebar options from the config file
|
| 47 |
+
LLM_OPTIONS = self.config.get_llm_options()
|
| 48 |
+
USE_CASE_OPTIONS = self.config.get_usecase_options()
|
| 49 |
+
|
| 50 |
+
#Creating a dropdown for the LLM options
|
| 51 |
+
st.session_state.selected_llm = st.selectbox("Select LLM", LLM_OPTIONS)
|
| 52 |
+
|
| 53 |
+
if st.session_state.selected_llm == "Groq":
|
| 54 |
+
model = self.config.get_groq_model()
|
| 55 |
+
st.session_state.selected_model = st.selectbox("Select Model", model)
|
| 56 |
+
st.session_state.selected_model_api_key = st.text_input("Enter API Key", type="password")
|
| 57 |
+
|
| 58 |
+
#validating the API key
|
| 59 |
+
if not st.session_state.selected_model_api_key:
|
| 60 |
+
st.error("Please enter the correct API key. refer : https://console.groq.com/keys")
|
| 61 |
+
|
| 62 |
+
#Creating a dropdown for the use case options
|
| 63 |
+
st.session_state.selected_usecase = st.selectbox("Select Use Case", USE_CASE_OPTIONS)
|
| 64 |
+
|
| 65 |
+
if "state" not in st.session_state:
|
| 66 |
+
st.session_state.state = self.initialize_state()
|
| 67 |
+
#self.render_requirements()
|
| 68 |
+
|
| 69 |
+
return self.user_controls
|
| 70 |
+
|
| 71 |
+
|
src/langgraph/graph/graph_builder.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, START,END, MessagesState
|
| 2 |
+
from langgraph.prebuilt import tools_condition,ToolNode
|
| 3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
+
from src.langgraphagenticai.state.state import State
|
| 5 |
+
from src.langgraphagenticai.nodes.basic_chatbot_node import BasicChatbotNode
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class GraphBuilder:
|
| 11 |
+
|
| 12 |
+
def __init__(self,model):
|
| 13 |
+
self.llm=model
|
| 14 |
+
self.graph_builder=StateGraph(State)
|
| 15 |
+
|
| 16 |
+
def basic_chatbot_build_graph(self):
|
| 17 |
+
"""
|
| 18 |
+
Builds a basic chatbot graph using LangGraph.
|
| 19 |
+
This method initializes a chatbot node using the `BasicChatbotNode` class
|
| 20 |
+
and integrates it into the graph. The chatbot node is set as both the
|
| 21 |
+
entry and exit point of the graph.
|
| 22 |
+
"""
|
| 23 |
+
self.basic_chatbot_node=BasicChatbotNode(self.llm)
|
| 24 |
+
self.graph_builder.add_node("chatbot",self.basic_chatbot_node.process)
|
| 25 |
+
self.graph_builder.add_edge(START,"chatbot")
|
| 26 |
+
self.graph_builder.add_edge("chatbot",END)
|
| 27 |
+
|
| 28 |
+
def setup_graph(self, usecase: str):
|
| 29 |
+
"""
|
| 30 |
+
Sets up the graph for the selected use case.
|
| 31 |
+
"""
|
| 32 |
+
if usecase == "Basic Chatbot":
|
| 33 |
+
self.basic_chatbot_build_graph()
|
| 34 |
+
return self.graph_builder.compile()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
src/langgraph/llm/groqllm.py
CHANGED
|
@@ -10,3 +10,13 @@ class GroqLLM:
|
|
| 10 |
try:
|
| 11 |
groq_api_key = self.user_controls_input["groq_api_key"]
|
| 12 |
selected_groq_model = self.user_controls_input["selected_groq_models"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
groq_api_key = self.user_controls_input["groq_api_key"]
|
| 12 |
selected_groq_model = self.user_controls_input["selected_groq_models"]
|
| 13 |
+
|
| 14 |
+
if not groq_api_key:
|
| 15 |
+
st.error("Please enter the Groq API Key")
|
| 16 |
+
|
| 17 |
+
llm = ChatGroq(api_key=groq_api_key, model=selected_groq_model)
|
| 18 |
+
|
| 19 |
+
except Exception as e:
|
| 20 |
+
st.error(f"Error in getting the Groq API Key: {e}", e)
|
| 21 |
+
|
| 22 |
+
return llm
|
src/langgraph/main.py
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
from src.langgraph.UI.streamlit.loadui import LoadStreamlitUI
|
| 4 |
+
from src.langgraph.llm.groqllm import GroqLLM
|
| 5 |
+
from src.langgraph.graph.graph_builder import GraphBuilder
|
| 6 |
+
from src.langgraph.UI.streamlit.displayresult import DisplayResultStreamlit
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def __main__():
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
Loads and runs the LangGranph Agentic AI POC application.
|
| 13 |
+
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
#load the UI
|
| 17 |
+
ui = LoadStreamlitUI()
|
| 18 |
+
user_input = ui.load_ui()
|
| 19 |
+
|
| 20 |
+
if not user_input:
|
| 21 |
+
st.error("Please enter the requirements and click on the button to generate the SDLC")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
#Test input for user message state
|
| 25 |
+
if st.session_state.IsFetchButtonClicked:
|
| 26 |
+
user_message = st.session_state.state.timeframe
|
| 27 |
+
else:
|
| 28 |
+
user_message = st.chat_input("Enter your message here...")
|
| 29 |
+
|
| 30 |
+
#Initialize the LLM
|
| 31 |
+
if user_message:
|
| 32 |
+
try:
|
| 33 |
+
llm = GroqLLM(user_controls_input=user_input)
|
| 34 |
+
model = llm.get_llm_model()
|
| 35 |
+
|
| 36 |
+
if not model:
|
| 37 |
+
st.error("Failed to initialize the LLM model")
|
| 38 |
+
return
|
| 39 |
+
|
| 40 |
+
#select use-case
|
| 41 |
+
use_case = user_input.get("selected_use_case")
|
| 42 |
+
if not use_case:
|
| 43 |
+
st.error("No Use Case Selected")
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
#Graph Builder
|
| 47 |
+
graph_builder = GraphBuilder(llm=model, use_case=use_case)
|
| 48 |
+
try:
|
| 49 |
+
graph = graph_builder.setup_graph(usecase)
|
| 50 |
+
DisplayResultStreamlit(usecase,graph,user_message).display_result_on_ui()
|
| 51 |
+
except Exception as e:
|
| 52 |
+
st.error(f"Error: Graph setup failed - {e}")
|
| 53 |
+
return
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
raise ValueError(f"Error Occurred with Exception : {e}")
|
| 58 |
+
|
src/langgraph/node/basic_chatbot.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.langgraph.state.state import State
|
| 2 |
+
|
| 3 |
+
class BasicChatbotNode:
|
| 4 |
+
"""
|
| 5 |
+
Basic chatbot logic implementation.
|
| 6 |
+
"""
|
| 7 |
+
def __init__(self,model):
|
| 8 |
+
self.llm = model
|
| 9 |
+
|
| 10 |
+
def process(self, state: State) -> dict:
|
| 11 |
+
"""
|
| 12 |
+
Processes the input state and generates a chatbot response.
|
| 13 |
+
"""
|
| 14 |
+
return {"messages":self.llm.invoke(state['messages'])}
|
src/langgraph/state/state.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Annotated, Literal, Optional
|
| 2 |
+
from typing_extensions import TypedDict
|
| 3 |
+
from langgraph.graph.message import add_messages
|
| 4 |
+
from typing import TypedDict, Annotated, List
|
| 5 |
+
from langchain_core.messages import HumanMessage, AIMessage
|
| 6 |
+
|
| 7 |
+
class State(TypedDict):
|
| 8 |
+
"""
|
| 9 |
+
Represents the structure of the state used in the graph.
|
| 10 |
+
"""
|
| 11 |
+
messages: Annotated[list, add_messages]
|