Spaces:
Sleeping
Sleeping
apple muncy
commited on
Commit
·
ed0ec2e
1
Parent(s):
dbd637b
added @tool
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from typing import TypedDict, Annotated
|
2 |
from langgraph.graph.message import add_messages
|
3 |
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage, SystemMessage
|
|
|
4 |
from langgraph.prebuilt import ToolNode
|
5 |
from langgraph.graph import START, StateGraph
|
6 |
from langgraph.prebuilt import tools_condition
|
@@ -32,15 +33,16 @@ chat = ChatOllama(model="qwen2:7b",
|
|
32 |
|
33 |
# Define available tools
|
34 |
tools = [
|
35 |
-
load_guest_dataset,
|
36 |
-
search_tool,
|
37 |
weather_info_tool,
|
38 |
-
hub_stats_tool
|
39 |
]
|
40 |
|
41 |
# Bind tools to the chat model
|
42 |
chat_with_tools = chat.bind_tools(tools)
|
43 |
|
|
|
44 |
# Generate the AgentState and Agent graph
|
45 |
class AgentState(TypedDict):
|
46 |
messages: Annotated[list[AnyMessage], add_messages]
|
@@ -62,7 +64,7 @@ builder = StateGraph(AgentState)
|
|
62 |
|
63 |
# Define nodes: these do the work
|
64 |
builder.add_node("assistant", assistant)
|
65 |
-
builder.add_node("tools",
|
66 |
|
67 |
# Define edges: these determine how the control flow moves
|
68 |
builder.add_edge(START, "assistant")
|
@@ -102,4 +104,4 @@ with gr.Blocks() as demo:
|
|
102 |
send_btn.click(fn=chat_fn, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
103 |
|
104 |
if __name__ == "__main__":
|
105 |
-
demo.launch()
|
|
|
1 |
from typing import TypedDict, Annotated
|
2 |
from langgraph.graph.message import add_messages
|
3 |
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage, SystemMessage
|
4 |
+
from langchain_core.tools import tool
|
5 |
from langgraph.prebuilt import ToolNode
|
6 |
from langgraph.graph import START, StateGraph
|
7 |
from langgraph.prebuilt import tools_condition
|
|
|
33 |
|
34 |
# Define available tools
|
35 |
tools = [
|
36 |
+
# load_guest_dataset,
|
37 |
+
# search_tool,
|
38 |
weather_info_tool,
|
39 |
+
# hub_stats_tool
|
40 |
]
|
41 |
|
42 |
# Bind tools to the chat model
|
43 |
chat_with_tools = chat.bind_tools(tools)
|
44 |
|
45 |
+
toolnode =ToolNode(Tools)
|
46 |
# Generate the AgentState and Agent graph
|
47 |
class AgentState(TypedDict):
|
48 |
messages: Annotated[list[AnyMessage], add_messages]
|
|
|
64 |
|
65 |
# Define nodes: these do the work
|
66 |
builder.add_node("assistant", assistant)
|
67 |
+
builder.add_node("tools", toolnode)
|
68 |
|
69 |
# Define edges: these determine how the control flow moves
|
70 |
builder.add_edge(START, "assistant")
|
|
|
104 |
send_btn.click(fn=chat_fn, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
+
demo.launch()
|
tools.py
CHANGED
@@ -7,7 +7,7 @@ from langchain.tools import Tool
|
|
7 |
|
8 |
|
9 |
search_tool = DuckDuckGoSearchRun()
|
10 |
-
|
11 |
def get_weather_info(location: str) -> str:
|
12 |
"""Fetches dummy weather information for a given location."""
|
13 |
# Dummy weather data
|
|
|
7 |
|
8 |
|
9 |
search_tool = DuckDuckGoSearchRun()
|
10 |
+
@tool
|
11 |
def get_weather_info(location: str) -> str:
|
12 |
"""Fetches dummy weather information for a given location."""
|
13 |
# Dummy weather data
|