Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
from tools import *
|
| 7 |
from typing import TypedDict, Annotated
|
| 8 |
-
from langgraph.graph import START, StateGraph
|
| 9 |
from langgraph.graph.message import add_messages
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
from langchain_core.messages import AnyMessage, HumanMessage
|
|
@@ -33,12 +33,8 @@ tools = [
|
|
| 33 |
search_tool
|
| 34 |
]
|
| 35 |
chat_with_tools = chat.bind_tools(tools)
|
| 36 |
-
|
| 37 |
-
# Generate the AgentState and Agent graph
|
| 38 |
-
class AgentState(TypedDict):
|
| 39 |
-
messages: Annotated[list[AnyMessage], add_messages]
|
| 40 |
|
| 41 |
-
def assistant(state:
|
| 42 |
return {
|
| 43 |
"messages": [chat_with_tools.invoke(state["messages"])],
|
| 44 |
}
|
|
@@ -59,7 +55,7 @@ class BasicAgent:
|
|
| 59 |
return response
|
| 60 |
|
| 61 |
def _build_graph(self):
|
| 62 |
-
graph = StateGraph(
|
| 63 |
graph.add_node("assistant", assistant)
|
| 64 |
graph.add_node("tools", ToolNode(tools))
|
| 65 |
graph.add_edge(START, "assistant")
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from tools import *
|
| 7 |
from typing import TypedDict, Annotated
|
| 8 |
+
from langgraph.graph import START, StateGraph, MessagesState
|
| 9 |
from langgraph.graph.message import add_messages
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
from langchain_core.messages import AnyMessage, HumanMessage
|
|
|
|
| 33 |
search_tool
|
| 34 |
]
|
| 35 |
chat_with_tools = chat.bind_tools(tools)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
def assistant(state: MessagesState):
|
| 38 |
return {
|
| 39 |
"messages": [chat_with_tools.invoke(state["messages"])],
|
| 40 |
}
|
|
|
|
| 55 |
return response
|
| 56 |
|
| 57 |
def _build_graph(self):
|
| 58 |
+
graph = StateGraph(MessagesState)
|
| 59 |
graph.add_node("assistant", assistant)
|
| 60 |
graph.add_node("tools", ToolNode(tools))
|
| 61 |
graph.add_edge(START, "assistant")
|