{ "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 }