sanket03 commited on
Commit
d63b69a
·
1 Parent(s): 14f1c62

added changes related to Chat bot with tool

Browse files
src/langgraphagenticai/graph/graph_builder.py CHANGED
@@ -3,6 +3,8 @@ 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
 
@@ -25,14 +27,47 @@ class GraphBuilder:
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
-
 
 
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
+ from src.langgraphagenticai.nodes.chatbot_with_Tool_node import ChatbotWithToolNode
7
+ from src.langgraphagenticai.tools.search_tool import get_tools,create_tool_node
8
 
9
 
10
 
 
27
  self.graph_builder.add_edge(START,"chatbot")
28
  self.graph_builder.add_edge("chatbot",END)
29
 
30
+
31
+ def chatbot_with_tools_build_graph(self):
32
+ """
33
+ Builds an advanced chatbot graph with tool integration.
34
+ This method creates a chatbot graph that includes both a chatbot node
35
+ and a tool node. It defines tools, initializes the chatbot with tool
36
+ capabilities, and sets up conditional and direct edges between nodes.
37
+ The chatbot node is set as the entry point.
38
+ """
39
+ ## Define the tool and tool node
40
+
41
+ tools=get_tools()
42
+ tool_node=create_tool_node(tools)
43
+
44
+ ##Define LLM
45
+ llm = self.llm
46
+
47
+ # Define chatbot node
48
+ obj_chatbot_with_node = ChatbotWithToolNode(llm)
49
+ chatbot_node = obj_chatbot_with_node.create_chatbot(tools)
50
+
51
+ # Add nodes
52
+ self.graph_builder.add_node("chatbot", chatbot_node)
53
+ self.graph_builder.add_node("tools", tool_node)
54
+
55
+ # Define conditional and direct edges
56
+ self.graph_builder.add_edge(START,"chatbot")
57
+ self.graph_builder.add_conditional_edges("chatbot", tools_condition)
58
+ self.graph_builder.add_edge("tools","chatbot")
59
+
60
+
61
+
62
+
63
  def setup_graph(self, usecase: str):
64
  """
65
  Sets up the graph for the selected use case.
66
  """
67
  if usecase == "Basic Chatbot":
68
  self.basic_chatbot_build_graph()
 
69
 
70
+ if usecase == "Chatbot with Tool":
71
+ self.chatbot_with_tools_build_graph()
72
+ return self.graph_builder.compile()
73
+