File size: 36,615 Bytes
115169a
 
 
 
4a81f80
115169a
 
 
 
 
 
 
 
 
 
 
 
4a81f80
115169a
7118dfb
 
4a81f80
 
 
 
 
 
 
 
 
 
 
 
 
7118dfb
 
 
115169a
 
 
 
 
7118dfb
 
 
 
 
 
 
 
 
 
 
 
115169a
7118dfb
 
115169a
7118dfb
115169a
7118dfb
115169a
7118dfb
 
 
 
 
 
115169a
7118dfb
115169a
7118dfb
 
 
 
 
 
 
115169a
 
7118dfb
 
 
 
 
 
 
 
 
 
 
 
115169a
 
7118dfb
 
 
 
115169a
7118dfb
 
 
 
 
115169a
 
 
 
4a81f80
115169a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7118dfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115169a
 
 
 
7118dfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115169a
 
 
7118dfb
115169a
 
7118dfb
115169a
 
 
 
 
7118dfb
 
 
 
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import utils\n",
    "\n",
    "utils.load_env()\n",
    "os.environ['LANGCHAIN_TRACING_V2'] = \"true\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "JSONDecodeError",
     "evalue": "Invalid control character at: line 4 column 358 (char 398)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mJSONDecodeError\u001b[0m                           Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[5], line 32\u001b[0m\n\u001b[1;32m     29\u001b[0m         buffer\u001b[38;5;241m.\u001b[39mappend(AIMessage(content\u001b[38;5;241m=\u001b[39mai))\n\u001b[1;32m     30\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m buffer\n\u001b[0;32m---> 32\u001b[0m meta \u001b[38;5;241m=\u001b[39m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload_agent_meta\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m     34\u001b[0m prompt \u001b[38;5;241m=\u001b[39m ChatPromptTemplate\u001b[38;5;241m.\u001b[39mfrom_messages(\n\u001b[1;32m     35\u001b[0m     [\n\u001b[1;32m     36\u001b[0m         (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msystem\u001b[39m\u001b[38;5;124m\"\u001b[39m, meta[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mprompt\u001b[39m\u001b[38;5;124m'\u001b[39m]),\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     40\u001b[0m     ]\n\u001b[1;32m     41\u001b[0m )\n\u001b[1;32m     43\u001b[0m agent \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m     44\u001b[0m     {\n\u001b[1;32m     45\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minput\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;01mlambda\u001b[39;00m x: x[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minput\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     53\u001b[0m     \u001b[38;5;241m|\u001b[39m OpenAIFunctionsAgentOutputParser()\n\u001b[1;32m     54\u001b[0m )\n",
      "File \u001b[0;32m~/Projects/Github/market-feasibility-analysis-chatbot/utils.py:8\u001b[0m, in \u001b[0;36mload_agent_meta\u001b[0;34m()\u001b[0m\n\u001b[1;32m      6\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload_agent_meta\u001b[39m():\n\u001b[1;32m      7\u001b[0m     \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m./prompt.json\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[0;32m----> 8\u001b[0m         prompt_data \u001b[38;5;241m=\u001b[39m \u001b[43mjson\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m      9\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m prompt_data\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py:293\u001b[0m, in \u001b[0;36mload\u001b[0;34m(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m    274\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload\u001b[39m(fp, \u001b[38;5;241m*\u001b[39m, \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, object_hook\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, parse_float\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m    275\u001b[0m         parse_int\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, parse_constant\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, object_pairs_hook\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkw):\n\u001b[1;32m    276\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Deserialize ``fp`` (a ``.read()``-supporting file-like object containing\u001b[39;00m\n\u001b[1;32m    277\u001b[0m \u001b[38;5;124;03m    a JSON document) to a Python object.\u001b[39;00m\n\u001b[1;32m    278\u001b[0m \n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    291\u001b[0m \u001b[38;5;124;03m    kwarg; otherwise ``JSONDecoder`` is used.\u001b[39;00m\n\u001b[1;32m    292\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 293\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mloads\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    294\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mobject_hook\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mobject_hook\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    295\u001b[0m \u001b[43m        \u001b[49m\u001b[43mparse_float\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_float\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparse_int\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_int\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    296\u001b[0m \u001b[43m        \u001b[49m\u001b[43mparse_constant\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_constant\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mobject_pairs_hook\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mobject_pairs_hook\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkw\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py:346\u001b[0m, in \u001b[0;36mloads\u001b[0;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m    341\u001b[0m     s \u001b[38;5;241m=\u001b[39m s\u001b[38;5;241m.\u001b[39mdecode(detect_encoding(s), \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msurrogatepass\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m    343\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m    344\u001b[0m         parse_int \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m parse_float \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m    345\u001b[0m         parse_constant \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_pairs_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m kw):\n\u001b[0;32m--> 346\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_default_decoder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdecode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    347\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m    348\u001b[0m     \u001b[38;5;28mcls\u001b[39m \u001b[38;5;241m=\u001b[39m JSONDecoder\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:337\u001b[0m, in \u001b[0;36mJSONDecoder.decode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m    332\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdecode\u001b[39m(\u001b[38;5;28mself\u001b[39m, s, _w\u001b[38;5;241m=\u001b[39mWHITESPACE\u001b[38;5;241m.\u001b[39mmatch):\n\u001b[1;32m    333\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001b[39;00m\n\u001b[1;32m    334\u001b[0m \u001b[38;5;124;03m    containing a JSON document).\u001b[39;00m\n\u001b[1;32m    335\u001b[0m \n\u001b[1;32m    336\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 337\u001b[0m     obj, end \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraw_decode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43midx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_w\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mend\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    338\u001b[0m     end \u001b[38;5;241m=\u001b[39m _w(s, end)\u001b[38;5;241m.\u001b[39mend()\n\u001b[1;32m    339\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m end \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(s):\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:353\u001b[0m, in \u001b[0;36mJSONDecoder.raw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m    344\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Decode a JSON document from ``s`` (a ``str`` beginning with\u001b[39;00m\n\u001b[1;32m    345\u001b[0m \u001b[38;5;124;03ma JSON document) and return a 2-tuple of the Python\u001b[39;00m\n\u001b[1;32m    346\u001b[0m \u001b[38;5;124;03mrepresentation and the index in ``s`` where the document ended.\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    350\u001b[0m \n\u001b[1;32m    351\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m    352\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 353\u001b[0m     obj, end \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mscan_once\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43midx\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    354\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m    355\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m JSONDecodeError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpecting value\u001b[39m\u001b[38;5;124m\"\u001b[39m, s, err\u001b[38;5;241m.\u001b[39mvalue) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
      "\u001b[0;31mJSONDecodeError\u001b[0m: Invalid control character at: line 4 column 358 (char 398)"
     ]
    }
   ],
   "source": [
    "from langchain_core.messages import HumanMessage\n",
    "\n",
    "# for llm model\n",
    "from langchain_openai import ChatOpenAI\n",
    "from langchain.agents.format_scratchpad import format_to_openai_function_messages\n",
    "from tools import find_place_from_text, nearby_search\n",
    "from typing import Dict, List, Tuple\n",
    "from langchain.agents import (\n",
    "    AgentExecutor,\n",
    ")\n",
    "from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser\n",
    "from langchain_community.chat_models import ChatOpenAI\n",
    "from langchain_community.tools.convert_to_openai import format_tool_to_openai_function\n",
    "from langchain_core.messages import AIMessage, HumanMessage\n",
    "from langchain_core.pydantic_v1 import BaseModel, Field\n",
    "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
    "\n",
    "# Bind the tools to the model\n",
    "tools = [find_place_from_text, nearby_search]  # Include both tools if needed\n",
    "\n",
    "llm = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])\n",
    "\n",
    "def _format_chat_history(chat_history: List[Tuple[str, str]]):\n",
    "    buffer = []\n",
    "    for human, ai in chat_history:\n",
    "        buffer.append(HumanMessage(content=human))\n",
    "        buffer.append(AIMessage(content=ai))\n",
    "    return buffer\n",
    "\n",
    "meta = utils.load_agent_meta()[0]\n",
    "\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", meta['prompt']),\n",
    "        MessagesPlaceholder(variable_name=\"chat_history\"),\n",
    "        (\"user\", \"{input}\"),\n",
    "        MessagesPlaceholder(variable_name=\"agent_scratchpad\"),\n",
    "    ]\n",
    ")\n",
    "\n",
    "agent = (\n",
    "    {\n",
    "        \"input\": lambda x: x[\"input\"],\n",
    "        \"chat_history\": lambda x: _format_chat_history(x[\"chat_history\"]),\n",
    "        \"agent_scratchpad\": lambda x: format_to_openai_function_messages(\n",
    "            x[\"intermediate_steps\"]\n",
    "        ),\n",
    "    }\n",
    "    | prompt\n",
    "    | llm_with_tools\n",
    "    | OpenAIFunctionsAgentOutputParser()\n",
    ")\n",
    "\n",
    "\n",
    "class AgentInput(BaseModel):\n",
    "    input: str\n",
    "    chat_history: List[Tuple[str, str]] = Field(\n",
    "        ..., extra={\"widget\": {\"type\": \"chat\", \"input\": \"input\", \"output\": \"output\"}}\n",
    "    )\n",
    "\n",
    "\n",
    "agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True).with_types(\n",
    "    input_type=AgentInput\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `nearby_search` with `{'input_dict': {'keyword': 'coffee shop', 'location_name': 'มาบุญครอง', 'radius': 1500, 'place_type': 'cafe'}}`\n",
      "\n",
      "\n",
      "\u001b[0m"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n",
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33;1m\u001b[1;3m\n",
      "        address: 991/1 Rama I Rd, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7458781, 'lng': 100.5341476}\n",
      "\n",
      "        name: BEANS Coffee Roaster Paragon\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52PGWM+9M\n",
      "\n",
      "\n",
      "        \n",
      "        address: 43/4 Rama VI Rd, Rong Muang, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7497223, 'lng': 100.521221}\n",
      "\n",
      "        name: Olympic Coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.8\n",
      "\n",
      "        plus code: 7P52PGXC+VF\n",
      "\n",
      "\n",
      "        \n",
      "        address: 994 Makkasan, Ratchathewi\n",
      "\n",
      "        location: {'lat': 13.7495947, 'lng': 100.5426623}\n",
      "\n",
      "        name: Earthy Roaster (Specialty Coffee)\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.8\n",
      "\n",
      "        plus code: 7P52PGXV+R3\n",
      "\n",
      "\n",
      "        \n",
      "        address: MINT TOWER Bantadthong Phetchaburi Rd, Subdistrict Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7450255, 'lng': 100.5235735}\n",
      "\n",
      "        name: Treasure specialty coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.9\n",
      "\n",
      "        plus code: 7P52PGWF+2C\n",
      "\n",
      "\n",
      "        \n",
      "        address: ตึก Gaysorn Amarin (ชั้น 2 496-502 Phloen Chit Rd, Khwaeng Lumphini, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7439676, 'lng': 100.5413037}\n",
      "\n",
      "        name: The Basic Coffee BKK\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.7\n",
      "\n",
      "        plus code: 7P52PGVR+HG\n",
      "\n",
      "\n",
      "        \n",
      "        address: 126 ซ. จุฬาลงกรณ์ 50 Wang Mai, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7344961, 'lng': 100.5268998}\n",
      "\n",
      "        name: CRANNIES Coffee & Brunch\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52PGMG+RQ\n",
      "\n",
      "\n",
      "        \n",
      "        address: 85 1 Akkharanithi Alley, Thanon Phaya Thai, Ratchathewi\n",
      "\n",
      "        location: {'lat': 13.7537094, 'lng': 100.5328794}\n",
      "\n",
      "        name: Bullet Thai Craft Beer\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52QG3M+F5\n",
      "\n",
      "\n",
      "        \n",
      "        address: 36, 6 Kasem San 1 Alley, Wang Mai, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7477989, 'lng': 100.5296324}\n",
      "\n",
      "        name: Sip 'n Drip\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.9\n",
      "\n",
      "        plus code: 7P52PGXH+4V\n",
      "\n",
      "\n",
      "        \n",
      "        address: 502, ห้างสรรพสินค้าอัมรินทร์ พลาซ่า ชั้น 1, Phloen Chit Rd, Lumphini, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.743762, 'lng': 100.541402}\n",
      "\n",
      "        name: TABLA Craft Coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.6\n",
      "\n",
      "        plus code: 7P52PGVR+GH\n",
      "\n",
      "\n",
      "        \n",
      "        address: Velaa Sindhorn Village Langsuan, 87 Soi Langsuan, Lumphini, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7365082, 'lng': 100.5428638}\n",
      "\n",
      "        name: The Coffee Academics\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.4\n",
      "\n",
      "        plus code: 7P52PGPV+J4\n",
      "\n",
      "\n",
      "        \n",
      "        address: 445 Rama I Rd, Rong Muang, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7476317, 'lng': 100.5232939}\n",
      "\n",
      "        name: D Coffee House\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.9\n",
      "\n",
      "        plus code: 7P52PGXF+38\n",
      "\n",
      "\n",
      "        \n",
      "        address: ศูนย์รวมนักศึกษาแบ๊บติสต์ 473 Thanon Si Ayutthaya, Thung Phaya Thai, Ratchathewi\n",
      "\n",
      "        location: {'lat': 13.758337, 'lng': 100.534177}\n",
      "\n",
      "        name: Baptist coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52QG5M+8M\n",
      "\n",
      "\n",
      "        \n",
      "        address: 1/11 Rong Muang 5 Alley, Rong Muang, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7466928, 'lng': 100.5227848}\n",
      "\n",
      "        name: Greatercafe Specialty Coffee Bangkok\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.7\n",
      "\n",
      "        plus code: 7P52PGWF+M4\n",
      "\n",
      "\n",
      "        \n",
      "        address: Bldg., 1 st Fl 320 TangHuaPak (Hualamphong Rama IV Rd, Mahapruettaram Bang Rak\n",
      "\n",
      "        location: {'lat': 13.7374409, 'lng': 100.5165419}\n",
      "\n",
      "        name: Better Coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52PGP8+XJ\n",
      "\n",
      "\n",
      "        \n",
      "        address: อาคารหอศิลปวัฒนธรรมแห่งกรุงเทพมหานคร(BACC) 939 Rama I Rd, Wang Mai, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7466896, 'lng': 100.5304572}\n",
      "\n",
      "        name: Gallery Drip Coffee\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.6\n",
      "\n",
      "        plus code: 7P52PGWJ+M5\n",
      "\n",
      "\n",
      "        \n",
      "        address: 27 ซอย จุฬาลงกรณ์ 20 Wang Mai, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7408514, 'lng': 100.5230725}\n",
      "\n",
      "        name: mm : MAKE MERRY\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.8\n",
      "\n",
      "        plus code: 7P52PGRF+86\n",
      "\n",
      "\n",
      "        \n",
      "        address: 2nd Floor Siam Square One 388 Rama I Rd, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7446247, 'lng': 100.5340785}\n",
      "\n",
      "        name: GATTA CAFé\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.9\n",
      "\n",
      "        plus code: 7P52PGVM+RJ\n",
      "\n",
      "\n",
      "        \n",
      "        address: 1873 Rama IV Rd, Khlong Tan Nuea, Watthana\n",
      "\n",
      "        location: {'lat': 13.7335441, 'lng': 100.5377224}\n",
      "\n",
      "        name: Redwood coffee and eatery\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.8\n",
      "\n",
      "        plus code: 7P52PGMQ+C3\n",
      "\n",
      "\n",
      "        \n",
      "        address: B1 The Offices At Central World ชั้น 104 Rama I Rd, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7458267, 'lng': 100.5381669}\n",
      "\n",
      "        name: Baankhunlek coffee สาขา CentralworldOffices\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 5\n",
      "\n",
      "        plus code: 7P52PGWQ+87\n",
      "\n",
      "\n",
      "        \n",
      "        address: 3rd Floor, CentralWorld, Ratchadamri Rd, Pathum Wan\n",
      "\n",
      "        location: {'lat': 13.7470656, 'lng': 100.5397062}\n",
      "\n",
      "        name: Café BAGA Central World\n",
      "\n",
      "        opening hours: {'open_now': True}\n",
      "\n",
      "        rating: 4.7\n",
      "\n",
      "        plus code: 7P52PGWQ+RV\n",
      "\n",
      "\n",
      "        \u001b[0m"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unable to load requested LangChainTracer. To disable this warning, unset the LANGCHAIN_TRACING_V2 environment variables.\n",
      "LangSmithUserError('API key must be provided when using hosted LangSmith API')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3mHere is a list of coffee shops near มาบุญครอง (MBK Center):\n",
      "\n",
      "1. **BEANS Coffee Roaster Paragon**\n",
      "   - Address: 991/1 Rama I Rd, Pathum Wan\n",
      "   - Rating: 5.0\n",
      "   - Open Now: Yes\n",
      "\n",
      "2. **Olympic Coffee**\n",
      "   - Address: 43/4 Rama VI Rd, Rong Muang, Pathum Wan\n",
      "   - Rating: 4.8\n",
      "   - Open Now: Yes\n",
      "\n",
      "3. **Earthy Roaster (Specialty Coffee)**\n",
      "   - Address: 994 Makkasan, Ratchathewi\n",
      "   - Rating: 4.8\n",
      "   - Open Now: Yes\n",
      "\n",
      "4. **Treasure specialty coffee**\n",
      "   - Address: MINT TOWER Bantadthong Phetchaburi Rd, Pathum Wan\n",
      "   - Rating: 4.9\n",
      "   - Open Now: Yes\n",
      "\n",
      "5. **The Basic Coffee BKK**\n",
      "   - Address: ตึก Gaysorn Amarin, ชั้น 2 496-502 Phloen Chit Rd, Khwaeng Lumphini, Pathum Wan\n",
      "   - Rating: 4.7\n",
      "   - Open Now: Yes\n",
      "\n",
      "6. **CRANNIES Coffee & Brunch**\n",
      "   - Address: 126 ซ. จุฬาลงกรณ์ 50 Wang Mai, Pathum Wan\n",
      "   - Rating: 5.0\n",
      "   - Open Now: Yes\n",
      "\n",
      "7. **Bullet Thai Craft Beer**\n",
      "   - Address: 85 1 Akkharanithi Alley, Thanon Phaya Thai, Ratchathewi\n",
      "   - Rating: 5.0\n",
      "   - Open Now: Yes\n",
      "\n",
      "8. **Sip 'n Drip**\n",
      "   - Address: 36, 6 Kasem San 1 Alley, Wang Mai, Pathum Wan\n",
      "   - Rating: 4.9\n",
      "   - Open Now: Yes\n",
      "\n",
      "9. **TABLA Craft Coffee**\n",
      "   - Address: 502, ห้างสรรพสินค้าอัมรินทร์ พลาซ่า ชั้น 1, Phloen Chit Rd, Lumphini, Pathum Wan\n",
      "   - Rating: 4.6\n",
      "   - Open Now: Yes\n",
      "\n",
      "10. **The Coffee Academics**\n",
      "    - Address: Velaa Sindhorn Village Langsuan, 87 Soi Langsuan, Lumphini, Pathum Wan\n",
      "    - Rating: 4.4\n",
      "    - Open Now: Yes\n",
      "\n",
      "11. **D Coffee House**\n",
      "    - Address: 445 Rama I Rd, Rong Muang, Pathum Wan\n",
      "    - Rating: 4.9\n",
      "    - Open Now: Yes\n",
      "\n",
      "12. **Baptist coffee**\n",
      "    - Address: ศูนย์รวมนักศึกษาแบ๊บติสต์ 473 Thanon Si Ayutthaya, Thung Phaya Thai, Ratchathewi\n",
      "    - Rating: 5.0\n",
      "    - Open Now: Yes\n",
      "\n",
      "13. **Greatercafe Specialty Coffee Bangkok**\n",
      "    - Address: 1/11 Rong Muang 5 Alley, Rong Muang, Pathum Wan\n",
      "    - Rating: 4.7\n",
      "    - Open Now: Yes\n",
      "\n",
      "14. **Better Coffee**\n",
      "    - Address: Bldg., 1 st Fl 320 TangHuaPak (Hualamphong Rama IV Rd, Mahapruettaram Bang Rak\n",
      "    - Rating: 5.0\n",
      "    - Open Now: Yes\n",
      "\n",
      "15. **Gallery Drip Coffee**\n",
      "    - Address: อาคารหอศิลปวัฒนธรรมแห่งกรุงเทพมหานคร(BACC) 939 Rama I Rd, Wang Mai, Pathum Wan\n",
      "    - Rating: 4.6\n",
      "    - Open Now: Yes\n",
      "\n",
      "16. **mm : MAKE MERRY**\n",
      "    - Address: 27 ซอย จุฬาลงกรณ์ 20 Wang Mai, Pathum Wan\n",
      "    - Rating: 4.8\n",
      "    - Open Now: Yes\n",
      "\n",
      "17. **GATTA CAFé**\n",
      "    - Address: 2nd Floor Siam Square One 388 Rama I Rd, Pathum Wan\n",
      "    - Rating: 4.9\n",
      "    - Open Now: Yes\n",
      "\n",
      "18. **Redwood coffee and eatery**\n",
      "    - Address: 1873 Rama IV Rd, Khlong Tan Nuea, Watthana\n",
      "    - Rating: 4.8\n",
      "    - Open Now: Yes\n",
      "\n",
      "19. **Baankhunlek coffee สาขา CentralworldOffices**\n",
      "    - Address: B1 The Offices At Central World ชั้น 104 Rama I Rd, Pathum Wan\n",
      "    - Rating: 5.0\n",
      "    - Open Now: Yes\n",
      "\n",
      "20. **Café BAGA Central World**\n",
      "    - Address: 3rd Floor, CentralWorld, Ratchadamri Rd, Pathum Wan\n",
      "    - Rating: 4.7\n",
      "    - Open Now: Yes\n",
      "\n",
      "These coffee shops are within a radius of approximately 1500 meters from MBK Center and are currently open.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\"Here is a list of coffee shops near มาบุญครอง (MBK Center):\\n\\n1. **BEANS Coffee Roaster Paragon**\\n   - Address: 991/1 Rama I Rd, Pathum Wan\\n   - Rating: 5.0\\n   - Open Now: Yes\\n\\n2. **Olympic Coffee**\\n   - Address: 43/4 Rama VI Rd, Rong Muang, Pathum Wan\\n   - Rating: 4.8\\n   - Open Now: Yes\\n\\n3. **Earthy Roaster (Specialty Coffee)**\\n   - Address: 994 Makkasan, Ratchathewi\\n   - Rating: 4.8\\n   - Open Now: Yes\\n\\n4. **Treasure specialty coffee**\\n   - Address: MINT TOWER Bantadthong Phetchaburi Rd, Pathum Wan\\n   - Rating: 4.9\\n   - Open Now: Yes\\n\\n5. **The Basic Coffee BKK**\\n   - Address: ตึก Gaysorn Amarin, ชั้น 2 496-502 Phloen Chit Rd, Khwaeng Lumphini, Pathum Wan\\n   - Rating: 4.7\\n   - Open Now: Yes\\n\\n6. **CRANNIES Coffee & Brunch**\\n   - Address: 126 ซ. จุฬาลงกรณ์ 50 Wang Mai, Pathum Wan\\n   - Rating: 5.0\\n   - Open Now: Yes\\n\\n7. **Bullet Thai Craft Beer**\\n   - Address: 85 1 Akkharanithi Alley, Thanon Phaya Thai, Ratchathewi\\n   - Rating: 5.0\\n   - Open Now: Yes\\n\\n8. **Sip 'n Drip**\\n   - Address: 36, 6 Kasem San 1 Alley, Wang Mai, Pathum Wan\\n   - Rating: 4.9\\n   - Open Now: Yes\\n\\n9. **TABLA Craft Coffee**\\n   - Address: 502, ห้างสรรพสินค้าอัมรินทร์ พลาซ่า ชั้น 1, Phloen Chit Rd, Lumphini, Pathum Wan\\n   - Rating: 4.6\\n   - Open Now: Yes\\n\\n10. **The Coffee Academics**\\n    - Address: Velaa Sindhorn Village Langsuan, 87 Soi Langsuan, Lumphini, Pathum Wan\\n    - Rating: 4.4\\n    - Open Now: Yes\\n\\n11. **D Coffee House**\\n    - Address: 445 Rama I Rd, Rong Muang, Pathum Wan\\n    - Rating: 4.9\\n    - Open Now: Yes\\n\\n12. **Baptist coffee**\\n    - Address: ศูนย์รวมนักศึกษาแบ๊บติสต์ 473 Thanon Si Ayutthaya, Thung Phaya Thai, Ratchathewi\\n    - Rating: 5.0\\n    - Open Now: Yes\\n\\n13. **Greatercafe Specialty Coffee Bangkok**\\n    - Address: 1/11 Rong Muang 5 Alley, Rong Muang, Pathum Wan\\n    - Rating: 4.7\\n    - Open Now: Yes\\n\\n14. **Better Coffee**\\n    - Address: Bldg., 1 st Fl 320 TangHuaPak (Hualamphong Rama IV Rd, Mahapruettaram Bang Rak\\n    - Rating: 5.0\\n    - Open Now: Yes\\n\\n15. **Gallery Drip Coffee**\\n    - Address: อาคารหอศิลปวัฒนธรรมแห่งกรุงเทพมหานคร(BACC) 939 Rama I Rd, Wang Mai, Pathum Wan\\n    - Rating: 4.6\\n    - Open Now: Yes\\n\\n16. **mm : MAKE MERRY**\\n    - Address: 27 ซอย จุฬาลงกรณ์ 20 Wang Mai, Pathum Wan\\n    - Rating: 4.8\\n    - Open Now: Yes\\n\\n17. **GATTA CAFé**\\n    - Address: 2nd Floor Siam Square One 388 Rama I Rd, Pathum Wan\\n    - Rating: 4.9\\n    - Open Now: Yes\\n\\n18. **Redwood coffee and eatery**\\n    - Address: 1873 Rama IV Rd, Khlong Tan Nuea, Watthana\\n    - Rating: 4.8\\n    - Open Now: Yes\\n\\n19. **Baankhunlek coffee สาขา CentralworldOffices**\\n    - Address: B1 The Offices At Central World ชั้น 104 Rama I Rd, Pathum Wan\\n    - Rating: 5.0\\n    - Open Now: Yes\\n\\n20. **Café BAGA Central World**\\n    - Address: 3rd Floor, CentralWorld, Ratchadamri Rd, Pathum Wan\\n    - Rating: 4.7\\n    - Open Now: Yes\\n\\nThese coffee shops are within a radius of approximately 1500 meters from MBK Center and are currently open.\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def submitUserMessage(user_input: str) -> str:\n",
    "    responce = agent_executor.invoke({\"input\": user_input, \"chat_history\": []})\n",
    "    return responce[\"output\"]\n",
    "\n",
    "submitUserMessage(\"ค้นหาร้านกาแฟใกล้มาบุญครอง\")"
   ]
  }
 ],
 "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
}