apple muncy commited on
Commit
18b52d2
·
1 Parent(s): 7284448

reverting tools.py and app.py

Browse files

Signed-off-by: apple muncy <[email protected]>

Files changed (2) hide show
  1. app.py +5 -7
  2. tools.py +7 -6
app.py CHANGED
@@ -1,7 +1,6 @@
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,16 +32,15 @@ chat = ChatOllama(model="qwen2:7b",
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,7 +62,7 @@ builder = StateGraph(AgentState)
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,4 +102,4 @@ with gr.Blocks() as demo:
104
  send_btn.click(fn=chat_fn, inputs=[msg, chatbot], outputs=[chatbot, msg])
105
 
106
  if __name__ == "__main__":
107
- 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 langgraph.prebuilt import ToolNode
5
  from langgraph.graph import START, StateGraph
6
  from langgraph.prebuilt import tools_condition
 
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
 
63
  # Define nodes: these do the work
64
  builder.add_node("assistant", assistant)
65
+ builder.add_node("tools", ToolNode(tools))
66
 
67
  # Define edges: these determine how the control flow moves
68
  builder.add_edge(START, "assistant")
 
102
  send_btn.click(fn=chat_fn, inputs=[msg, chatbot], outputs=[chatbot, msg])
103
 
104
  if __name__ == "__main__":
105
+ demo.launch()
tools.py CHANGED
@@ -1,13 +1,16 @@
 
 
1
  from langchain_community.tools import DuckDuckGoSearchRun
2
  import random
 
 
3
 
4
- from langchain_core.tools import tool
5
 
6
  # Initialize the DuckDuckGo search tool
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
@@ -21,7 +24,7 @@ def get_weather_info(location: str) -> str:
21
  return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
22
 
23
  # Initialize the tool
24
- weather_info_tool = tool(
25
  name="get_weather_info",
26
  func=get_weather_info,
27
  description="Fetches dummy weather information for a given location."
@@ -47,6 +50,4 @@ hub_stats_tool = Tool(
47
  name="get_hub_stats",
48
  func=get_hub_stats,
49
  description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
50
- )
51
-
52
-
 
1
+ #from smolagents import DuckDuckGoSearchTool
2
+ #from smolagents import Tool
3
  from langchain_community.tools import DuckDuckGoSearchRun
4
  import random
5
+ from huggingface_hub import list_models
6
+ from langchain.tools import Tool
7
 
 
8
 
9
  # Initialize the DuckDuckGo search tool
10
 
11
 
12
  search_tool = DuckDuckGoSearchRun()
13
+
14
  def get_weather_info(location: str) -> str:
15
  """Fetches dummy weather information for a given location."""
16
  # Dummy weather data
 
24
  return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
25
 
26
  # Initialize the tool
27
+ weather_info_tool = Tool(
28
  name="get_weather_info",
29
  func=get_weather_info,
30
  description="Fetches dummy weather information for a given location."
 
50
  name="get_hub_stats",
51
  func=get_hub_stats,
52
  description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
53
+ )