File size: 8,454 Bytes
115169a
 
5831cdb
 
ae3368c
5831cdb
 
 
 
 
 
 
 
 
 
 
 
ae3368c
5831cdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7118dfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5831cdb
0189767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5831cdb
 
 
 
 
ae3368c
5831cdb
ae3368c
115169a
 
 
 
fa2543e
 
a7abe3e
 
fa2543e
 
 
 
 
115169a
 
 
fa2543e
 
 
 
 
a7abe3e
 
 
 
 
115169a
5831cdb
115169a
 
 
 
7b69047
 
 
ae3368c
7b69047
 
ae3368c
 
 
 
 
 
 
 
7b69047
 
 
ae3368c
7b69047
 
ae3368c
7b69047
 
 
 
 
ae3368c
7b69047
115169a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "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": 9,
   "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(location:str, radius:int=2000):\n",
    "    \"\"\" getting nearby dense community such as (community mall, hotel, school, etc), by geomatric location, radius(in meters)\n",
    "    return list of location community nearby, name, community type.\n",
    "    \"\"\"\n",
    "    result = gplace.nearby_dense_community(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",
    "        name: {address}\\n\n",
    "        types: {location_info}\\n\n",
    "        \"\"\"\n",
    "    return strout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "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": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:141: LangChainDeprecationWarning: The method `BaseTool.__call__` was deprecated in langchain-core 0.1.47 and will be removed in 1.0. Use invoke instead.\n",
      "  warn_deprecated(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Oct 16, 2020 ... ... กับสาขาใหม่อย่าง เท็กซัส ชิคเก้น PTT Station นวลจันทร์ ... Follow. B.S corset แผ่นรัดเอว. \\U000f1676. Follow. SalmonFarm By ม่อนอ้วน แซลมอนนอร์เวย์สด\\xa0... Oct 26, 2020 ... ... นวลจันทร์ - PTT Station บางแสน - PTT Station ประชาชื่น-นนทบุรี - PTT ... B.S corset แผ่นรัดเอว. \\U000f1676. Follow. Wizard Beer. \\U000f1676. Follow. Beertique. บริการตรวจสภาพรถ เช็ดระยะเปลี่ยนน้ำมันเครื่อง ครบวงจร ที่ Cockpit (ค็อกพิท) ศูนย์บริการรถยนต์ใกล้บ้านคุณ มีโปรโมชั่นสินค้ารถยนต์ เพียบ คลิก!! Nov 4, 2021 ... ... B.S.Williams, Orch. Album 3: t. 134 (1884); Calanthe turneri var ... Vernacular names. edit. lietuvių: Gaubtoji kalantė ไทย: อั้วนวลจันทร์ 33:31. ธนิก ศิริสุนทรไพบูลย์+ก้องภพ อัศวอารักษ์ VS กิตติพศ นวลจันทร์+กฤษฎิ์ ประภาศิริ BD U15 SF ... ธนิก ฟู (ที ไทยแลนด์)[4] VS ปัณณธร มหาพัณณาภรณ์ (ที ไทยแลนด์)[3] BS U13 Final. 818K Followers, 1178 Following, 5931 Posts - Nualphan Lamsam (@panglamsam) on Instagram: \"นวลพรรณ ล่ำซำ CEO เมืองไทยประกันภัย, นายกสมาคมกีฬาฟุตบอลแห่งประเทศไทย,\\xa0... Nov 25, 2020 ... ไทย : อั้วนวลจันทร์; eesti : õrn mudikäpp; lietuvių : Gaubtoji kalantė ... B.S.Williams, Orch. Album 3: t. 134 (1884); Calanthe turneri\\xa0... นวลจันทร์ ประดุจชนม์. ศศ.บ.(ภาษาอังกฤษ) มหาวิทยาลัยขอนแก่น ความเชี่ยวชาญ ... B.S. (Aerospace Engineering) Iowa State Univ., U.S.A. ความเชี่ยวชาญ: Email\\xa0... Jul 8, 2024 ... Moovit. วิธีการไปยัง ร้านไปรษณีย์ไทย จรเข้บัว 206 (นวลจันทร์) ที่ บึงกุ่ม โดย รถบัส, รถไฟใต้ดิน หรือ SkyTrain\\xa0... 51. Cetinkaya F, Tufekci BS, Kutluk G. A comparison of nebulized ... munity of central Thailand, a population-based study. J Med Assoc Thai 2002\\xa0...'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "google_search(\"BS SHOP THAILAND in นวลจันทร์\")"
   ]
  }
 ],
 "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
}