{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import utils\n", "\n", "utils.load_env()\n", "os.environ['LANGCHAIN_TRACING_V2'] = \"false\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from langchain.globals import set_debug, set_verbose\n", "\n", "set_verbose(True)\n", "set_debug(False)" ] }, { "cell_type": "code", "execution_count": 3, "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 class `GooglePlacesTool` was deprecated in LangChain 0.0.33 and will be removed in 0.3.0. An updated version of the class exists in the langchain-google-community package and should be used instead. To use it run `pip install -U langchain-google-community` and import as `from langchain_google_community import GooglePlacesTool`.\n", " warn_deprecated(\n", "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:141: LangChainDeprecationWarning: The class `GooglePlacesAPIWrapper` was deprecated in LangChain 0.0.33 and will be removed in 0.3.0. An updated version of the class exists in the langchain-google-community package and should be used instead. To use it run `pip install -U langchain-google-community` and import as `from langchain_google_community import GooglePlacesAPIWrapper`.\n", " warn_deprecated(\n" ] } ], "source": [ "from langchain_core.messages import HumanMessage\n", "import operator\n", "import functools\n", "\n", "# for llm model\n", "from langchain_openai import ChatOpenAI\n", "# from langchain_community.chat_models 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, Annotated, Sequence, TypedDict\n", "from langchain.agents import (\n", " AgentExecutor,\n", ")\n", "from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser\n", "from langchain_community.tools.convert_to_openai import format_tool_to_openai_function\n", "from langchain_core.messages import (\n", " AIMessage, \n", " HumanMessage,\n", " BaseMessage,\n", " ToolMessage\n", ")\n", "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", "from langgraph.graph import END, StateGraph, START\n", "\n", "## Document vector store for context\n", "from langchain_core.runnables import RunnablePassthrough\n", "from langchain_chroma import Chroma\n", "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", "from langchain_community.document_loaders import CSVLoader\n", "from langchain_openai import OpenAIEmbeddings\n", "import glob\n", "from langchain.tools import Tool\n", "\n", "def format_docs(docs):\n", " return \"\\n\\n\".join(doc.page_content for doc in docs)\n", "\n", "\n", "## Document csv\n", "# Specify the pattern\n", "file_pattern = \"document/*.csv\"\n", "file_paths = tuple(glob.glob(file_pattern))\n", "\n", "all_docs = []\n", "\n", "for file_path in file_paths:\n", " loader = CSVLoader(file_path=file_path)\n", " docs = loader.load()\n", " all_docs.extend(docs) # Add the documents to the list\n", "\n", "# Split text into chunks separated.\n", "text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=100)\n", "splits = text_splitter.split_documents(all_docs)\n", "\n", "# Text Vectorization.\n", "vectorstore = Chroma.from_documents(documents=splits, embedding=OpenAIEmbeddings())\n", "\n", "# Retrieve and generate using the relevant snippets of the blog.\n", "retriever = vectorstore.as_retriever()\n", "\n", "\n", "## tools and LLM\n", "retriever_tool = Tool(\n", " name=\"population_community_ousehold_expenditures_data\",\n", " func=retriever.get_relevant_documents,\n", " description=\"Use this tool to retrieve information about population, community and household expenditures.\"\n", ")\n", "\n", "# Bind the tools to the model\n", "# tools = [retriever_tool, find_place_from_text, nearby_search] # Include both tools if needed\n", "tools = [find_place_from_text, nearby_search]\n", "\n", "llm = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0.0)\n", "\n", "## Create agents\n", "def create_agent(llm, tools, system_message: str):\n", " \"\"\"Create an agent.\"\"\"\n", " prompt = ChatPromptTemplate.from_messages(\n", " [\n", " (\n", " \"system\",\n", " \"You are a helpful AI assistant, collaborating with other assistants.\"\n", " \" Use the provided tools to progress towards answering the question.\"\n", " \" If you are unable to fully answer, that's OK, another assistant with different tools \"\n", " \" will help where you left off. Execute what you can to make progress.\"\n", " \" If you or any of the other assistants have the final answer or deliverable,\"\n", " \" prefix your response with FINAL ANSWER so the team knows to stop.\"\n", " \" You have access to the following tools: {tool_names}.\\n{system_message}\",\n", " ),\n", " MessagesPlaceholder(variable_name=\"messages\"),\n", " ]\n", " )\n", " prompt = prompt.partial(system_message=system_message)\n", " prompt = prompt.partial(tool_names=\", \".join([tool.name for tool in tools]))\n", " #llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])\n", " return prompt | llm.bind_tools(tools)\n", " #agent = prompt | llm_with_tools\n", " #return agent\n", "\n", "\n", "## Define state\n", "# This defines the object that is passed between each node\n", "# in the graph. We will create different nodes for each agent and tool\n", "class AgentState(TypedDict):\n", " messages: Annotated[Sequence[BaseMessage], operator.add]\n", " sender: str\n", "\n", "\n", "# Helper function to create a node for a given agent\n", "def agent_node(state, agent, name):\n", " result = agent.invoke(state)\n", " # We convert the agent output into a format that is suitable to append to the global state\n", " if isinstance(result, ToolMessage):\n", " pass\n", " else:\n", " result = AIMessage(**result.dict(exclude={\"type\", \"name\"}), name=name)\n", " return {\n", " \"messages\": [result],\n", " # Since we have a strict workflow, we can\n", " # track the sender so we know who to pass to next.\n", " \"sender\": name,\n", " }\n", "\n", "\n", "## Define Agents Node\n", "# Research agent and node\n", "from prompt import agent_meta\n", "agent_name = [meta['name'] for meta in agent_meta]\n", "\n", "agents={}\n", "agent_nodes={}\n", "\n", "for meta in agent_meta:\n", " name = meta['name']\n", " prompt = meta['prompt']\n", " \n", " agents[name] = create_agent(\n", " llm,\n", " tools,\n", " system_message=prompt,\n", " )\n", " \n", " agent_nodes[name] = functools.partial(agent_node, agent=agents[name], name=name)\n", "\n", "\n", "## Define Tool Node\n", "from langgraph.prebuilt import ToolNode\n", "from typing import Literal\n", "\n", "tool_node = ToolNode(tools)\n", "\n", "def router(state) -> Literal[\"call_tool\", \"__end__\", \"continue\"]:\n", " # This is the router\n", " messages = state[\"messages\"]\n", " last_message = messages[-1]\n", " if last_message.tool_calls:\n", " # The previous agent is invoking a tool\n", " return \"call_tool\"\n", " if \"FINAL ANSWER\" in last_message.content:\n", " # Any agent decided the work is done\n", " return \"__end__\"\n", " return \"continue\"\n", "\n", "\n", "## Workflow Graph\n", "workflow = StateGraph(AgentState)\n", "\n", "# add agent nodes\n", "for name, node in agent_nodes.items():\n", " workflow.add_node(name, node)\n", " \n", "workflow.add_node(\"call_tool\", tool_node)\n", "\n", "\n", "workflow.add_conditional_edges(\n", " \"analyst\",\n", " router,\n", " {\"continue\": \"data_collector\", \"call_tool\": \"call_tool\", \"__end__\": END}\n", ")\n", "\n", "workflow.add_conditional_edges(\n", " \"data_collector\",\n", " router,\n", " {\"call_tool\": \"call_tool\", \"continue\": \"reporter\", \"__end__\": END}\n", ")\n", "\n", "workflow.add_conditional_edges(\n", " \"reporter\",\n", " router,\n", " {\"continue\": \"data_collector\", \"call_tool\": \"call_tool\", \"__end__\": END}\n", ")\n", "\n", "workflow.add_conditional_edges(\n", " \"call_tool\",\n", " # Each agent node updates the 'sender' field\n", " # the tool calling node does not, meaning\n", " # this edge will route back to the original agent\n", " # who invoked the tool\n", " lambda x: x[\"sender\"],\n", " {name:name for name in agent_name},\n", ")\n", "workflow.add_edge(START, \"analyst\")\n", "graph = workflow.compile()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# from IPython.display import Image, display\n", "\n", "# try:\n", "# display(Image(graph.get_graph(xray=True).draw_mermaid_png()))\n", "# except Exception:\n", "# # This requires some extra dependencies and is optional\n", "# pass" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "Name: analyst\n", "Tool Calls:\n", " nearby_search (call_P34CTmQBMFVscuCNoXAMPeoc)\n", " Call ID: call_P34CTmQBMFVscuCNoXAMPeoc\n", " Args:\n", " input_dict: {'keyword': 'ร้านของชำ', 'location_name': 'อนุสาวรีย์ชัยสมรภูมิ', 'radius': 1000, 'place_type': 'store'}\n", " google_places (call_KOeGzcJyOhVGgxmdAw9a6UoH)\n", " Call ID: call_KOeGzcJyOhVGgxmdAw9a6UoH\n", " Args:\n", " query: อนุสาวรีย์ชัยสมรภูมิ\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n", "Name: nearby_search\n", "\n", "number of results: 18\n", "\n", " address: 163, 25 Soi Phetchaburi 5, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7575211, 'lng': 100.5284703}\n", "\n", " lacation_name: ร้านค้า พรรณี\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 5\n", "\n", " plus code: 7P52QG5H+29\n", "\n", "\n", " \n", " address: เลขที่ 467 1 Ratchawithi Rd, Thanon Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7642431, 'lng': 100.539397}\n", "\n", " lacation_name: ร้านกิตติของชำ\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 4\n", "\n", " plus code: 7P52QG7Q+MQ\n", "\n", "\n", " \n", " address: สมใจอพาร์ทเม้นท์ 184/4 Soi Phahon Yothin 1, Phaya Thai\n", "\n", " location: {'lat': 13.7698885, 'lng': 100.5358358}\n", "\n", " lacation_name: ขายของ\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 4.5\n", "\n", " plus code: 7P52QG9P+W8\n", "\n", "\n", " \n", " address: 476 ตลาดศรีวนิช ซอย Thanon Asok - Din Daeng, Din Daeng\n", "\n", " location: {'lat': 13.7631408, 'lng': 100.5455863}\n", "\n", " lacation_name: ร้านปิ่นสุวรรณ\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 4.4\n", "\n", " plus code: 7P52QG7W+76\n", "\n", "\n", " \n", " address: 140/6 Ratchawithi Rd, Phaya Thai\n", "\n", " location: {'lat': 13.7708078, 'lng': 100.5345492}\n", "\n", " lacation_name: ร้านแอมโชห่วย\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 5\n", "\n", " plus code: 7P52QGCM+8R\n", "\n", "\n", " \n", " address: 156/5 ซอย เพชรบุรี 7 Phetchaburi Rd, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7564968, 'lng': 100.5303369}\n", "\n", " lacation_name: ร้านชำคุณภาวิมล\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 3\n", "\n", " plus code: 7P52QG4J+H4\n", "\n", "\n", " \n", " address: 292 Takhe Alley, Din Daeng\n", "\n", " location: {'lat': 13.7623644, 'lng': 100.5454444}\n", "\n", " lacation_name: ร้านนุสรา\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 4.3\n", "\n", " plus code: 7P52QG6W+W5\n", "\n", "\n", " \n", " address: เลขที่ 475 Phaya Thai Rd, Khwaeng Thanon Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7583454, 'lng': 100.5356299}\n", "\n", " lacation_name: ขายของชำ ประตูน้ำ\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 5\n", "\n", " plus code: 7P52QG5P+87\n", "\n", "\n", " \n", " address: 208/1 Ratchaprarop Rd, Makkasan, Ratchathewi\n", "\n", " location: {'lat': 13.758491, 'lng': 100.5467617}\n", "\n", " lacation_name: ร้านแดง ขายของชำ\n", "\n", " opening hours: {}\n", "\n", " rating: 0\n", "\n", " plus code: 7P52QG5W+9P\n", "\n", "\n", " \n", " address: Satsana Alley, Phaya Thai\n", "\n", " location: {'lat': 13.7752298, 'lng': 100.5344783}\n", "\n", " lacation_name: ร้านชำปากมาสด้า\n", "\n", " opening hours: N/A\n", "\n", " rating: 5\n", "\n", " plus code: 7P52QGGM+3Q\n", "\n", "\n", " \n", " address: 158, ถนนเพชรบุรี, แขวงถนนพญาไท เขตราชเทวี กทม, 10400\n", "\n", " location: {'lat': 13.7539101, 'lng': 100.5388145}\n", "\n", " lacation_name: โชคดีพานิช\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 3\n", "\n", " plus code: N/A\n", "\n", "\n", " \n", " address: QG6W+V6W, Soi Talat Sri Wanit, Din Daeng\n", "\n", " location: {'lat': 13.7622819, 'lng': 100.5456102}\n", "\n", " lacation_name: Shoping Minimart\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 0\n", "\n", " plus code: N/A\n", "\n", "\n", " \n", " address: 421 6-7 Ratchawithi Rd, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.765786, 'lng': 100.5366638}\n", "\n", " lacation_name: Komol Center\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 4.1\n", "\n", " plus code: 7P52QG8P+8M\n", "\n", "\n", " \n", " address: 164 52 Soi Nom Chit, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7549367, 'lng': 100.5312989}\n", "\n", " lacation_name: ร้านนันทา\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 0\n", "\n", " plus code: 7P52QG3J+XG\n", "\n", "\n", " \n", " address: 156/2 ซอย เพชรบุรี 7 Phetchaburi Rd, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7564122, 'lng': 100.5303184}\n", "\n", " lacation_name: ร้านชำทองศรี\n", "\n", " opening hours: N/A\n", "\n", " rating: 0\n", "\n", " plus code: 7P52QG4J+H4\n", "\n", "\n", " \n", " address: QG6V+8G2, Soi Ratchaprarop 22, Makkasan, Ratchathewi\n", "\n", " location: {'lat': 13.7607492, 'lng': 100.5437717}\n", "\n", " lacation_name: PB Minimart\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 0\n", "\n", " plus code: N/A\n", "\n", "\n", " \n", " address: 5 ซอย อร่ามศรี Phaya Thai Rd, Thung Phaya Thai, Ratchathewi\n", "\n", " location: {'lat': 13.7552514, 'lng': 100.5324115}\n", "\n", " lacation_name: อนิรุช มินิมาร์ท\n", "\n", " opening hours: {'open_now': True}\n", "\n", " rating: 0\n", "\n", " plus code: 7P52QG4J+4X\n", "\n", "\n", " \n", " address: 208/1 Ratchaprarop Rd, Makkasan, Ratchathewi\n", "\n", " location: {'lat': 13.758491, 'lng': 100.5467617}\n", "\n", " lacation_name: ร้านป้าแดง มินิมาร์ท\n", "\n", " opening hours: {}\n", "\n", " rating: 0\n", "\n", " plus code: 7P52QG5W+9P\n", "\n", "\n", " \n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "Name: analyst\n", "\n", "I have gathered information about grocery stores (ร้านของชำ) near the Victory Monument (อนุสาวรีย์ชัยสมรภูมิ). Here are some of the notable results:\n", "\n", "1. **ร้านของชำ 1**\n", " - **Address:** 163, 25 Soi Phetchaburi 5, Thung Phaya Thai, Ratchathewi\n", " - **Location:** Latitude 13.7575211, Longitude 100.5284703\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "2. **ร้านของชำ 2**\n", " - **Address:** 467 1 Ratchawithi Rd, Thanon Phaya Thai, Ratchathewi\n", " - **Location:** Latitude 13.7642431, Longitude 100.539397\n", " - **Rating:** 4\n", " - **Open Now:** Yes\n", "\n", "3. **ร้านของชำ 3**\n", " - **Address:** 184/4 Soi Phahon Yothin 1, Phaya Thai\n", " - **Location:** Latitude 13.7698885, Longitude 100.5358358\n", " - **Rating:** 4.5\n", " - **Open Now:** Yes\n", "\n", "4. **ร้านของชำ 4**\n", " - **Address:** 476 Thanon Asok - Din Daeng, Din Daeng\n", " - **Location:** Latitude 13.7631408, Longitude 100.5455863\n", " - **Rating:** 4.4\n", " - **Open Now:** Yes\n", "\n", "5. **ร้านของชำ 5**\n", " - **Address:** 140/6 Ratchawithi Rd, Phaya Thai\n", " - **Location:** Latitude 13.7708078, Longitude 100.5345492\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "There are a total of 18 grocery stores found in the vicinity.\n", "\n", "Next, I will need to gather demographic data regarding the population in the area surrounding the Victory Monument to analyze the business opportunity further. Please hold on while I collect that information.\n", "Tool Calls:\n", " google_places (call_WuhlWTBQgU0nZwbMBdCVwf6i)\n", " Call ID: call_WuhlWTBQgU0nZwbMBdCVwf6i\n", " Args:\n", " query: Victory Monument Bangkok demographics\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n", "Name: google_places\n", "\n", "1. Victory Monument\n", "Address: QG7Q+X87, Phahon Yothin Rd, Khwaeng Thanon Phaya Thai, Khet Ratchathewi, Krung Thep Maha Nakhon 10400, Thailand\n", "Google place ID: ChIJgV6P8rCe4jARDeGu63VNWdQ\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "2. Victory Monument\n", "Address: Thanon Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJgyNezLae4jARDb68DW25BV8\n", "Phone: Unknown\n", "Website: http://www.bts.co.th/\n", "\n", "\n", "3. Victory Monument\n", "Address: Thanon Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJEwyQ3rCe4jARk62JeFdOh4g\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "4. Victory momument market\n", "Address: QG7Q+JFF, Thanon Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJ20qIBgCf4jAR2GmWQw3fYN0\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "5. Victory Monument (Ratchawithi side)\n", "Address: Thung Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJ-fASHLGe4jAR6aspBE2QiTk\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "6. VIX Bangkok Hotel @ Victory Monument\n", "Address: 459 13-15 Thanon Ratchawithi, Khwaeng Thanon Phaya Thai, Khet Ratchathewi, Krung Thep Maha Nakhon 10400, Thailand\n", "Google place ID: ChIJi6NE7LGe4jARIVOxSOdE7Ns\n", "Phone: 065 441 4164\n", "Website: https://www.vixbangkokhotel.com/\n", "\n", "\n", "7. Victory Point\n", "Address: QG7Q+F9R, ซอยราชวิถี 9 (เลิศปัญญา, Khwaeng Thanon Phaya Thai, Khet Ratchathewi, Krung Thep Maha Nakhon 10400, Thailand\n", "Google place ID: ChIJO4Fr2rCe4jARspM8TZcOE7E\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "8. Victory Monument (Phaya Thai Side)\n", "Address: Thanon Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJj3NG3rCe4jARZCgajLqNYwY\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "9. Victory Monument (Din Daeng side)\n", "Address: Thanon Phaya Thai, Ratchathewi, Bangkok 10400, Thailand\n", "Google place ID: ChIJuWPz8bCe4jAR5dvTSk4O8uk\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "10. World War I Volunteer Monument\n", "Address: 4 Soi Na Phra That, Khwaeng Phra Borom Maha Ratchawang, Khet Phra Nakhon, Krung Thep Maha Nakhon 10200, Thailand\n", "Google place ID: ChIJr1UBJw2Z4jARZ5tidTivoDA\n", "Phone: Unknown\n", "Website: http://www.resource.lib.su.ac.th/rattanakosin/index.php/2014-10-27-08-52-05/2015-10-19-03-54-00/2015-10-19-04-17-51\n", "\n", "\n", "11. King Rama VI Monument\n", "Address: 315 Thanon Ratchawithi, Khwaeng Thung Phaya Thai, Khet Ratchathewi, Krung Thep Maha Nakhon 10400, Thailand\n", "Google place ID: ChIJ8825fLKe4jAR4OhUee1Kyfc\n", "Phone: Unknown\n", "Website: Unknown\n", "\n", "\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "Name: analyst\n", "\n", "I was unable to find specific demographic data directly related to the population around the Victory Monument. However, I can summarize the key points regarding the grocery stores found in the area:\n", "\n", "### Grocery Stores Near Victory Monument:\n", "1. **ร้านของชำ 1**\n", " - **Address:** 163, 25 Soi Phetchaburi 5, Thung Phaya Thai, Ratchathewi\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "2. **ร้านของชำ 2**\n", " - **Address:** 467 1 Ratchawithi Rd, Thanon Phaya Thai, Ratchathewi\n", " - **Rating:** 4\n", " - **Open Now:** Yes\n", "\n", "3. **ร้านของชำ 3**\n", " - **Address:** 184/4 Soi Phahon Yothin 1, Phaya Thai\n", " - **Rating:** 4.5\n", " - **Open Now:** Yes\n", "\n", "4. **ร้านของชำ 4**\n", " - **Address:** 476 Thanon Asok - Din Daeng, Din Daeng\n", " - **Rating:** 4.4\n", " - **Open Now:** Yes\n", "\n", "5. **ร้านของชำ 5**\n", " - **Address:** 140/6 Ratchawithi Rd, Phaya Thai\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "### Next Steps:\n", "To analyze the business opportunity effectively, I recommend looking into local demographic statistics such as population density, average income, and consumer behavior in the Ratchathewi district. This information can often be found through local government resources or demographic research websites.\n", "\n", "If you need further assistance in gathering specific demographic data or any other information, please let me know!\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "Name: data_collector\n", "\n", "FINAL ANSWER: I have gathered information about grocery stores near the Victory Monument (อนุสาวรีย์ชัยสมรภูมิ) and summarized the key points regarding the stores. However, I was unable to find specific demographic data directly related to the population around the Victory Monument. \n", "\n", "### Grocery Stores Near Victory Monument:\n", "1. **ร้านของชำ 1**\n", " - **Address:** 163, 25 Soi Phetchaburi 5, Thung Phaya Thai, Ratchathewi\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "2. **ร้านของชำ 2**\n", " - **Address:** 467 1 Ratchawithi Rd, Thanon Phaya Thai, Ratchathewi\n", " - **Rating:** 4\n", " - **Open Now:** Yes\n", "\n", "3. **ร้านของชำ 3**\n", " - **Address:** 184/4 Soi Phahon Yothin 1, Phaya Thai\n", " - **Rating:** 4.5\n", " - **Open Now:** Yes\n", "\n", "4. **ร้านของชำ 4**\n", " - **Address:** 476 Thanon Asok - Din Daeng, Din Daeng\n", " - **Rating:** 4.4\n", " - **Open Now:** Yes\n", "\n", "5. **ร้านของชำ 5**\n", " - **Address:** 140/6 Ratchawithi Rd, Phaya Thai\n", " - **Rating:** 5\n", " - **Open Now:** Yes\n", "\n", "For further analysis, I recommend looking into local demographic statistics such as population density, average income, and consumer behavior in the Ratchathewi district. If you need more assistance, feel free to ask!\n" ] } ], "source": [ "# question = \"ค้นหาร้านของชำใกล้อนุสาวรีย์ชัยฯ พร้อมวิเคราะห์จำนวนประชากร\"\n", "\n", "# graph = workflow.compile()\n", "\n", "# events = graph.stream(\n", "# {\n", "# \"messages\": [\n", "# HumanMessage(\n", "# question\n", "# )\n", "# ],\n", "# },\n", "# # Maximum number of steps to take in the graph\n", "# {\"recursion_limit\": 20},\n", "# )\n", "# for s in events:\n", "# # print(s)\n", "# a = list(s.items())[0]\n", "# a[1]['messages'][0].pretty_print()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def submitUserMessage(user_input: str) -> str:\n", " graph = workflow.compile()\n", "\n", " events = graph.stream(\n", " {\n", " \"messages\": [\n", " HumanMessage(\n", " user_input\n", " )\n", " ],\n", " },\n", " # Maximum number of steps to take in the graph\n", " {\"recursion_limit\": 20},\n", " )\n", " \n", " events = [e for e in events]\n", " \n", " response = list(events[-1].values())[0][\"messages\"][0]\n", " response = response.content\n", " response = response.replace(\"FINAL ANSWER: \", \"\")\n", " \n", " return response\n", "\n", "\n", "# question = \"วิเคราะห์ร้านอาหารแถวลุมพินี เซ็นเตอร์ ลาดพร้าว\"\n", "# submitUserMessage(question)" ] } ], "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 }