Spaces:
Sleeping
Sleeping
File size: 3,437 Bytes
686a009 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | import os
import json
from langchain_tavily import TavilySearch
from langchain_google_community import GooglePlacesTool, GooglePlacesAPIWrapper
class GooglePlaceSearchTool:
def __init__(self, api_key: str):
self.places_wrapper = GooglePlacesAPIWrapper(gplaces_api_key=api_key)
self.places_tool = GooglePlacesTool(api_wrapper=self.places_wrapper)
def google_search_attractions(self, place: str) -> dict:
"""
Searches for attractions in the specified place using GooglePlaces API.
"""
return self.places_tool.run(f"top attractive places in and around {place}")
def google_search_restaurants(self, place: str) -> dict:
"""
Searches for available restaurants in the specified place using GooglePlaces API.
"""
return self.places_tool.run(f"what are the top 10 restaurants and eateries in and around {place}?")
def google_search_activity(self, place: str) -> dict:
"""
Searches for popular activities in the specified place using GooglePlaces API.
"""
return self.places_tool.run(f"Activities in and around {place}")
def google_search_transportation(self, place: str) -> dict:
"""
Searches for available modes of transportation in the specified place using GooglePlaces API.
"""
return self.places_tool.run(f"What are the different modes of transportations available in {place}")
class TavilyPlaceSearchTool:
def __init__(self):
pass
def tavily_search_attractions(self, place: str) -> dict:
"""
Searches for attractions in the specified place using TavilySearch.
"""
tavily_tool = TavilySearch(topic="general", include_answer="advanced")
result = tavily_tool.invoke({"query": f"top attractive places in and around {place}"})
if isinstance(result, dict) and result.get("answer"):
return result["answer"]
return result
def tavily_search_restaurants(self, place: str) -> dict:
"""
Searches for available restaurants in the specified place using TavilySearch.
"""
tavily_tool = TavilySearch(topic="general", include_answer="advanced")
result = tavily_tool.invoke({"query": f"what are the top 10 restaurants and eateries in and around {place}."})
if isinstance(result, dict) and result.get("answer"):
return result["answer"]
return result
def tavily_search_activity(self, place: str) -> dict:
"""
Searches for popular activities in the specified place using TavilySearch.
"""
tavily_tool = TavilySearch(topic="general", include_answer="advanced")
result = tavily_tool.invoke({"query": f"activities in and around {place}"})
if isinstance(result, dict) and result.get("answer"):
return result["answer"]
return result
def tavily_search_transportation(self, place: str) -> dict:
"""
Searches for available modes of transportation in the specified place using TavilySearch.
"""
tavily_tool = TavilySearch(topic="general", include_answer="advanced")
result = tavily_tool.invoke({"query": f"What are the different modes of transportations available in {place}"})
if isinstance(result, dict) and result.get("answer"):
return result["answer"]
return result
|