anupom100 commited on
Commit
06e57c6
·
verified ·
1 Parent(s): 01ff992

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +24 -19
tools.py CHANGED
@@ -1,30 +1,35 @@
1
  # Tool Section
2
 
3
- from langchain_community.tools import DuckDuckGoSearchRun
4
  from langchain.tools import Tool
5
  from huggingface_hub import list_models
6
- import random
7
-
8
- # Internet Search Tool
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
14
- weather_conditions = [
15
- {"condition": "Rainy", "temp_c": 15},
16
- {"condition": "Clear", "temp_c": 25},
17
- {"condition": "Windy", "temp_c": 20}
18
- ]
19
- # Randomly select a weather condition
20
- data = random.choice(weather_conditions)
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."
28
  )
29
 
30
  def get_hub_stats(author: str) -> str:
 
1
  # Tool Section
2
 
 
3
  from langchain.tools import Tool
4
  from huggingface_hub import list_models
5
+ import requests
6
+ import os
7
+ from tavily import TavilyClient
8
+
9
+ def internet_search_tool(query: str) -> str:
10
+ """Fetches information, news, etc from internet."""
11
+ client = TavilyClient(os.getenv("TAVILY_API_KEY"))
12
+ response = client.search(query=query)
13
+ return response
14
+
15
+ search_tool = Tool(
16
+ name="internet_search_tool",
17
+ func=internet_search_tool,
18
+ description="Fetches information, news, etc from internet."
19
+ )
20
+
21
+ def get_weather_info(city: str) -> str:
22
+ """Fetches the current weather information of specific city."""
23
+ weather_api = "http://api.weatherapi.com/v1/current.json?q={city}".format(city=city)
24
+ weather_api_response = requests.get(weather_api, headers={"key":os.getenv("WEATHER_API_KEY")})
25
+ if weather_api_response.status_code == 200:
26
+ return weather_api_response.text
27
+ return "Problem at moment with API requests, please try after some time"
28
 
 
29
  weather_info_tool = Tool(
30
  name="get_weather_info",
31
  func=get_weather_info,
32
+ description="Fetches the current weather information of specific city."
33
  )
34
 
35
  def get_hub_stats(author: str) -> str: