DarkRodry commited on
Commit
fca0e83
Β·
1 Parent(s): 2dfaba1

more tools

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. tools.py +46 -1
app.py CHANGED
@@ -8,7 +8,7 @@ from langgraph.graph import START, StateGraph
8
  from langgraph.prebuilt import tools_condition
9
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
10
 
11
- from tools import guest_info_tool
12
 
13
  # Generate the chat interface, including the tools
14
  llm = HuggingFaceEndpoint(
@@ -17,7 +17,7 @@ llm = HuggingFaceEndpoint(
17
  )
18
 
19
  chat = ChatHuggingFace(llm=llm, verbose=True)
20
- tools = [guest_info_tool]
21
  chat_with_tools = chat.bind_tools(tools)
22
 
23
  # Generate the AgentState and Agent graph
@@ -47,7 +47,7 @@ builder.add_conditional_edges(
47
  builder.add_edge("tools", "assistant")
48
  alfred = builder.compile()
49
 
50
- messages = [HumanMessage(content="Tell me about our guest named 'Lady Ada Lovelace'.")]
51
  response = alfred.invoke({"messages": messages})
52
 
53
  print("🎩 Alfred's Response:")
 
8
  from langgraph.prebuilt import tools_condition
9
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
10
 
11
+ from tools import *
12
 
13
  # Generate the chat interface, including the tools
14
  llm = HuggingFaceEndpoint(
 
17
  )
18
 
19
  chat = ChatHuggingFace(llm=llm, verbose=True)
20
+ tools = [search_tool, weather_info_tool, hub_stats_tool]
21
  chat_with_tools = chat.bind_tools(tools)
22
 
23
  # Generate the AgentState and Agent graph
 
47
  builder.add_edge("tools", "assistant")
48
  alfred = builder.compile()
49
 
50
+ messages = [HumanMessage(content="Who is Facebook and what's their most popular model?")]
51
  response = alfred.invoke({"messages": messages})
52
 
53
  print("🎩 Alfred's Response:")
tools.py CHANGED
@@ -1,5 +1,8 @@
 
1
  from langchain_community.retrievers import BM25Retriever
2
  from langchain.tools import Tool
 
 
3
 
4
  from retriever import docs
5
 
@@ -17,4 +20,46 @@ guest_info_tool = Tool(
17
  name="guest_info_retriever",
18
  func=extract_text,
19
  description="Retrieves detailed information about gala guests based on their name or relation."
20
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
  from langchain_community.retrievers import BM25Retriever
3
  from langchain.tools import Tool
4
+ from huggingface_hub import list_models
5
+ from langchain_community.tools import DuckDuckGoSearchRun
6
 
7
  from retriever import docs
8
 
 
20
  name="guest_info_retriever",
21
  func=extract_text,
22
  description="Retrieves detailed information about gala guests based on their name or relation."
23
+ )
24
+
25
+ def get_weather_info(location: str) -> str:
26
+ """Fetches dummy weather information for a given location."""
27
+ # Dummy weather data
28
+ weather_conditions = [
29
+ {"condition": "Rainy", "temp_c": 15},
30
+ {"condition": "Clear", "temp_c": 25},
31
+ {"condition": "Windy", "temp_c": 20}
32
+ ]
33
+ # Randomly select a weather condition
34
+ data = random.choice(weather_conditions)
35
+ return f"Weather in {location}: {data['condition']}, {data['temp_c']}Β°C"
36
+
37
+ # Initialize the tool
38
+ weather_info_tool = Tool(
39
+ name="get_weather_info",
40
+ func=get_weather_info,
41
+ description="Fetches dummy weather information for a given location."
42
+ )
43
+
44
+ def get_hub_stats(author: str) -> str:
45
+ """Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
46
+ try:
47
+ # List models from the specified author, sorted by downloads
48
+ models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
49
+
50
+ if models:
51
+ model = models[0]
52
+ return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
53
+ else:
54
+ return f"No models found for author {author}."
55
+ except Exception as e:
56
+ return f"Error fetching models for {author}: {str(e)}"
57
+
58
+ # Initialize the tool
59
+ hub_stats_tool = Tool(
60
+ name="get_hub_stats",
61
+ func=get_hub_stats,
62
+ description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
63
+ )
64
+
65
+ search_tool = DuckDuckGoSearchRun()