Spaces:
Build error
Build error
File size: 1,587 Bytes
58459b2 | 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 | from src.langgraphagenticai.state.state import State
class ChatbotWithToolNode:
"""
chatbot logic enhanced with tool integration
"""
def __init__(self, model):
self.llm = model
def process(self, state: State) -> dict:
"""
Processes the input state and generates a response with tool integration.
"""
user_input = state["messages"][-1] if state["messages"] else ""
llm_response = self.llm.invoke([{"role": "user", "content": user_input}])
# simulate tool-specific logic
tools_response = f"Tool Integration for: '{user_input}'"
return {"messages": [llm_response, tools_response]}
def create_chatbot(self, tools):
"""
Returns a chatbot node function
"""
llm_with_tools = self.llm.bind_tools(tools)
def chatbot_node(state: State):
"""
Chatbot logic for processing the input state and returning a response
"""
return {"messages": [llm_with_tools.invoke(state["messages"])]}
return chatbot_node
# def chatbot_node(state: State, llm_with_tools):
# """
# Chatbot logic for processing the input state and returning a response
# """
# return {"messages": [llm_with_tools.invoke(state["messages"])]}
# def create_chatbot(self, tools):
# """
# Returns a chatbot node function
# """
# llm_with_tools = self.llm.bind_tools(tools)
# chatbot_node = self.chatbot_node(State, llm_with_tools)
# return chatbot_node |