{ "cells": [ { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "import gplace\n", "\n", "location = \"13.744677,100.5295593\" # Latitude and Longitude\n", "keyword = \"ร้านกาแฟ\"\n", "result = gplace.nearby_search(keyword, location)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "from typing import TypedDict, Optional\n", "\n", "class NearbyDenseCommunityInput(TypedDict):\n", " location_name: str\n", " radius: int" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "def find_place_from_text(location:str):\n", " \"\"\"Finds a place and related data from the query text\"\"\"\n", " \n", " result = gplace.find_place_from_text(location)\n", " r = result['candidates'][0]\n", " return f\"\"\"\n", " address: {r['formatted_address']}\\n\n", " location: {r['geometry']['location']}\\n\n", " name: {r['name']}\\n\n", " opening hours: {r['opening_hours']}\\n\n", " rating: {r['rating']}\\n\n", " \"\"\"\n", " \n", "def nearby_search(keyword:str, location:str, radius=2000, place_type=None):\n", " \"\"\"Searches for many places nearby the location based on a keyword. using keyword like \\\"coffee shop\\\", \\\"restaurants\\\". radius is the range to search from the location\"\"\"\n", " location = gplace.find_location(location, radius=radius)\n", " result = gplace.nearby_search(keyword, location, radius)\n", " \n", " strout = \"\"\n", " for r in result:\n", " # Use .get() to handle missing keys\n", " address = r.get('vicinity', 'N/A')\n", " location_info = r.get('geometry', {}).get('location', 'N/A')\n", " name = r.get('name', 'N/A')\n", " opening_hours = r.get('opening_hours', 'N/A')\n", " rating = r.get('rating', 'N/A')\n", " plus_code = r.get('plus_code', {}).get('global_code', 'N/A')\n", " \n", " strout += f\"\"\"\n", " address: {address}\\n\n", " location: {location_info}\\n\n", " name: {name}\\n\n", " opening hours: {opening_hours}\\n\n", " rating: {rating}\\n\n", " plus code: {plus_code}\\n\\n\n", " \"\"\"\n", " return strout\n", "\n", "def nearby_dense_community(input_dict: NearbyDenseCommunityInput) -> str:\n", " \"\"\" getting nearby dense community such as (community mall, hotel, school, etc), by location name, radius(in meters)\n", " return list of location community nearby, name, community type.\n", " \"\"\"\n", " location = input_dict['location_name']\n", " radius = input_dict['radius']\n", " \n", " location_coords = gplace.find_location(location, radius=radius)\n", " result = gplace.nearby_dense_community(location_coords, radius)\n", " \n", " strout = \"\"\n", " for r in result:\n", " # Use .get() to handle missing keys\n", " address = r.get('vicinity', 'N/A')\n", " location_types = r.get('types', 'N/A')\n", " name = r.get('name', 'N/A')\n", " opening_hours = r.get('opening_hours', 'N/A')\n", " rating = r.get('rating', 'N/A')\n", " plus_code = r.get('plus_code', {}).get('global_code', 'N/A')\n", " \n", " strout += f\"\"\"\n", " name: {name}\\n\n", " types: {location_types}\\n\n", " \"\"\".strip()\n", " return strout\n" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "# gplace_tools.py\n", "from langgraph.prebuilt import ToolNode\n", "from langchain_core.tools import tool\n", "from langchain_core.tools import Tool\n", "from langchain_google_community import GoogleSearchAPIWrapper\n", "from langchain_community.document_loaders import WebBaseLoader\n", "\n", "import utils\n", "\n", "utils.load_env()\n", "\n", "search = GoogleSearchAPIWrapper()\n", "\n", "find_place_from_text = tool(find_place_from_text)\n", "nearby_search = tool(nearby_search)\n", "google_search = Tool(\n", " name=\"google_search\",\n", " description=\"Search Google for recent results.\",\n", " func=search.run,\n", ")\n", "web_loader = Tool(\n", " name=\"google_search\",\n", " description=\"Search Google for recent results.\",\n", " func=WebBaseLoader,\n", ")\n", "\n", "tools = [find_place_from_text, nearby_search]\n", "\n", "# Create ToolNodes for each tool\n", "tool_node = ToolNode(tools)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"name: Bangkok\\n\\n types: ['locality', 'political']name: Metropoint Bangkok Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: The Grand Fourwings Convention Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Hua Mak Indoor Stadium\\n\\n types: ['point_of_interest', 'establishment']name: B2 Bangkok Srinagarindra Boutique & Budget Hotel\\n\\n types: ['lodging', 'clothing_store', 'store', 'point_of_interest', 'establishment']name: HappyLand Mansion\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Bangkok Swimming by Kru Jin\\n\\n types: ['point_of_interest', 'establishment']name: Aunchaleena grand Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Anda Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Grand Mandarin Residence\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Wallada Place Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: NIDA Rooms Plubpla Bangkapi 591\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Bangkok Interplace\\n\\n types: ['lodging', 'restaurant', 'food', 'point_of_interest', 'establishment']name: Vejthani Hospital\\n\\n types: ['hospital', 'doctor', 'health', 'point_of_interest', 'establishment']name: โรงแรม ชาลีน่า ปริ้นเซส Chaleena princess\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Royal Pimand\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Baron Residence Hotel\\n\\n types: ['lodging', 'point_of_interest', 'establishment']name: Ridwanun Islam Mosque\\n\\n types: ['mosque', 'place_of_worship', 'point_of_interest', 'establishment']name: Thep Phanom Building\\n\\n types: ['point_of_interest', 'establishment']name: Bang Kapi District\\n\\n types: ['sublocality_level_1', 'sublocality', 'political']\"" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nearby_dense_community({'location_name': 'ลุมพินี เซ็นเตอร์ ลาดพร้าว', 'radius': 8000})" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"Apr 8, 2023 ... They actually have two locations within Central World (you guessed it, another huge shopping mall). If you're in the area, the fifth floor\\xa0... It is the best time to go to Central world plaza when you want to spend your money on fashion stuff, or eat some delicious food! If you are the one who\\xa0... Jan 22, 2023 ... they have different outlets but we tried the one at central world! interior looks like a mini coffee shop which was rly cute! u cld order\\xa0... One can buy soft drinks but no coffee. Seating arrangements could be more comfortable. This ice arena is on the 2nd floor at Central World. It is open from\\xa0... Aug 26, 2023 ... McDonalds coffee is terrible. I have been all over the world though, to some of the coffiest destinations on the globe, and maybe it's because I\\xa0... You don't have any items in your cart. Checkout. Continue Shopping. Accepted here. Apple Pay Google Pay Visa Mastercard American Express Discover JCB CashApp. Apr 29, 2024 ... ... they have grown, cultivated and processed coffee. Starbucks will donate 100 percent of the sale price to World Central Kitchen for each unit\\xa0... Dec 25, 2021 ... ... rates, the question I asked at the outset still remains. Why bother ... Now, are you saying that the declining cup quality of Kenyan Coffee\\xa0... I will likely do another post about the drinking culture in Italy because I find it fascinating. The rules of Italian Coffee and Bars… The Cappuccino Law:\\xa0... Mar 27, 2019 ... More often than not you're getting some of the best coffee in the entire world. ... have transparency reports on coffee prices they buy so that I\\xa0...\"" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "google_search(\"pricing of You Drink Coffee in Central World\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }