Spaces:
Sleeping
Sleeping
Commit
Β·
f54fc8b
1
Parent(s):
143db94
partially sdlc
Browse files- src/langgraphagenticai/graph/graph_builder.py +21 -1
- src/langgraphagenticai/main.py +3 -0
- src/langgraphagenticai/node/sdlc_node.py +38 -0
- src/langgraphagenticai/state/state.py +18 -2
- src/langgraphagenticai/tools/customer_support_tools.py +4 -3
- src/langgraphagenticai/ui/streamlitui/display_result.py +16 -6
- src/langgraphagenticai/ui/streamlitui/loadui.py +34 -0
- src/langgraphagenticai/ui/uiconfigfile.ini +1 -1
src/langgraphagenticai/graph/graph_builder.py
CHANGED
|
@@ -3,6 +3,7 @@ from langgraph.prebuilt import tools_condition,ToolNode
|
|
| 3 |
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
import datetime
|
| 5 |
#module import
|
|
|
|
| 6 |
from src.langgraphagenticai.node.ai_news_node import AINewsNode
|
| 7 |
from src.langgraphagenticai.node import travel_planner_node
|
| 8 |
from src.langgraphagenticai.node.customer_support_chatbot import Customer_Support_Bot
|
|
@@ -10,7 +11,7 @@ from src.langgraphagenticai.tools.customtool import book_appointment, cancel_app
|
|
| 10 |
from src.langgraphagenticai.tools.search_tool import create_tool_node, get_tools
|
| 11 |
from src.langgraphagenticai.node.chatbot_with_tool_node import ChatbotWithToolNode
|
| 12 |
from src.langgraphagenticai.node.basic_chatbot_node import BasicChatbotNode
|
| 13 |
-
from src.langgraphagenticai.state.state import State
|
| 14 |
from src.langgraphagenticai.node.travel_planner_node import TravelPlannerNode
|
| 15 |
|
| 16 |
class GraphBuilder:
|
|
@@ -20,6 +21,7 @@ class GraphBuilder:
|
|
| 20 |
def __init__(self,model):
|
| 21 |
self.llm = model
|
| 22 |
self.graph_builder = StateGraph(State)
|
|
|
|
| 23 |
|
| 24 |
def basic_chatbot_build_graph(self):
|
| 25 |
"""
|
|
@@ -148,6 +150,22 @@ class GraphBuilder:
|
|
| 148 |
self.graph_builder.add_edge("fetch_news", "summarize_news")
|
| 149 |
self.graph_builder.add_edge("summarize_news", "save_result")
|
| 150 |
self.graph_builder.add_edge("save_result", END)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
def setup_graph(self, usecase: str):
|
| 153 |
"""
|
|
@@ -165,6 +183,8 @@ class GraphBuilder:
|
|
| 165 |
self.customer_support_build_graph()
|
| 166 |
elif usecase =="AI News":
|
| 167 |
self.ai_news_build_graph()
|
|
|
|
|
|
|
| 168 |
else:
|
| 169 |
raise ValueError("Invalid use case selected.")
|
| 170 |
return self.graph_builder.compile()
|
|
|
|
| 3 |
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
import datetime
|
| 5 |
#module import
|
| 6 |
+
from src.langgraphagenticai.node.sdlc_node import SDLCNode
|
| 7 |
from src.langgraphagenticai.node.ai_news_node import AINewsNode
|
| 8 |
from src.langgraphagenticai.node import travel_planner_node
|
| 9 |
from src.langgraphagenticai.node.customer_support_chatbot import Customer_Support_Bot
|
|
|
|
| 11 |
from src.langgraphagenticai.tools.search_tool import create_tool_node, get_tools
|
| 12 |
from src.langgraphagenticai.node.chatbot_with_tool_node import ChatbotWithToolNode
|
| 13 |
from src.langgraphagenticai.node.basic_chatbot_node import BasicChatbotNode
|
| 14 |
+
from src.langgraphagenticai.state.state import State , SDLCState
|
| 15 |
from src.langgraphagenticai.node.travel_planner_node import TravelPlannerNode
|
| 16 |
|
| 17 |
class GraphBuilder:
|
|
|
|
| 21 |
def __init__(self,model):
|
| 22 |
self.llm = model
|
| 23 |
self.graph_builder = StateGraph(State)
|
| 24 |
+
self.sdlc_graph_builder = StateGraph(SDLCState)
|
| 25 |
|
| 26 |
def basic_chatbot_build_graph(self):
|
| 27 |
"""
|
|
|
|
| 150 |
self.graph_builder.add_edge("fetch_news", "summarize_news")
|
| 151 |
self.graph_builder.add_edge("summarize_news", "save_result")
|
| 152 |
self.graph_builder.add_edge("save_result", END)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def sdlc_workflow_build_graph(self):
|
| 156 |
+
|
| 157 |
+
sdlc_wf_node = SDLCNode(self.llm)
|
| 158 |
+
|
| 159 |
+
self.graph_builder = self.sdlc_graph_builder
|
| 160 |
+
|
| 161 |
+
self.graph_builder.add_node("generate_user_stories", sdlc_wf_node.generate_user_stories)
|
| 162 |
+
self.graph_builder.add_node("generate_code", sdlc_wf_node.generate_code)
|
| 163 |
+
|
| 164 |
+
self.graph_builder.set_entry_point("generate_user_stories")
|
| 165 |
+
self.graph_builder.add_edge("generate_user_stories", "generate_code")
|
| 166 |
+
self.graph_builder.add_edge("generate_code", END)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
|
| 170 |
def setup_graph(self, usecase: str):
|
| 171 |
"""
|
|
|
|
| 183 |
self.customer_support_build_graph()
|
| 184 |
elif usecase =="AI News":
|
| 185 |
self.ai_news_build_graph()
|
| 186 |
+
elif usecase =="SDLC Workflow":
|
| 187 |
+
self.sdlc_workflow_build_graph()
|
| 188 |
else:
|
| 189 |
raise ValueError("Invalid use case selected.")
|
| 190 |
return self.graph_builder.compile()
|
src/langgraphagenticai/main.py
CHANGED
|
@@ -7,6 +7,7 @@ import streamlit as st
|
|
| 7 |
import json
|
| 8 |
|
| 9 |
|
|
|
|
| 10 |
# MAIN Function START
|
| 11 |
def load_langgraph_agenticai_app():
|
| 12 |
"""
|
|
@@ -28,6 +29,8 @@ def load_langgraph_agenticai_app():
|
|
| 28 |
# Text input for user message
|
| 29 |
if st.session_state.IsFetchButtonClicked:
|
| 30 |
user_message = st.session_state.timeframe
|
|
|
|
|
|
|
| 31 |
else :
|
| 32 |
user_message = st.chat_input("Enter your message:")
|
| 33 |
if user_message:
|
|
|
|
| 7 |
import json
|
| 8 |
|
| 9 |
|
| 10 |
+
|
| 11 |
# MAIN Function START
|
| 12 |
def load_langgraph_agenticai_app():
|
| 13 |
"""
|
|
|
|
| 29 |
# Text input for user message
|
| 30 |
if st.session_state.IsFetchButtonClicked:
|
| 31 |
user_message = st.session_state.timeframe
|
| 32 |
+
elif st.session_state.IsSDLC :
|
| 33 |
+
user_message = st.session_state.state
|
| 34 |
else :
|
| 35 |
user_message = st.chat_input("Enter your message:")
|
| 36 |
if user_message:
|
src/langgraphagenticai/node/sdlc_node.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
class SDLCNode:
|
| 4 |
+
def __init__(self, llm):
|
| 5 |
+
self.llm = llm
|
| 6 |
+
|
| 7 |
+
def generate_user_stories(self, state: dict) -> dict:
|
| 8 |
+
prompt = f"""
|
| 9 |
+
Generate comprehensive user stories based on the following requirements:
|
| 10 |
+
{state['requirements']}
|
| 11 |
+
|
| 12 |
+
{f"PO Feedback to incorporate: {state['po_feedback']}" if state.get('po_feedback') else ""}
|
| 13 |
+
|
| 14 |
+
Format the user stories in Markdown with clear acceptance criteria.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
response = self.llm.invoke(prompt)
|
| 18 |
+
|
| 19 |
+
st.session_state.state["user_stories"] = response.content
|
| 20 |
+
st.session_state.state["current_step"] = "po_approval"
|
| 21 |
+
return {"user_stories": response.content, "current_step": "po_approval"}
|
| 22 |
+
|
| 23 |
+
def po_approval(self, state: dict) -> dict:
|
| 24 |
+
return {"current_step": "po_approval"}
|
| 25 |
+
|
| 26 |
+
def generate_code(self, state: dict) -> dict:
|
| 27 |
+
prompt = f"""
|
| 28 |
+
Generate production-quality code based on these user stories:
|
| 29 |
+
{state['user_stories']}
|
| 30 |
+
|
| 31 |
+
{f"Review Feedback to incorporate: {state['review_feedback']}" if state.get('review_feedback') else ""}
|
| 32 |
+
|
| 33 |
+
Include proper error handling, comments, and follow best practices.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
response = self.llm.invoke(prompt)
|
| 37 |
+
st.session_state.state["generated_code"] = response.content
|
| 38 |
+
return {"generated_code": response.content, "current_step": "code_review"}
|
src/langgraphagenticai/state/state.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from typing import Annotated
|
| 2 |
from typing_extensions import TypedDict
|
| 3 |
from langgraph.graph.message import add_messages
|
| 4 |
from typing import TypedDict, Annotated, List
|
|
@@ -17,4 +17,20 @@ class PlannerState(TypedDict):
|
|
| 17 |
interests: List[str]
|
| 18 |
itinerary: str
|
| 19 |
start_date: str
|
| 20 |
-
end_date: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 17 |
interests: List[str]
|
| 18 |
itinerary: str
|
| 19 |
start_date: str
|
| 20 |
+
end_date: str
|
| 21 |
+
|
| 22 |
+
class SDLCState(TypedDict):
|
| 23 |
+
current_step: Literal[
|
| 24 |
+
"requirements",
|
| 25 |
+
"generate_user_stories",
|
| 26 |
+
"po_approval",
|
| 27 |
+
"generate_code",
|
| 28 |
+
"code_review",
|
| 29 |
+
"completed"
|
| 30 |
+
]
|
| 31 |
+
requirements: Optional[str]
|
| 32 |
+
user_stories: Optional[str]
|
| 33 |
+
po_feedback: Optional[str]
|
| 34 |
+
generated_code: Optional[str]
|
| 35 |
+
review_feedback: Optional[str]
|
| 36 |
+
decision: Optional[Literal["approved", "feedback"]]
|
src/langgraphagenticai/tools/customer_support_tools.py
CHANGED
|
@@ -4,7 +4,8 @@ import json
|
|
| 4 |
|
| 5 |
from src.langgraphagenticai.vectorstores.vectore_store import FlowerShopVectorStore
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
INVENTORY_FILE_PATH = './data/inventory.json'
|
| 9 |
|
| 10 |
customers_database = [
|
|
@@ -101,7 +102,7 @@ def query_knowledge_base(query: str) -> List[Dict[str, str]]:
|
|
| 101 |
Return:
|
| 102 |
List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
|
| 103 |
"""
|
| 104 |
-
return vector_store.query_faqs(query=query)
|
| 105 |
|
| 106 |
|
| 107 |
|
|
@@ -120,7 +121,7 @@ def search_for_product_reccommendations(description: str):
|
|
| 120 |
Return:
|
| 121 |
List[Dict[str, str]]: Potentially relevant products
|
| 122 |
"""
|
| 123 |
-
return vector_store.query_inventories(query=description)
|
| 124 |
|
| 125 |
@tool
|
| 126 |
def retrieve_existing_customer_orders(customer_id: str) -> List[Dict]:
|
|
|
|
| 4 |
|
| 5 |
from src.langgraphagenticai.vectorstores.vectore_store import FlowerShopVectorStore
|
| 6 |
|
| 7 |
+
|
| 8 |
+
|
| 9 |
INVENTORY_FILE_PATH = './data/inventory.json'
|
| 10 |
|
| 11 |
customers_database = [
|
|
|
|
| 102 |
Return:
|
| 103 |
List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
|
| 104 |
"""
|
| 105 |
+
return FlowerShopVectorStore().vector_store.query_faqs(query=query)
|
| 106 |
|
| 107 |
|
| 108 |
|
|
|
|
| 121 |
Return:
|
| 122 |
List[Dict[str, str]]: Potentially relevant products
|
| 123 |
"""
|
| 124 |
+
return FlowerShopVectorStore().vector_store.query_inventories(query=description)
|
| 125 |
|
| 126 |
@tool
|
| 127 |
def retrieve_existing_customer_orders(customer_id: str) -> List[Dict]:
|
src/langgraphagenticai/ui/streamlitui/display_result.py
CHANGED
|
@@ -87,7 +87,6 @@ class DisplayResultStreamlit:
|
|
| 87 |
st.write(customers_database)
|
| 88 |
st.title('data protection checks')
|
| 89 |
st.write(data_protection_checks)
|
| 90 |
-
|
| 91 |
elif usecase == "AI News":
|
| 92 |
frequency = self.user_message
|
| 93 |
with st.spinner("Fetching and summarizing news... β³"):
|
|
@@ -114,11 +113,22 @@ class DisplayResultStreamlit:
|
|
| 114 |
mime="text/markdown"
|
| 115 |
)
|
| 116 |
st.success(f"β
Summary saved to {AI_NEWS_PATH}")
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
def _display_travel_planner_results(self):
|
| 124 |
# Extract travel parameters from message
|
|
|
|
| 87 |
st.write(customers_database)
|
| 88 |
st.title('data protection checks')
|
| 89 |
st.write(data_protection_checks)
|
|
|
|
| 90 |
elif usecase == "AI News":
|
| 91 |
frequency = self.user_message
|
| 92 |
with st.spinner("Fetching and summarizing news... β³"):
|
|
|
|
| 113 |
mime="text/markdown"
|
| 114 |
)
|
| 115 |
st.success(f"β
Summary saved to {AI_NEWS_PATH}")
|
| 116 |
+
|
| 117 |
+
elif usecase == "SDLC Workflow":
|
| 118 |
+
initial_state = self.user_message
|
| 119 |
+
# Invoke the workflow node for generating user stories
|
| 120 |
+
result = graph.invoke(initial_state)
|
| 121 |
+
if 'user_stories' in result:
|
| 122 |
+
with st.expander('generated userstories'):
|
| 123 |
+
st.markdown(result["user_stories"])
|
| 124 |
+
if 'generated_code' in result:
|
| 125 |
+
with st.expander('generated code'):
|
| 126 |
+
st.markdown(result['generated_code'])
|
| 127 |
+
|
| 128 |
+
# display graph
|
| 129 |
+
if graph:
|
| 130 |
+
st.write('state graph - workflow')
|
| 131 |
+
st.image(graph.get_graph(xray=True).draw_mermaid_png())
|
| 132 |
|
| 133 |
def _display_travel_planner_results(self):
|
| 134 |
# Extract travel parameters from message
|
src/langgraphagenticai/ui/streamlitui/loadui.py
CHANGED
|
@@ -10,13 +10,36 @@ class LoadStreamlitUI:
|
|
| 10 |
def __init__(self):
|
| 11 |
self.config = Config() # config
|
| 12 |
self.user_controls = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def load_streamlit_ui(self):
|
| 16 |
st.set_page_config(page_title= "π€ " + self.config.get_page_title(), layout="wide")
|
| 17 |
st.header("π€ " + self.config.get_page_title())
|
| 18 |
st.session_state.timeframe = ''
|
| 19 |
st.session_state.IsFetchButtonClicked = False
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
|
|
@@ -117,4 +140,15 @@ class LoadStreamlitUI:
|
|
| 117 |
else :
|
| 118 |
st.session_state.IsFetchButtonClicked = False
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
return self.user_controls
|
|
|
|
| 10 |
def __init__(self):
|
| 11 |
self.config = Config() # config
|
| 12 |
self.user_controls = {}
|
| 13 |
+
|
| 14 |
+
def initialize_session(self):
|
| 15 |
+
return {
|
| 16 |
+
"current_step": "requirements",
|
| 17 |
+
"requirements": "",
|
| 18 |
+
"user_stories": "",
|
| 19 |
+
"po_feedback": "",
|
| 20 |
+
"generated_code": "",
|
| 21 |
+
"review_feedback": "",
|
| 22 |
+
"decision": None
|
| 23 |
+
}
|
| 24 |
|
| 25 |
+
def render_requirements(self):
|
| 26 |
+
st.markdown("## π Requirements Submission")
|
| 27 |
+
st.session_state.state["requirements"] = st.text_area(
|
| 28 |
+
"Enter your requirements:",
|
| 29 |
+
height=200,
|
| 30 |
+
key="req_input"
|
| 31 |
+
)
|
| 32 |
+
if st.button("Submit Requirements", key="submit_req"):
|
| 33 |
+
st.session_state.state["current_step"] = "generate_user_stories"
|
| 34 |
+
st.session_state.IsSDLC = True
|
| 35 |
+
|
| 36 |
|
| 37 |
def load_streamlit_ui(self):
|
| 38 |
st.set_page_config(page_title= "π€ " + self.config.get_page_title(), layout="wide")
|
| 39 |
st.header("π€ " + self.config.get_page_title())
|
| 40 |
st.session_state.timeframe = ''
|
| 41 |
st.session_state.IsFetchButtonClicked = False
|
| 42 |
+
st.session_state.IsSDLC = False
|
| 43 |
|
| 44 |
|
| 45 |
|
|
|
|
| 140 |
else :
|
| 141 |
st.session_state.IsFetchButtonClicked = False
|
| 142 |
|
| 143 |
+
|
| 144 |
+
# Added for SDLC Workflow
|
| 145 |
+
elif self.user_controls['selected_usecase']=="SDLC Workflow":
|
| 146 |
+
st.subheader(" SDLC Workflow ")
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
if "state" not in st.session_state:
|
| 150 |
+
st.session_state.state = self.initialize_session()
|
| 151 |
+
self.render_requirements()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
return self.user_controls
|
src/langgraphagenticai/ui/uiconfigfile.ini
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
[DEFAULT]
|
| 2 |
PAGE_TITLE = LangGraph: Build Stateful Agentic AI graph
|
| 3 |
LLM_OPTIONS = Groq
|
| 4 |
-
USECASE_OPTIONS = Basic Chatbot, Chatbot with Tool, Travel Planner, AI News, Appointment Receptionist, Customer Support
|
| 5 |
GROQ_MODEL_OPTIONS = mixtral-8x7b-32768, llama3-8b-8192, llama3-70b-8192, gemma-7b-i
|
| 6 |
|
|
|
|
| 1 |
[DEFAULT]
|
| 2 |
PAGE_TITLE = LangGraph: Build Stateful Agentic AI graph
|
| 3 |
LLM_OPTIONS = Groq
|
| 4 |
+
USECASE_OPTIONS = Basic Chatbot, Chatbot with Tool, Travel Planner, AI News, SDLC Workflow, Appointment Receptionist, Customer Support
|
| 5 |
GROQ_MODEL_OPTIONS = mixtral-8x7b-32768, llama3-8b-8192, llama3-70b-8192, gemma-7b-i
|
| 6 |
|