Team Ai
Apppublic

ankitpatil3003/Basic-AI-Chatbot-using-Langgraph

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
1likes
chatbot_with_Tool_node.py34 linesDownload Raw Back to nodes
1from src.langgraphagenticai.state.state import State2 3class ChatbotWithToolNode:4    """5    Chatbot logic enhanced with tool integration.6    """7    def __init__(self,model):8        self.llm = model9 10    def process(self, state: State) -> dict:11        """12        Processes the input state and generates a response with tool integration.13        """14        user_input = state["messages"][-1] if state["messages"] else ""15        llm_response = self.llm.invoke([{"role": "user", "content": user_input}])16 17        # Simulate tool-specific logic18        tools_response = f"Tool integration for: '{user_input}'"19 20        return {"messages": [llm_response, tools_response]}21    22    def create_chatbot(self, tools):23        """24        Returns a chatbot node function.25        """26        llm_with_tools = self.llm.bind_tools(tools)27 28        def chatbot_node(state: State):29            """30            Chatbot logic for processing the input state and returning a response.31            """32            return {"messages": [llm_with_tools.invoke(state["messages"])]}33 34        return chatbot_node