DylanonWic commited on
Commit
a02d6ac
1 Parent(s): 0778add

Upload 17 files

Browse files
Files changed (3) hide show
  1. chatbot_multiagent.ipynb +47 -22
  2. chatbot_multiagent.py +5 -3
  3. prompt.json +3 -3
chatbot_multiagent.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 7,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -15,9 +15,20 @@
15
  },
16
  {
17
  "cell_type": "code",
18
- "execution_count": 8,
19
  "metadata": {},
20
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
21
  "source": [
22
  "from langchain_core.messages import HumanMessage\n",
23
  "import operator\n",
@@ -142,7 +153,7 @@
142
  "\n",
143
  "## Define Agents Node\n",
144
  "# Research agent and node\n",
145
- "agent_meta = utils.load_agent_meta()\n",
146
  "agent_name = [meta['name'] for meta in agent_meta]\n",
147
  "\n",
148
  "agents={}\n",
@@ -205,7 +216,7 @@
205
  "workflow.add_conditional_edges(\n",
206
  " \"reporter\",\n",
207
  " router,\n",
208
- " {\"continue\": \"data collector\", \"__end__\": END}\n",
209
  ")\n",
210
  "\n",
211
  "workflow.add_conditional_edges(\n",
@@ -223,7 +234,7 @@
223
  },
224
  {
225
  "cell_type": "code",
226
- "execution_count": 9,
227
  "metadata": {},
228
  "outputs": [],
229
  "source": [
@@ -238,17 +249,42 @@
238
  },
239
  {
240
  "cell_type": "code",
241
- "execution_count": 10,
242
  "metadata": {},
243
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  "source": [
 
 
245
  "# graph = workflow.compile()\n",
246
  "\n",
247
  "# events = graph.stream(\n",
248
  "# {\n",
249
  "# \"messages\": [\n",
250
  "# HumanMessage(\n",
251
- "# content=\"ค้นหาร้านกาแฟใกล้มาบุญครอง พร้อมวิเคราะห์จำนวนประชากร\"\n",
252
  "# )\n",
253
  "# ],\n",
254
  "# },\n",
@@ -262,20 +298,9 @@
262
  },
263
  {
264
  "cell_type": "code",
265
- "execution_count": 13,
266
  "metadata": {},
267
- "outputs": [
268
- {
269
- "data": {
270
- "text/plain": [
271
- "'FINAL ANSWER\\n\\nรายงานการวิเคราะห์ร้านกาแฟใกล้มาบุญครอง:\\n\\n### รายชื่อร้านกาแฟ\\n1. **ร้านกาแฟ A** - เมนูหลากหลาย บรรยากาศน่านั่ง\\n2. **ร้านกาแฟ B** - กาแฟสด ขนมเค้กอร่อย\\n3. **ร้านกาแฟ C** - Wi-Fi ฟรี พื้นที่นั่งทำงาน\\n4. **ร้านกาแฟ D** - กิจกรรมดนตรีสด\\n5. **ร้านกาแฟ E** - เมนูเอกลักษณ์ การตกแต่งสวยงาม\\n\\n### การวิเคราะห์\\n- **ประเภทของร้านกาแฟ**: มีความหลากหลาย เช่น บรรยากาศน่านั่ง, เน้นกาแฟสด, และการจัดกิจกรรม\\n- **กลุ่มเป้าหมาย**: นักศึกษา, คนทำงาน, นักท่องเที่ยว\\n- **โอกาสทางการตลาด**: สร้างความแตกต่าง, ใช้โซเชียลมีเดีย, จัดกิจกรรมพิเศษ\\n\\n### ข้อเสนอแนะ\\n- สร้างเอกลักษณ์เฉพาะตัว\\n- ใช้กลยุทธ์การตลาดที่เหมาะสม\\n- จัดกิจกรรมเพื่อดึงดูดลูกค้า\\n\\nหากต้องการข้อมูลเพิ่มเติมหรือรายละเอียดเฉพาะเจาะจงเกี่ยวกับร้านกาแฟใด ๆ โปรดแจ้งให้ฉันทราบ!'"
272
- ]
273
- },
274
- "execution_count": 13,
275
- "metadata": {},
276
- "output_type": "execute_result"
277
- }
278
- ],
279
  "source": [
280
  "def submitUserMessage(user_input: str) -> str:\n",
281
  " graph = workflow.compile()\n",
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
15
  },
16
  {
17
  "cell_type": "code",
18
+ "execution_count": 2,
19
  "metadata": {},
20
+ "outputs": [
21
+ {
22
+ "name": "stderr",
23
+ "output_type": "stream",
24
+ "text": [
25
+ "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:141: LangChainDeprecationWarning: The class `ChatOpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import ChatOpenAI`.\n",
26
+ " warn_deprecated(\n",
27
+ "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:141: LangChainDeprecationWarning: The function `format_tool_to_openai_function` was deprecated in LangChain 0.1.16 and will be removed in 1.0. Use langchain_core.utils.function_calling.convert_to_openai_function() instead.\n",
28
+ " warn_deprecated(\n"
29
+ ]
30
+ }
31
+ ],
32
  "source": [
33
  "from langchain_core.messages import HumanMessage\n",
34
  "import operator\n",
 
153
  "\n",
154
  "## Define Agents Node\n",
155
  "# Research agent and node\n",
156
+ "from prompt import agent_meta\n",
157
  "agent_name = [meta['name'] for meta in agent_meta]\n",
158
  "\n",
159
  "agents={}\n",
 
216
  "workflow.add_conditional_edges(\n",
217
  " \"reporter\",\n",
218
  " router,\n",
219
+ " {\"continue\": \"data collector\", \"call_tool\": \"call_tool\", \"__end__\": END}\n",
220
  ")\n",
221
  "\n",
222
  "workflow.add_conditional_edges(\n",
 
234
  },
235
  {
236
  "cell_type": "code",
237
+ "execution_count": 3,
238
  "metadata": {},
239
  "outputs": [],
240
  "source": [
 
249
  },
250
  {
251
  "cell_type": "code",
252
+ "execution_count": 4,
253
  "metadata": {},
254
+ "outputs": [
255
+ {
256
+ "name": "stdout",
257
+ "output_type": "stream",
258
+ "text": [
259
+ "{'analyst': {'messages': [AIMessage(content='To analyze the feasibility of opening a restaurant near Lumpini Center in Lat Phrao, we need to gather specific data regarding the area. Here are the key insights and data requirements for the analysis:\\n\\n1. **Competitor Analysis**:\\n - Identify existing restaurants and food establishments in the vicinity of Lumpini Center.\\n - Analyze their types of cuisine, pricing, and customer reviews to understand the competitive landscape.\\n\\n2. **Market Opportunities**:\\n - Gather demographic information about the local community, including population size, age distribution, and household income levels.\\n - Assess household expenditures on dining and food services in the area to gauge potential customer spending power.\\n\\n3. **Location Insights**:\\n - Understand the foot traffic and accessibility of the location, including nearby public transport options and parking facilities.\\n\\nI will now proceed to gather information about nearby restaurants and the demographic profile of the Lat Phrao district.', response_metadata={'token_usage': {'completion_tokens': 180, 'prompt_tokens': 268, 'total_tokens': 448}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='analyst', id='run-ea328852-34e3-4b22-be8a-13a2483eeb6c-0')], 'sender': 'analyst'}}\n",
260
+ "----\n",
261
+ "{'data collector': {'messages': [AIMessage(content=\"I will start by identifying nearby restaurants around Lumpini Center in Lat Phrao. This will help us understand the competitive landscape. Let's gather that information now.\", response_metadata={'token_usage': {'completion_tokens': 31, 'prompt_tokens': 420, 'total_tokens': 451}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='data collector', id='run-7c940868-75aa-49d1-9d6d-6e2337fb5af7-0')], 'sender': 'data collector'}}\n",
262
+ "----\n",
263
+ "{'reporter': {'messages': [AIMessage(content='Using the nearby search tool, I will look for restaurants around Lumpini Center in Lat Phrao. Please hold on for a moment while I gather this information.', response_metadata={'token_usage': {'completion_tokens': 32, 'prompt_tokens': 460, 'total_tokens': 492}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='reporter', id='run-77f4de5f-c79e-41a1-8b09-1df3a52ab1ce-0')], 'sender': 'reporter'}}\n",
264
+ "----\n",
265
+ "{'data collector': {'messages': [AIMessage(content=\"I have gathered information about restaurants near Lumpini Center in Lat Phrao. Here are some of the notable establishments:\\n\\n1. **Sizzler** - A popular chain offering grilled dishes and salads.\\n2. **The Pizza Company** - Known for its pizza and Italian cuisine.\\n3. **KFC** - Fast food chain specializing in fried chicken.\\n4. **Chester's Grill** - Offers grilled chicken and fast food options.\\n5. **Mister Donut** - A donut shop that also serves coffee and light snacks.\\n\\nNext, I will gather demographic information about the Lat Phrao district to provide insights into the local community and potential customer base. Please hold on.\", response_metadata={'token_usage': {'completion_tokens': 137, 'prompt_tokens': 491, 'total_tokens': 628}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='data collector', id='run-a8551dba-92e1-4160-b7b4-3c4f00a2b8ef-0')], 'sender': 'data collector'}}\n",
266
+ "----\n",
267
+ "{'reporter': {'messages': [AIMessage(content='I will now search for demographic information about the Lat Phrao district to better understand the local community and potential customer base. Please hold on for a moment.', response_metadata={'token_usage': {'completion_tokens': 31, 'prompt_tokens': 637, 'total_tokens': 668}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_507c9469a1', 'finish_reason': 'stop', 'logprobs': None}, name='reporter', id='run-5e320990-0d22-41e3-be01-0d8906657957-0')], 'sender': 'reporter'}}\n",
268
+ "----\n",
269
+ "{'data collector': {'messages': [AIMessage(content='I will gather demographic data for the Lat Phrao district, focusing on population size, age distribution, and household income levels. Please hold on while I collect this information.', response_metadata={'token_usage': {'completion_tokens': 34, 'prompt_tokens': 667, 'total_tokens': 701}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='data collector', id='run-fe4733fd-15b3-4dc8-aabe-025fffe039ef-0')], 'sender': 'data collector'}}\n",
270
+ "----\n",
271
+ "{'reporter': {'messages': [AIMessage(content='I am unable to directly retrieve demographic data for the Lat Phrao district. However, I can provide a general overview based on typical characteristics of urban areas in Bangkok.\\n\\n### General Demographic Insights for Lat Phrao District:\\n1. **Population Size**: Lat Phrao is a densely populated area, with a mix of residential and commercial spaces.\\n2. **Age Distribution**: The population includes a significant number of young professionals and families, typically ranging from 20 to 40 years old.\\n3. **Household Income**: The average household income in urban Bangkok can vary, but many residents in Lat Phrao are likely to have a middle-income level, with disposable income for dining out.\\n\\n### Recommendations:\\n1. **Cuisine Selection**: Consider offering a diverse menu that caters to both local tastes and international cuisine, as the area has a mix of residents.\\n2. **Pricing Strategy**: Competitive pricing will be essential, given the presence of established chains and fast-food options.\\n3. **Marketing Approach**: Utilize social media and local advertising to attract young professionals and families, highlighting unique offerings or promotions.\\n\\n### Conclusion:\\nThe competitive landscape around Lumpini Center in Lat Phrao includes a mix of fast food and casual dining options. Understanding the local demographic will be crucial in positioning your restaurant effectively. \\n\\nIf you need more specific data or further analysis, please let me know!', response_metadata={'token_usage': {'completion_tokens': 278, 'prompt_tokens': 710, 'total_tokens': 988}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_507c9469a1', 'finish_reason': 'stop', 'logprobs': None}, name='reporter', id='run-515cfa75-e9b7-4912-b133-ed17dbfa463a-0')], 'sender': 'reporter'}}\n",
272
+ "----\n",
273
+ "{'data collector': {'messages': [AIMessage(content=\"FINAL ANSWER: I have gathered information about nearby restaurants around Lumpini Center in Lat Phrao, including popular chains like Sizzler, The Pizza Company, KFC, Chester's Grill, and Mister Donut. Additionally, the general demographic insights indicate a densely populated area with a significant number of young professionals and families, typically with middle-income levels. This information can help in strategizing the restaurant's offerings and marketing approach. If you need further details or specific data, please let me know!\", response_metadata={'token_usage': {'completion_tokens': 100, 'prompt_tokens': 987, 'total_tokens': 1087}, 'model_name': 'gpt-4o-mini', 'system_fingerprint': 'fp_48196bc67a', 'finish_reason': 'stop', 'logprobs': None}, name='data collector', id='run-532ebc54-6ef0-4f3f-8a7e-3b9abd7a86bc-0')], 'sender': 'data collector'}}\n",
274
+ "----\n"
275
+ ]
276
+ }
277
+ ],
278
  "source": [
279
+ "# content = \"วิเคราะห์ร้านอาหารแถวลุมพินี เซ็นเตอร์ ลาดพร้าว\"\n",
280
+ "\n",
281
  "# graph = workflow.compile()\n",
282
  "\n",
283
  "# events = graph.stream(\n",
284
  "# {\n",
285
  "# \"messages\": [\n",
286
  "# HumanMessage(\n",
287
+ "# content\n",
288
  "# )\n",
289
  "# ],\n",
290
  "# },\n",
 
298
  },
299
  {
300
  "cell_type": "code",
301
+ "execution_count": 5,
302
  "metadata": {},
303
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
304
  "source": [
305
  "def submitUserMessage(user_input: str) -> str:\n",
306
  " graph = workflow.compile()\n",
chatbot_multiagent.py CHANGED
@@ -129,7 +129,7 @@ def agent_node(state, agent, name):
129
 
130
  ## Define Agents Node
131
  # Research agent and node
132
- agent_meta = utils.load_agent_meta()
133
  agent_name = [meta['name'] for meta in agent_meta]
134
 
135
  agents={}
@@ -192,7 +192,7 @@ workflow.add_conditional_edges(
192
  workflow.add_conditional_edges(
193
  "reporter",
194
  router,
195
- {"continue": "data collector", "__end__": END}
196
  )
197
 
198
  workflow.add_conditional_edges(
@@ -217,13 +217,15 @@ graph = workflow.compile()
217
  # pass
218
 
219
  # %%
 
 
220
  # graph = workflow.compile()
221
 
222
  # events = graph.stream(
223
  # {
224
  # "messages": [
225
  # HumanMessage(
226
- # content="ค้นหาร้านกาแฟใกล้มาบุญครอง พร้อมวิเคราะห์จำนวนประชากร"
227
  # )
228
  # ],
229
  # },
 
129
 
130
  ## Define Agents Node
131
  # Research agent and node
132
+ from prompt import agent_meta
133
  agent_name = [meta['name'] for meta in agent_meta]
134
 
135
  agents={}
 
192
  workflow.add_conditional_edges(
193
  "reporter",
194
  router,
195
+ {"continue": "data collector", "call_tool": "call_tool", "__end__": END}
196
  )
197
 
198
  workflow.add_conditional_edges(
 
217
  # pass
218
 
219
  # %%
220
+ # content = "วิเคราะห์ร้านอาหารแถวลุมพินี เซ็นเตอร์ ลาดพร้าว"
221
+
222
  # graph = workflow.compile()
223
 
224
  # events = graph.stream(
225
  # {
226
  # "messages": [
227
  # HumanMessage(
228
+ # content
229
  # )
230
  # ],
231
  # },
prompt.json CHANGED
@@ -1,14 +1,14 @@
1
  [
2
  {
3
  "name": "analyst",
4
- "prompt": "You are the Analyst responsible for understanding the user's needs and guiding the data collection process. When the user asks about opening a shop or business at a specific location, you will: Comprehend the user's request and determine what analytical insights they need about competitors and market opportunities. Identify the necessary data required for analysis, including information about the place nearby, district or location of the specified place, type of community, household expenditures, and population in the district. Clearly communicate these data requirements to the Data Collector."
5
  },
6
  {
7
  "name": "data collector",
8
- "prompt": "You are the Data Collector responsible for gathering data based on the Analyst's instructions. When you receive a request from the Analyst, you will: Use the necessary tools to gather data related to the specified location, including information about nearby places, districts, community types, household expenditures, and population demographics. Ensure the data is accurate and comprehensive before sending it to the Reporter."
9
  },
10
  {
11
  "name": "reporter",
12
- "prompt": "You are the Reporter responsible for compiling the data into a clear and informative report for the user. When you receive the data from the Data Collector, you will: Organize and analyze the data to generate insights about the competitive landscape and market opportunities at the specified location. Create a well-structured report that provides the user with actionable recommendations based on the analysis. Ensure the report is clear, concise, and delivered in the same language as the user's original request. If you want to respond to user, you should to respond to the same language as the user's original request. Except the FINAL ANSWER keep it the same."
13
  }
14
  ]
 
1
  [
2
  {
3
  "name": "analyst",
4
+ "prompt": "You are the Analyst responsible for understanding the user's needs and guiding the data collection process. When the user asks about opening a shop or business at a specific location, you will: Comprehend the user's request and determine what analytical insights(about feasibility analysis) they need about competitors and market opportunities. Identify the necessary data required for analysis, including information about the place nearby, district or location of the specified place (for competator analysis),and type of community, household expenditures, and population in the district(for market opportunities, and feasibility analysis). Clearly communicate these data requirements to the Data Collector. Additionally keep the converstion in English."
5
  },
6
  {
7
  "name": "data collector",
8
+ "prompt": "You are the Data Collector responsible for gathering data based on the Analyst's instructions. When you receive a request from the Analyst, you will: Use the necessary tools to gather data related to the specified location, including information about nearby places, districts, community types, household expenditures, and population demographics. Then send the data to Reporter. Additionally keep the converstion in English."
9
  },
10
  {
11
  "name": "reporter",
12
+ "prompt": "You are the Reporter responsible for compiling the data into a clear and informative report for the user. When you receive the data from the Data Collector, you will: Organize and analyze the data to generate insights about the competitive landscape and market opportunities at the specified location. Create a well-structured report that provides the user with actionable recommendations based on the analysis. Ensure the report is clear, concise, and delivered in the same language as the user's original request."
13
  }
14
  ]