colin4554 commited on
Commit
12f769d
1 Parent(s): ab1773b

cleanup structure

Browse files
Files changed (5) hide show
  1. app.py +74 -29
  2. functions.py +129 -81
  3. home_depot_data.csv +0 -0
  4. home_depot_result.py +225 -0
  5. requirements.txt +4 -1
app.py CHANGED
@@ -4,13 +4,13 @@ from openai import AzureOpenAI
4
 
5
  from functions import call_function
6
 
7
- st.title("Support Chat UI")
8
  # when will my order be delivered?, colin.flueck@gmail.com W123123
9
 
10
  functions = [
11
  {
12
- "name": "order_tracking_status",
13
- "description": "Retrieves the status of an order based on **both** the email address and order number.",
14
  "parameters": {
15
  "type": "object",
16
  "properties": {
@@ -26,17 +26,45 @@ functions = [
26
  "required": ["email_address", "order_number"]
27
  }
28
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  {
30
  "name": "refer_to_human_agent",
31
  "description": "Use this to refer the customer's question to a human agent. You should only call this "
32
- "function if you don't know how to answer the inquiry?.",
33
  "parameters": {
34
  "type": "object",
35
  "properties": {
36
  "conversation_summary": {
37
  "type": "string",
38
- "description": "A short summary of the current conversation so the agent can quickly get up to "
39
- "speed. Make sure you include all relevant details. "
40
  },
41
  },
42
  "required": ["conversation_summary"]
@@ -54,9 +82,8 @@ if "openai_model" not in st.session_state:
54
  st.session_state["openai_model"] = "gpt-35-turbo"
55
 
56
  if "messages" not in st.session_state:
57
- st.session_state.messages = [{"role": "system", "content": "You are a helpful customer support agent for Lowes."
58
- "Be as helpful as possible and call "
59
- "functions when necessary."},]
60
 
61
  for message in st.session_state.messages:
62
  if message["role"] == "assistant" or message["role"] == "user":
@@ -76,16 +103,46 @@ if prompt := st.chat_input("How can we help you today?"):
76
  "arguments": "",
77
  }
78
 
79
- called_function = True
80
- while called_function:
81
- called_function = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  for response in client.chat.completions.create(
83
  model=st.session_state["openai_model"],
84
  messages=[
85
- {"role": m["role"], "content": m["content"], "name": m["name"]} if "name" in m else
86
- {"role": m["role"], "content": m["content"]}
87
- for m in st.session_state.messages
88
- ],
89
  functions=functions,
90
  function_call="auto",
91
  stream=True,
@@ -100,19 +157,7 @@ if prompt := st.chat_input("How can we help you today?"):
100
  if delta.function_call.arguments is not None:
101
  func_call["arguments"] += delta.function_call.arguments
102
 
103
- message_placeholder.markdown(full_message + "")
104
-
105
- if func_call["name"] is not None:
106
- print(f"Function generation requested, calling function")
107
- function_response = call_function(st.session_state.messages, func_call)
108
- print("function response")
109
- print(function_response)
110
- st.session_state.messages.append(function_response)
111
- called_function = True
112
- func_call = {
113
- "name": None,
114
- "arguments": "",
115
- }
116
 
117
  message_placeholder.markdown(full_message)
118
 
 
4
 
5
  from functions import call_function
6
 
7
+ st.title("SupportFlow Demo")
8
  # when will my order be delivered?, colin.flueck@gmail.com W123123
9
 
10
  functions = [
11
  {
12
+ "name": "lookup_order_status",
13
+ "description": "Retrieves the status, location, etc. of an order based on **both** the email address and order number.",
14
  "parameters": {
15
  "type": "object",
16
  "properties": {
 
26
  "required": ["email_address", "order_number"]
27
  }
28
  },
29
+ # {
30
+ # "name": "lookup_product",
31
+ # "description": "Returns a detailed list of products based on a product query.",
32
+ # "parameters": {
33
+ # "type": "object",
34
+ # "properties": {
35
+ # "query": {
36
+ # "type": "string",
37
+ # "description": "Product query to search for like drills, lights, or hammers"
38
+ # },
39
+ # },
40
+ # "required": ["query"]
41
+ # }
42
+ # },
43
+ # {
44
+ # "name": "get_product_listing",
45
+ # "description": "Returns information about the product based on the SKU.",
46
+ # "parameters": {
47
+ # "type": "object",
48
+ # "properties": {
49
+ # "sku": {
50
+ # "type": "integer",
51
+ # "description": "Product sku to search for like 123123"
52
+ # },
53
+ # },
54
+ # "required": ["sku"]
55
+ # }
56
+ # },
57
  {
58
  "name": "refer_to_human_agent",
59
  "description": "Use this to refer the customer's question to a human agent. You should only call this "
60
+ "function if there is no way for you to answer their question.",
61
  "parameters": {
62
  "type": "object",
63
  "properties": {
64
  "conversation_summary": {
65
  "type": "string",
66
+ "description": "A short summary of the current conversation so the human agent can quickly get up "
67
+ "to speed. Make sure you include all relevant details."
68
  },
69
  },
70
  "required": ["conversation_summary"]
 
82
  st.session_state["openai_model"] = "gpt-35-turbo"
83
 
84
  if "messages" not in st.session_state:
85
+ st.session_state.messages = [{"role": "system", "content": "You are a helpful customer support agent for The Home "
86
+ "Depot. Your goal is to answer as many questions as possible without escalating to a human agent."},]
 
87
 
88
  for message in st.session_state.messages:
89
  if message["role"] == "assistant" or message["role"] == "user":
 
103
  "arguments": "",
104
  }
105
 
106
+ for response in client.chat.completions.create(
107
+ model=st.session_state["openai_model"],
108
+ messages=[
109
+ {"role": m["role"], "content": m["content"], "name": m["name"]} if "name" in m else
110
+ {"role": m["role"], "content": m["content"]}
111
+ for m in st.session_state.messages
112
+ ],
113
+ functions=functions,
114
+ function_call="auto",
115
+ stream=True,
116
+ ):
117
+ if len(response.choices) > 0:
118
+ delta = response.choices[0].delta
119
+
120
+ full_message += (delta.content or "")
121
+ if delta.function_call is not None:
122
+ if delta.function_call.name is not None:
123
+ func_call["name"] = delta.function_call.name
124
+ if delta.function_call.arguments is not None:
125
+ func_call["arguments"] += delta.function_call.arguments
126
+
127
+ message_placeholder.markdown(full_message + "")
128
+
129
+ if func_call["name"] is not None and func_call["arguments"] != "":
130
+ print(f"Function generation requested, calling function")
131
+ function_response = call_function(st.session_state.messages, func_call)
132
+ print("function response")
133
+ print(function_response)
134
+ st.session_state.messages.append(function_response)
135
+
136
+ message_placeholder = st.empty()
137
+ full_message = ""
138
+
139
  for response in client.chat.completions.create(
140
  model=st.session_state["openai_model"],
141
  messages=[
142
+ {"role": m["role"], "content": m["content"], "name": m["name"]} if "name" in m else
143
+ {"role": m["role"], "content": m["content"]}
144
+ for m in st.session_state.messages
145
+ ],
146
  functions=functions,
147
  function_call="auto",
148
  stream=True,
 
157
  if delta.function_call.arguments is not None:
158
  func_call["arguments"] += delta.function_call.arguments
159
 
160
+ message_placeholder.markdown(full_message + "")
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  message_placeholder.markdown(full_message)
163
 
functions.py CHANGED
@@ -1,6 +1,9 @@
1
  import json
2
- from typing import Any, Dict
3
  import requests
 
 
 
4
 
5
 
6
  def call_function(messages, function_call):
@@ -8,13 +11,13 @@ def call_function(messages, function_call):
8
  Currently extended by adding clauses to this if statement."""
9
  print(function_call)
10
 
11
- if function_call["name"] == "order_tracking_status":
12
  try:
13
  parsed_output = json.loads(
14
  function_call["arguments"]
15
  )
16
  print("Looking up order status")
17
- results = get_order_tracking_status(parsed_output["email_address"], parsed_output["order_number"])
18
  return {
19
  "role": "function",
20
  "name": function_call["name"],
@@ -24,7 +27,39 @@ def call_function(messages, function_call):
24
  # print(parsed_output)
25
  print(f"Function execution failed")
26
  print(f"Error message: {e}")
27
- return {"role": "function", "content": "call failed", "name": "order_tracking_status"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  elif function_call["name"] == "refer_to_human_agent":
29
  try:
30
  parsed_output = json.loads(
@@ -46,96 +81,109 @@ def call_function(messages, function_call):
46
  raise Exception("Function does not exist and cannot be called")
47
 
48
 
49
- def get_order_tracking_status(email_address: str, order_number: int) -> str:
50
- url = "https://www.lowes.com/api/mylowes/orders/details"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- payload = json.dumps({
53
- "masterOrderNumber": f"{order_number}",
54
- "emailId": f"{email_address}",
55
- "type": "online",
56
- "storeNumber": "1875"
57
- })
58
  headers = {
59
  'authority': 'www.lowes.com',
60
- 'accept': 'application/json, text/plain, */*',
61
  'accept-language': 'en-US,en;q=0.9',
62
- 'content-type': 'application/json',
63
- 'cookie': 'dbidv2=56b2862a-8fa1-4476-ae09-6368c4fab002; al_sess=FuA4EWsuT07UWryyq/3foEQIwIqOxmho8CAP0qIisJkWP6yrEciiDxJiF8HPZ/09; HPLA=1; region=east; AKA_A2=A; EPID=NTZiMjg2MmEtOGZhMS00NDc2LWFlMDktNjM2OGM0ZmFiMDAy; bm_sz=FD2C6C9185843B61533705694D14EF09~YAAQTCXRFy7EGs+LAQAA9Cok5BVOqBRlOAkc2ibX247znTkInxYHj4yFBMY+lWEGSucc9Vag1mzB5owd7ujrIa8Tt+k8M+uWh6wPPUWz3QF7RpyIyxsA4NOmjVwds1rEkGCtXtnhtxNvg9eoBeVW2rKmOI+Wo6eeyG5ZD/Be3I8J0Mw859Xt03pOB7zh2NviHhi1rTbZLCqj7ihbL4OpgQWv4gd8p5JX2VOFHAjWA3xPtGEVZuPn3tcMJTKbETxO4xHmmO+ER0l6Pgsk+hDYu/G6s71XDkkcDyR2XosdOhO9sIYljoBjBCGktjJird6wvK8WJEC+9WFKdeY=~3486278~4604217; TAsessionID=0421ade3-7a84-4692-9ad8-d67927442c16|NEW; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQTCXRF0zEGs+LAQAALC0k5BVU2zm/cgpTeSAB5oJBqTX8djy+rUtTzcodc06GoFRo/QB3NhhzPSPPvUd6lmCx0k5hK2OgXrT0s2ifZbUneCF7u/kOPX+aDP51oWsuZnVOScC1doltiJAJ7UVHfSlZ+7aCjw5+bm5istYopvV+sJHwtPdNabdtculQtPwq7uRDJadaMZCd+pieFtiMEltlxmCTYZp0ATGsxOSnqKn01LIOMAPHUNIJivM9tMPTSvDvr3mW0JbB7slTFD5CHuRLWYhHtT5LT8BzF0R3VTy+SGkrzdLyF8IuQmFfWAiT7FIHUrDtcxRZpjQUBkenz8ObtREzb23FobM3pWZgb9YbdxnxCUdgUnI33Hkh+uKFxNHfnCLCtwddDQ==; ph_aid=3c68acb4-b3eb-487a-fc03-1cd3fc616418-7080571749703-454eb8c121d15-bf29dec353e8d; _lgsid=1700339660085; sn=1875; sd=%7B%22id%22%3A%221875%22%2C%22zip%22%3A%2230307%22%2C%22city%22%3A%22Atlanta%22%2C%22state%22%3A%22GA%22%2C%22name%22%3A%22Atlanta-Edgewood%20Lowe\'s%22%2C%22region%22%3A%223%22%7D; zipcode=30307; nearbyid=1875; zipstate=GA; bm_mi=6808FB6A942BFA186D4C6F584A7C2C13~YAAQTCXRFzfLGs+LAQAA1fMk5BW7b5b1fpebVli+q0WvFABZFCZymNL07sKET78++WCh2c2PlR2cWb0Mhgy6c0kb+eQQXXnhzTvCBO+c3SXbahePgkJIiNOjvqCpTFDAiy4o0TOqYYTsE6ZalTslHCv7kgGY96uF1sBUFxvNqSN3/Cj5CGcIaCwZZb15pkIFLj7DXqoZ+AEYScs4TUAzhDbJ/g1ShZGx0fUeUqHVwn3pzgdFuuPh2O/WTXQzA4lgzTY+dkhTw5pdbc8vvsu7SdXK0d6R0JW3UyuP5oMThUuIetC0PoVSmycGaHLIPz16~1; user=%7B%22zipPrompt%22%3Atrue%7D; audience=DIY; _abck=84784437A2290F7C7665B869C07C4FDE~0~YAAQTCXRFznOGs+LAQAApl0l5AoUWttzoglFBJBV0r/WGr6wXArpqRxmVKRftBWRNCD7Rc/+z809D45jGbTU0yldpjr9Jq5XeDPG1B6Gdkb3oeu+pL7t1YdLuYUU8pdsnTHiuNU6zW7wKAyzF7lmeXACJHQrlO7cN+zqBaTaile96J18Gj82+zHpDvkU1RuhcqH3rNlV8jq8Ecn8rminJr1LfE4xiOM6SH6yL0eFVl2T4wbNOpIhlZ7ycluXvEHEJQYrb8U3me7oJ0FVDbKXa8mi50c3LPk/maBSzz3LXvK8WwXAiMgWMnu7+D4r96p9YKKXVxiN2khwsm/YixV2j5vtGCEboSy+yWcBTZyDimKxpCf8JYbPRVvJyvgFmbEY/IZcDkueOCKIGxIsSfP+pyReapNRw0cvwmyBtzKDX4bnjU9lGGWZeoEUzwYzpheqs6Z2NyPpkpIl~-1~-1~-1; prodNumber=2; akavpau_default=1700340036~id=0d6c97bed4e510e00b212e2c7151704a; akavpau_cart=1700340038~id=c8d179c7ab834971d54fb6b3f37fb5cd; notice_behavior=implied,eu; p13n=%7B%22zipCode%22%3A%2230307%22%2C%22storeId%22%3A%221875%22%2C%22state%22%3A%22GA%22%2C%22audienceList%22%3A%5B%5D%7D; g_previous=%7B%22gpvPageLoadTime%22%3A%220.00%22%2C%22gpvPageScroll%22%3A%228%7C9%7C0%7C10258%22%2C%22gpvSitesections%22%3A%22checkorderstatus%22%2C%22gpvSiteId%22%3A%22desktop%22%2C%22gpvPageType%22%3A%22check-order-status%22%7D; PT_ST=6c202780-f553-4693-bb78-129dedacc842; akaalb_prod_dual=1700426396~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=ddbf1d57536e8f52d396da19f5e80dc4; bm_sv=8B13230A1BED940DF1CD6E283A4D1610~YAAQTCXRFx0AG8+LAQAAb1Yp5BXh8z5aM//hZ+YV+MjKJgNR34HJmJZTf3AixPor3SXeREgpHBbsqJUONoLbqAG1NGKbZR0gevtiZH9fdU0VojEHjQOvH0dbif9h9QivxlMSphKTTDy5EQYEFumXDVmNKtMKFjh6uV5Imj2r5hfucyAyTZiQ6V0yOiRigqEUDnY3Yzx2y2CPKvHPpgOLu6NREx34B64M8OOl2nzIJCzlhZfizbm8tDyr6+YYRtgB~1; _abck=84784437A2290F7C7665B869C07C4FDE~-1~YAAQTCXRFyEKG8+LAQAAmScq5AqXSATqkt25kWxxHAg3BLxuo+Nz1ihcUXOUs/s0PjLsQmvz72U0IrKBhYjfN6DLPT0x/N4/ntmJOZQYWN0SUrK3S1MKBuDFQWRMQAdDYPgPrQ9sGLxg/9jiUX8mNYgODb9F9iOKvS0tl0W1MBaPygnbVYeo6YYU/7/GV3KuiLSUbHLRn2Y49ltGRz4SFJpy12VJTBP4f1SYjBovTH3WlsVfdVbY/4YNfGuA862HvGYwo2D7oDMhZsMxZNdm8vBEeGJS0GyOTmeZtUal0izS3wq6KC5ybCiwaCGlI+D8nYkg7SZvjfZTmkvr9oLRW+R40BbDk2OfXGjrqSEq4WLXoR7oFI9iIekZcsOb5nmrtTQEYcjkWCK6jLnIN5ayo+7gbwud/+a9iH3VNctfWmgOamOPjorT79jy3ydPfflYCW9e4iG1W6Ff~0~-1~-1; PT_ST=3c02c563-e159-4766-be6b-f6df25069176; akaalb_prod_dual=1700426449~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=987589ee78f2a6df0f0ac4a0eb2f0327',
64
- 'origin': 'https://www.lowes.com',
65
- 'referer': 'https://www.lowes.com/mylowes/orders/checkorderstatus',
66
  'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
67
  'sec-ch-ua-mobile': '?0',
68
  'sec-ch-ua-platform': '"Windows"',
69
- 'sec-fetch-dest': 'empty',
70
- 'sec-fetch-mode': 'cors',
71
  'sec-fetch-site': 'same-origin',
72
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
73
- 'x-requested-with': 'XMLHttpRequest'
74
- }
75
-
76
- response = requests.request("POST", url, headers=headers, data=payload)
77
-
78
- return response.text
79
-
80
- def find_product_info(query: str) -> Dict[str, Any]:
81
- url = "https://brickseek.com/api/brickseek-public"
82
-
83
- payload = "{\"params\":{\"search\":\"Wireless Earbuds\",\"store_type\":10},\"url\":\"ajax/product_search\"}"
84
- headers = {
85
- 'authority': 'brickseek.com',
86
- 'accept': '*/*',
87
- 'accept-language': 'en-US,en;q=0.9',
88
- 'baggage': 'sentry-environment=vercel-production,sentry-release=ca34a251f847fd72e72bf9f0656cea41aec74315,sentry-public_key=cdad1d45449541899fbf219ad1d6ebdb,sentry-trace_id=d9fb3a828b3045b688a444c93ebe25a0',
89
- 'content-type': 'text/plain;charset=UTF-8',
90
- 'cookie': '__cf_bm=HU3YnfBsggOePLMQc2lMbpEGvRS6XGg7aPex5VNdJ3Q-1700341559-0-AWvI96ju3QZHuINgeCgWv4wciLY8puzHv0o+iAitfuZARVg+dp4RAKSG/Pr0Gey2lUWsJj0ORKBaphLMq51IHpc=; cf_clearance=1Bd418eBhJTFAfAAdoK8d3I3EFpST.1ler5y0XFXf8k-1700341561-0-1-389cfab0.3c4718a5.6f9da550-0.2.1700341561',
91
- 'origin': 'https://brickseek.com',
92
- 'referer': 'https://brickseek.com/lowes-inventory-checker',
93
- 'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
94
- 'sec-ch-ua-mobile': '?0',
95
- 'sec-ch-ua-platform': '"Windows"',
96
- 'sec-fetch-dest': 'empty',
97
- 'sec-fetch-mode': 'cors',
98
- 'sec-fetch-site': 'same-origin',
99
- 'sentry-trace': 'd9fb3a828b3045b688a444c93ebe25a0-874f3c7351675e10-1',
100
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
101
- }
102
-
103
- response = requests.request("POST", url, headers=headers, data=payload)
104
-
105
- print(response.text)
106
-
107
- # The output is a JSON object
108
- # Turn it into a python dictionary
109
- response_dict = json.loads(response.text)
110
-
111
- return response_dict
112
-
113
- def get_product_listing(sku: int):
114
- url = f"https://www.lowes.com/search?searchTerm={sku}"
115
-
116
- payload = {}
117
- headers = {
118
- 'authority': 'www.lowes.com',
119
- 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
120
- 'accept-language': 'en-US,en;q=0.9',
121
- 'cookie': 'dbidv2=56b2862a-8fa1-4476-ae09-6368c4fab002; al_sess=FuA4EWsuT07UWryyq/3foEQIwIqOxmho8CAP0qIisJkWP6yrEciiDxJiF8HPZ/09; region=east; AKA_A2=A; EPID=NTZiMjg2MmEtOGZhMS00NDc2LWFlMDktNjM2OGM0ZmFiMDAy; bm_sz=FD2C6C9185843B61533705694D14EF09~YAAQTCXRFy7EGs+LAQAA9Cok5BVOqBRlOAkc2ibX247znTkInxYHj4yFBMY+lWEGSucc9Vag1mzB5owd7ujrIa8Tt+k8M+uWh6wPPUWz3QF7RpyIyxsA4NOmjVwds1rEkGCtXtnhtxNvg9eoBeVW2rKmOI+Wo6eeyG5ZD/Be3I8J0Mw859Xt03pOB7zh2NviHhi1rTbZLCqj7ihbL4OpgQWv4gd8p5JX2VOFHAjWA3xPtGEVZuPn3tcMJTKbETxO4xHmmO+ER0l6Pgsk+hDYu/G6s71XDkkcDyR2XosdOhO9sIYljoBjBCGktjJird6wvK8WJEC+9WFKdeY=~3486278~4604217; ph_aid=3c68acb4-b3eb-487a-fc03-1cd3fc616418-7080571749703-454eb8c121d15-bf29dec353e8d; sn=1875; sd=%7B%22id%22%3A%221875%22%2C%22zip%22%3A%2230307%22%2C%22city%22%3A%22Atlanta%22%2C%22state%22%3A%22GA%22%2C%22name%22%3A%22Atlanta-Edgewood%20Lowe\'s%22%2C%22region%22%3A%223%22%7D; zipcode=30307; nearbyid=1875; zipstate=GA; user=%7B%22zipPrompt%22%3Atrue%7D; audience=DIY; _abck=84784437A2290F7C7665B869C07C4FDE~0~YAAQTCXRFznOGs+LAQAApl0l5AoUWttzoglFBJBV0r/WGr6wXArpqRxmVKRftBWRNCD7Rc/+z809D45jGbTU0yldpjr9Jq5XeDPG1B6Gdkb3oeu+pL7t1YdLuYUU8pdsnTHiuNU6zW7wKAyzF7lmeXACJHQrlO7cN+zqBaTaile96J18Gj82+zHpDvkU1RuhcqH3rNlV8jq8Ecn8rminJr1LfE4xiOM6SH6yL0eFVl2T4wbNOpIhlZ7ycluXvEHEJQYrb8U3me7oJ0FVDbKXa8mi50c3LPk/maBSzz3LXvK8WwXAiMgWMnu7+D4r96p9YKKXVxiN2khwsm/YixV2j5vtGCEboSy+yWcBTZyDimKxpCf8JYbPRVvJyvgFmbEY/IZcDkueOCKIGxIsSfP+pyReapNRw0cvwmyBtzKDX4bnjU9lGGWZeoEUzwYzpheqs6Z2NyPpkpIl~-1~-1~-1; prodNumber=2; TAsessionID=a9359468-38d7-478b-98e3-860e86a1c42a|NEW; _lgsid=1700342200927; grs_search_token=HEAD:I3:1:NA:NA:b3dc2d9f6b133c15b34e9ca2541bf2dd; seo-partner=gDTMXB9g7l46qsQ3gCM3qCMsoDgSmXpC; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQruULFz542duLAQAA5BRL5BXlhv5ALaFuOMlnw0rduBHyCy8g2x4aoRSl0bjIyvNthNZqx/oMOjDmsDXaGHch5h0UTU2NyX0uSZpoGaD5Nu7axdj83DCrq/+sLwzIF+fJuEVH082RuCsd8sgxzIPi+aapEk1DmwWZOWrcfpFqtAPPlKS4hBGcjW6jAPLFEwTsQpcqzKeAXG0WndvQa+UEg8LIHLTWhIG3AyrosHtIjhh9TgdBLz4qO+kJiBJqvCzsYmzgcVEJg2p63heU2mk81o1uHusoFpOr+9S4VG7ImIVxnOgpdloinc9kFQ3fhQRonCWzfX9mM9Fq3LvgL3lixNgkdAFbQv9D9uD9CtpqorrXUzYcP7R8Mm/bzUBSFPxQ3i1z0fynE9S9VeiyJ117QrGVbCo/hbzsZ1d2Bxa2T8plvUCFXGzma4B3IaB6uGdOqshQqEP5QGSiov1P; sbsd=spqmx35Jl1HZrCR8jTl/PwpARJNPMewXjZUqj7gbzQcY4wcZLgFQ9KZ5ScmDCPq9IQAJWPpG/ZzKqzHsEGcsMQieWXmXGHxPNFBLvWBK4e3P+9++e+Vt/LQ70pv2wTqJRSzpgXZKAD/1P3u8gwHUBNQ==; bm_mi=6808FB6A942BFA186D4C6F584A7C2C13~YAAQruULF1R42duLAQAAbx5L5BX3ooyVh0CCz1S9KEPjsw+YZ/EyDyiRfDZ5NN2w6tN4NyVhogBqJ40FFHb7E9ZsM3x5B5RHpjiDnd1z1t3nDhnLDCyQz/fDo28shr6/wtFLmRMzefrDK2MLPaoOmJ0HN2W/YgNp2H5LhNHPdClZqsrKDCbcI0Bu4PO/MREIY/7UYbVoV7Md1oZgMVxL42Rjsu7SKACEfGByzzysZCc8Fnlz66oecOp8+SMGPcsNk7+vrVklNCXi9VObPp5Zs02JmO4u3uGrTzHX91RvRNP5uLBmAcg3llq0XDnDUeLG~1; salsify_session_id=0869bdc0-eb71-4df8-8a00-2581bdc455a1; akavpau_default=1700342511~id=d12fe16cb50bff6560c1af6055b1278c; akavpau_cart=1700342513~id=d28f6ce6f94e835c9677ad1aa459d716; notice_behavior=implied,eu; p13n=%7B%22zipCode%22%3A%2230307%22%2C%22storeId%22%3A%221875%22%2C%22state%22%3A%22GA%22%2C%22audienceList%22%3A%5B%5D%7D; g_previous=%7B%22gpvPageLoadTime%22%3A%220.00%22%2C%22gpvPageScroll%22%3A%2226%7C27%7C0%7C3149%22%2C%22gpvSitesections%22%3A%22checkorderstatus%22%2C%22gpvSiteId%22%3A%22desktop%22%2C%22gpvPageType%22%3A%22check-order-status%22%7D; akaalb_prod_dual=1700428639~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=2cf1cd354d83c94f9da60e4ebbc25c6e; bm_sv=8B13230A1BED940DF1CD6E283A4D1610~YAAQruULF7R42duLAQAAVpBL5BUdn0LlPXETpnblyyruPK4VG5bVhjNMqHn059CHQH/1BiSLnADboIS3aZWm2HrbjSicvoG6MsTqumzNORm9VzKfH3+PRzhqk0m7XDglfg2qO03xrSoMhn2x0HtBaFHYUu+LPlZYRrrU+chMrVHtzp5i8JTx3grQiWcJnahnj5Dm2Nm6r3d22ifqZG1hcxA9oNG69Kbiwinwv2B0Dt7kbujRggMq+dV/rHHmdyNF~1; _abck=84784437A2290F7C7665B869C07C4FDE~-1~YAAQruULFyp82duLAQAAjltO5Aq5Z2Wy7IwrT8LGPETsMNBYgR3ioKo05jXyjh7pnHJE/6HuQ48H84Qlbz3pLV0XC0Em8SxGIWwx4/jtqFwVP2HseXKdmJJm7bO5DHvTg1K7wu1LyubY7qU+eSTAxOMgnJiKjMy10pGMnVIsgS5/3UWvZprfNvZWYVFT/q6FtVpK7EOXXyI+FIherVv1IQBngeQbxFFT3sZ9yGVgcpuXffHW5G2ph7UB3sKQCVyU+XovIpman//ZoiNIBUrp9NR5pOoIA6ui8Wg8N4cm/bBUGRfxBCw4je16mWTbZP5Jm0XQvREBYvBBR8mXhP/iZvReV8YCMg5zjerxzeT3MGyzIipoLQeLxLzr9I/SUG5cHN7mXh8YFvmbuppyhnBQCTKrnhm8wZ+6Ga0eHY0jz9zhgSijOECuGxpnV4mdtC/rX7hswdMyAmmj~0~-1~-1; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQruULFyt82duLAQAAjltO5BUVgHseFizgyiwC7KNxfqvcDdkjtdW0+ykbMNKpCOBkYKvRomJO8hYi+7pVA6Oi5vIWP7qYR9hLzp5KZz8nWu3DkYMpaDqbMTD16nRwkh36KS/NYhosAjQABuYoOUYw1IbBsr1L/uKHHOJv+jLyZcdpI92BOATTt/x7ZmVxVTJMH3Po+92V7gsXFvbJr281h3e41RVJUpUD4KG+4OfnJTaHuGqK5z2+Iw0hRvJtKDnWaaG9/iCLxLwFm9tFO7+8hDMW7SdoolHwKZ0KeajzTbYkugFRiTbH0SyKnM2zqMIt0hJfvIYsPkwzvxXR23BYoEl//ocbzN1Egsiknd83AtUgDG0qTMNJ/fpS8ey0Lpic9jk+qxm1aIozuv6wqZMcN+pCVuOZXMrV1YYo6Iifzr2z9dtTtufBvFQI6UrLBYVStlorAkMNO1ieotC48iLQoZnWa7Cex0FFNQ==; akaalb_prod_dual=1700426449~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=987589ee78f2a6df0f0ac4a0eb2f0327',
122
- 'referer': 'https://www.lowes.com/c/Departments',
123
- 'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
124
- 'sec-ch-ua-mobile': '?0',
125
- 'sec-ch-ua-platform': '"Windows"',
126
- 'sec-fetch-dest': 'document',
127
- 'sec-fetch-mode': 'navigate',
128
- 'sec-fetch-site': 'same-origin',
129
- 'sec-fetch-user': '?1',
130
- 'upgrade-insecure-requests': '1',
131
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
132
  }
133
 
134
  response = requests.request("GET", url, headers=headers, data=payload)
135
-
136
  return response.text
137
 
138
 
139
-
140
  def refer_to_human_agent(summary: str) -> str:
141
  return "I'm sorry, I don't know how to help you with that. I'll refer you to a human agent."
 
1
  import json
2
+ import pandas as pd
3
  import requests
4
+ from pandas import DataFrame
5
+
6
+ from home_depot_result import home_depot_result
7
 
8
 
9
  def call_function(messages, function_call):
 
11
  Currently extended by adding clauses to this if statement."""
12
  print(function_call)
13
 
14
+ if function_call["name"] == "lookup_order_status":
15
  try:
16
  parsed_output = json.loads(
17
  function_call["arguments"]
18
  )
19
  print("Looking up order status")
20
+ results = get_lookup_order_status(parsed_output["email_address"], parsed_output["order_number"])
21
  return {
22
  "role": "function",
23
  "name": function_call["name"],
 
27
  # print(parsed_output)
28
  print(f"Function execution failed")
29
  print(f"Error message: {e}")
30
+ return {"role": "function", "content": "call failed", "name": "lookup_order_status"}
31
+ elif function_call["name"] == "lookup_product":
32
+ try:
33
+ parsed_output = json.loads(
34
+ function_call["arguments"]
35
+ )
36
+ print("Looking up product sku")
37
+ results = lookup_product(parsed_output["query"])
38
+ return {
39
+ "role": "function",
40
+ "name": function_call["name"],
41
+ "content": str(results),
42
+ }
43
+ except Exception as e:
44
+ print(f"Function execution failed")
45
+ print(f"Error message: {e}")
46
+ return {"role": "function", "content": "call failed", "name": "lookup_product"}
47
+ elif function_call["name"] == "get_product_listing":
48
+ try:
49
+ parsed_output = json.loads(
50
+ function_call["arguments"]
51
+ )
52
+ print("retrieving product listing")
53
+ results = get_product_listing(parsed_output["sku"])
54
+ return {
55
+ "role": "function",
56
+ "name": function_call["name"],
57
+ "content": str(results),
58
+ }
59
+ except Exception as e:
60
+ print(f"Function execution failed")
61
+ print(f"Error message: {e}")
62
+ return {"role": "function", "content": "call failed", "name": "get_product_listing"}
63
  elif function_call["name"] == "refer_to_human_agent":
64
  try:
65
  parsed_output = json.loads(
 
81
  raise Exception("Function does not exist and cannot be called")
82
 
83
 
84
+ def get_lookup_order_status(email_address: str, order_number: int) -> str:
85
+ return home_depot_result
86
+ # url = "https://www.lowes.com/api/mylowes/orders/details"
87
+ #
88
+ # payload = json.dumps({
89
+ # "masterOrderNumber": f"{order_number}",
90
+ # "emailId": f"{email_address}",
91
+ # "type": "online",
92
+ # "storeNumber": "1875"
93
+ # })
94
+ # headers = {
95
+ # 'authority': 'www.lowes.com',
96
+ # 'accept': 'application/json, text/plain, */*',
97
+ # 'accept-language': 'en-US,en;q=0.9',
98
+ # 'content-type': 'application/json',
99
+ # 'cookie': 'dbidv2=56b2862a-8fa1-4476-ae09-6368c4fab002; al_sess=FuA4EWsuT07UWryyq/3foEQIwIqOxmho8CAP0qIisJkWP6yrEciiDxJiF8HPZ/09; HPLA=1; region=east; AKA_A2=A; EPID=NTZiMjg2MmEtOGZhMS00NDc2LWFlMDktNjM2OGM0ZmFiMDAy; bm_sz=FD2C6C9185843B61533705694D14EF09~YAAQTCXRFy7EGs+LAQAA9Cok5BVOqBRlOAkc2ibX247znTkInxYHj4yFBMY+lWEGSucc9Vag1mzB5owd7ujrIa8Tt+k8M+uWh6wPPUWz3QF7RpyIyxsA4NOmjVwds1rEkGCtXtnhtxNvg9eoBeVW2rKmOI+Wo6eeyG5ZD/Be3I8J0Mw859Xt03pOB7zh2NviHhi1rTbZLCqj7ihbL4OpgQWv4gd8p5JX2VOFHAjWA3xPtGEVZuPn3tcMJTKbETxO4xHmmO+ER0l6Pgsk+hDYu/G6s71XDkkcDyR2XosdOhO9sIYljoBjBCGktjJird6wvK8WJEC+9WFKdeY=~3486278~4604217; TAsessionID=0421ade3-7a84-4692-9ad8-d67927442c16|NEW; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQTCXRF0zEGs+LAQAALC0k5BVU2zm/cgpTeSAB5oJBqTX8djy+rUtTzcodc06GoFRo/QB3NhhzPSPPvUd6lmCx0k5hK2OgXrT0s2ifZbUneCF7u/kOPX+aDP51oWsuZnVOScC1doltiJAJ7UVHfSlZ+7aCjw5+bm5istYopvV+sJHwtPdNabdtculQtPwq7uRDJadaMZCd+pieFtiMEltlxmCTYZp0ATGsxOSnqKn01LIOMAPHUNIJivM9tMPTSvDvr3mW0JbB7slTFD5CHuRLWYhHtT5LT8BzF0R3VTy+SGkrzdLyF8IuQmFfWAiT7FIHUrDtcxRZpjQUBkenz8ObtREzb23FobM3pWZgb9YbdxnxCUdgUnI33Hkh+uKFxNHfnCLCtwddDQ==; ph_aid=3c68acb4-b3eb-487a-fc03-1cd3fc616418-7080571749703-454eb8c121d15-bf29dec353e8d; _lgsid=1700339660085; sn=1875; sd=%7B%22id%22%3A%221875%22%2C%22zip%22%3A%2230307%22%2C%22city%22%3A%22Atlanta%22%2C%22state%22%3A%22GA%22%2C%22name%22%3A%22Atlanta-Edgewood%20Lowe\'s%22%2C%22region%22%3A%223%22%7D; zipcode=30307; nearbyid=1875; zipstate=GA; bm_mi=6808FB6A942BFA186D4C6F584A7C2C13~YAAQTCXRFzfLGs+LAQAA1fMk5BW7b5b1fpebVli+q0WvFABZFCZymNL07sKET78++WCh2c2PlR2cWb0Mhgy6c0kb+eQQXXnhzTvCBO+c3SXbahePgkJIiNOjvqCpTFDAiy4o0TOqYYTsE6ZalTslHCv7kgGY96uF1sBUFxvNqSN3/Cj5CGcIaCwZZb15pkIFLj7DXqoZ+AEYScs4TUAzhDbJ/g1ShZGx0fUeUqHVwn3pzgdFuuPh2O/WTXQzA4lgzTY+dkhTw5pdbc8vvsu7SdXK0d6R0JW3UyuP5oMThUuIetC0PoVSmycGaHLIPz16~1; user=%7B%22zipPrompt%22%3Atrue%7D; audience=DIY; _abck=84784437A2290F7C7665B869C07C4FDE~0~YAAQTCXRFznOGs+LAQAApl0l5AoUWttzoglFBJBV0r/WGr6wXArpqRxmVKRftBWRNCD7Rc/+z809D45jGbTU0yldpjr9Jq5XeDPG1B6Gdkb3oeu+pL7t1YdLuYUU8pdsnTHiuNU6zW7wKAyzF7lmeXACJHQrlO7cN+zqBaTaile96J18Gj82+zHpDvkU1RuhcqH3rNlV8jq8Ecn8rminJr1LfE4xiOM6SH6yL0eFVl2T4wbNOpIhlZ7ycluXvEHEJQYrb8U3me7oJ0FVDbKXa8mi50c3LPk/maBSzz3LXvK8WwXAiMgWMnu7+D4r96p9YKKXVxiN2khwsm/YixV2j5vtGCEboSy+yWcBTZyDimKxpCf8JYbPRVvJyvgFmbEY/IZcDkueOCKIGxIsSfP+pyReapNRw0cvwmyBtzKDX4bnjU9lGGWZeoEUzwYzpheqs6Z2NyPpkpIl~-1~-1~-1; prodNumber=2; akavpau_default=1700340036~id=0d6c97bed4e510e00b212e2c7151704a; akavpau_cart=1700340038~id=c8d179c7ab834971d54fb6b3f37fb5cd; notice_behavior=implied,eu; p13n=%7B%22zipCode%22%3A%2230307%22%2C%22storeId%22%3A%221875%22%2C%22state%22%3A%22GA%22%2C%22audienceList%22%3A%5B%5D%7D; g_previous=%7B%22gpvPageLoadTime%22%3A%220.00%22%2C%22gpvPageScroll%22%3A%228%7C9%7C0%7C10258%22%2C%22gpvSitesections%22%3A%22checkorderstatus%22%2C%22gpvSiteId%22%3A%22desktop%22%2C%22gpvPageType%22%3A%22check-order-status%22%7D; PT_ST=6c202780-f553-4693-bb78-129dedacc842; akaalb_prod_dual=1700426396~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=ddbf1d57536e8f52d396da19f5e80dc4; bm_sv=8B13230A1BED940DF1CD6E283A4D1610~YAAQTCXRFx0AG8+LAQAAb1Yp5BXh8z5aM//hZ+YV+MjKJgNR34HJmJZTf3AixPor3SXeREgpHBbsqJUONoLbqAG1NGKbZR0gevtiZH9fdU0VojEHjQOvH0dbif9h9QivxlMSphKTTDy5EQYEFumXDVmNKtMKFjh6uV5Imj2r5hfucyAyTZiQ6V0yOiRigqEUDnY3Yzx2y2CPKvHPpgOLu6NREx34B64M8OOl2nzIJCzlhZfizbm8tDyr6+YYRtgB~1; _abck=84784437A2290F7C7665B869C07C4FDE~-1~YAAQTCXRFyEKG8+LAQAAmScq5AqXSATqkt25kWxxHAg3BLxuo+Nz1ihcUXOUs/s0PjLsQmvz72U0IrKBhYjfN6DLPT0x/N4/ntmJOZQYWN0SUrK3S1MKBuDFQWRMQAdDYPgPrQ9sGLxg/9jiUX8mNYgODb9F9iOKvS0tl0W1MBaPygnbVYeo6YYU/7/GV3KuiLSUbHLRn2Y49ltGRz4SFJpy12VJTBP4f1SYjBovTH3WlsVfdVbY/4YNfGuA862HvGYwo2D7oDMhZsMxZNdm8vBEeGJS0GyOTmeZtUal0izS3wq6KC5ybCiwaCGlI+D8nYkg7SZvjfZTmkvr9oLRW+R40BbDk2OfXGjrqSEq4WLXoR7oFI9iIekZcsOb5nmrtTQEYcjkWCK6jLnIN5ayo+7gbwud/+a9iH3VNctfWmgOamOPjorT79jy3ydPfflYCW9e4iG1W6Ff~0~-1~-1; PT_ST=3c02c563-e159-4766-be6b-f6df25069176; akaalb_prod_dual=1700426449~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=987589ee78f2a6df0f0ac4a0eb2f0327',
100
+ # 'origin': 'https://www.lowes.com',
101
+ # 'referer': 'https://www.lowes.com/mylowes/orders/checkorderstatus',
102
+ # 'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
103
+ # 'sec-ch-ua-mobile': '?0',
104
+ # 'sec-ch-ua-platform': '"Windows"',
105
+ # 'sec-fetch-dest': 'empty',
106
+ # 'sec-fetch-mode': 'cors',
107
+ # 'sec-fetch-site': 'same-origin',
108
+ # 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
109
+ # 'x-requested-with': 'XMLHttpRequest'
110
+ # }
111
+ #
112
+ # response = requests.request("POST", url, headers=headers, data=payload)
113
+ #
114
+ # return response.text
115
+
116
+
117
+ def lookup_product(query: str) -> DataFrame:
118
+ df = pd.read_csv('home_depot_data.csv')
119
+ # df['score'] = df['title'].apply(lambda x: fuzz.ratio(x, query))
120
+ queries = query.split(" ")
121
+ df['contains_queries'] = df['url'].str.contains('|'.join(queries), case=False)
122
+
123
+ print(df[df["contains_queries"] == True])
124
+
125
+ return df[df["contains_queries"] == True].head(5)['title']
126
+
127
+ # url = "https://brickseek.com/api/brickseek-public"
128
+ #
129
+ # payload = {"params": {"search": query, "store_type": 10}, "url": "ajax/product_search"}
130
+ # headers = {
131
+ # 'authority': 'brickseek.com',
132
+ # 'accept': '*/*',
133
+ # 'accept-language': 'en-US,en;q=0.9',
134
+ # 'baggage': 'sentry-environment=vercel-production,sentry-release=ca34a251f847fd72e72bf9f0656cea41aec74315,sentry-public_key=cdad1d45449541899fbf219ad1d6ebdb,sentry-trace_id=d9fb3a828b3045b688a444c93ebe25a0',
135
+ # 'content-type': 'text/plain;charset=UTF-8',
136
+ # 'cookie': '__cf_bm=HU3YnfBsggOePLMQc2lMbpEGvRS6XGg7aPex5VNdJ3Q-1700341559-0-AWvI96ju3QZHuINgeCgWv4wciLY8puzHv0o+iAitfuZARVg+dp4RAKSG/Pr0Gey2lUWsJj0ORKBaphLMq51IHpc=; cf_clearance=1Bd418eBhJTFAfAAdoK8d3I3EFpST.1ler5y0XFXf8k-1700341561-0-1-389cfab0.3c4718a5.6f9da550-0.2.1700341561',
137
+ # 'origin': 'https://brickseek.com',
138
+ # 'referer': 'https://brickseek.com/lowes-inventory-checker',
139
+ # 'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
140
+ # 'sec-ch-ua-mobile': '?0',
141
+ # 'sec-ch-ua-platform': '"Windows"',
142
+ # 'sec-fetch-dest': 'empty',
143
+ # 'sec-fetch-mode': 'cors',
144
+ # 'sec-fetch-site': 'same-origin',
145
+ # 'sentry-trace': 'd9fb3a828b3045b688a444c93ebe25a0-874f3c7351675e10-1',
146
+ # 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
147
+ # }
148
+ #
149
+ # response = requests.request("POST", url, headers=headers, data=payload)
150
+ #
151
+ # print(response.text)
152
+ #
153
+ # # The output is a JSON object
154
+ # # Turn it into a python dictionary
155
+ # response_dict = json.loads(response.text)
156
+ #
157
+ # return response_dict
158
+
159
+
160
+ # https://www.lowes.com/search?searchTerm=MRN12
161
+ def get_product_listing(sku: str):
162
+ print("get_product_listing")
163
+ url = f"https://www.lowes.com/search?searchTerm={sku}"
164
 
165
+ payload = {}
 
 
 
 
 
166
  headers = {
167
  'authority': 'www.lowes.com',
168
+ 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
169
  'accept-language': 'en-US,en;q=0.9',
170
+ # 'cookie': 'dbidv2=56b2862a-8fa1-4476-ae09-6368c4fab002; al_sess=FuA4EWsuT07UWryyq/3foEQIwIqOxmho8CAP0qIisJkWP6yrEciiDxJiF8HPZ/09; region=east; AKA_A2=A; EPID=NTZiMjg2MmEtOGZhMS00NDc2LWFlMDktNjM2OGM0ZmFiMDAy; bm_sz=FD2C6C9185843B61533705694D14EF09~YAAQTCXRFy7EGs+LAQAA9Cok5BVOqBRlOAkc2ibX247znTkInxYHj4yFBMY+lWEGSucc9Vag1mzB5owd7ujrIa8Tt+k8M+uWh6wPPUWz3QF7RpyIyxsA4NOmjVwds1rEkGCtXtnhtxNvg9eoBeVW2rKmOI+Wo6eeyG5ZD/Be3I8J0Mw859Xt03pOB7zh2NviHhi1rTbZLCqj7ihbL4OpgQWv4gd8p5JX2VOFHAjWA3xPtGEVZuPn3tcMJTKbETxO4xHmmO+ER0l6Pgsk+hDYu/G6s71XDkkcDyR2XosdOhO9sIYljoBjBCGktjJird6wvK8WJEC+9WFKdeY=~3486278~4604217; ph_aid=3c68acb4-b3eb-487a-fc03-1cd3fc616418-7080571749703-454eb8c121d15-bf29dec353e8d; sn=1875; sd=%7B%22id%22%3A%221875%22%2C%22zip%22%3A%2230307%22%2C%22city%22%3A%22Atlanta%22%2C%22state%22%3A%22GA%22%2C%22name%22%3A%22Atlanta-Edgewood%20Lowe\'s%22%2C%22region%22%3A%223%22%7D; zipcode=30307; nearbyid=1875; zipstate=GA; user=%7B%22zipPrompt%22%3Atrue%7D; audience=DIY; _abck=84784437A2290F7C7665B869C07C4FDE~0~YAAQTCXRFznOGs+LAQAApl0l5AoUWttzoglFBJBV0r/WGr6wXArpqRxmVKRftBWRNCD7Rc/+z809D45jGbTU0yldpjr9Jq5XeDPG1B6Gdkb3oeu+pL7t1YdLuYUU8pdsnTHiuNU6zW7wKAyzF7lmeXACJHQrlO7cN+zqBaTaile96J18Gj82+zHpDvkU1RuhcqH3rNlV8jq8Ecn8rminJr1LfE4xiOM6SH6yL0eFVl2T4wbNOpIhlZ7ycluXvEHEJQYrb8U3me7oJ0FVDbKXa8mi50c3LPk/maBSzz3LXvK8WwXAiMgWMnu7+D4r96p9YKKXVxiN2khwsm/YixV2j5vtGCEboSy+yWcBTZyDimKxpCf8JYbPRVvJyvgFmbEY/IZcDkueOCKIGxIsSfP+pyReapNRw0cvwmyBtzKDX4bnjU9lGGWZeoEUzwYzpheqs6Z2NyPpkpIl~-1~-1~-1; prodNumber=2; TAsessionID=a9359468-38d7-478b-98e3-860e86a1c42a|NEW; _lgsid=1700342200927; grs_search_token=HEAD:I3:1:NA:NA:b3dc2d9f6b133c15b34e9ca2541bf2dd; seo-partner=gDTMXB9g7l46qsQ3gCM3qCMsoDgSmXpC; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQruULFz542duLAQAA5BRL5BXlhv5ALaFuOMlnw0rduBHyCy8g2x4aoRSl0bjIyvNthNZqx/oMOjDmsDXaGHch5h0UTU2NyX0uSZpoGaD5Nu7axdj83DCrq/+sLwzIF+fJuEVH082RuCsd8sgxzIPi+aapEk1DmwWZOWrcfpFqtAPPlKS4hBGcjW6jAPLFEwTsQpcqzKeAXG0WndvQa+UEg8LIHLTWhIG3AyrosHtIjhh9TgdBLz4qO+kJiBJqvCzsYmzgcVEJg2p63heU2mk81o1uHusoFpOr+9S4VG7ImIVxnOgpdloinc9kFQ3fhQRonCWzfX9mM9Fq3LvgL3lixNgkdAFbQv9D9uD9CtpqorrXUzYcP7R8Mm/bzUBSFPxQ3i1z0fynE9S9VeiyJ117QrGVbCo/hbzsZ1d2Bxa2T8plvUCFXGzma4B3IaB6uGdOqshQqEP5QGSiov1P; sbsd=spqmx35Jl1HZrCR8jTl/PwpARJNPMewXjZUqj7gbzQcY4wcZLgFQ9KZ5ScmDCPq9IQAJWPpG/ZzKqzHsEGcsMQieWXmXGHxPNFBLvWBK4e3P+9++e+Vt/LQ70pv2wTqJRSzpgXZKAD/1P3u8gwHUBNQ==; bm_mi=6808FB6A942BFA186D4C6F584A7C2C13~YAAQruULF1R42duLAQAAbx5L5BX3ooyVh0CCz1S9KEPjsw+YZ/EyDyiRfDZ5NN2w6tN4NyVhogBqJ40FFHb7E9ZsM3x5B5RHpjiDnd1z1t3nDhnLDCyQz/fDo28shr6/wtFLmRMzefrDK2MLPaoOmJ0HN2W/YgNp2H5LhNHPdClZqsrKDCbcI0Bu4PO/MREIY/7UYbVoV7Md1oZgMVxL42Rjsu7SKACEfGByzzysZCc8Fnlz66oecOp8+SMGPcsNk7+vrVklNCXi9VObPp5Zs02JmO4u3uGrTzHX91RvRNP5uLBmAcg3llq0XDnDUeLG~1; salsify_session_id=0869bdc0-eb71-4df8-8a00-2581bdc455a1; akavpau_default=1700342511~id=d12fe16cb50bff6560c1af6055b1278c; akavpau_cart=1700342513~id=d28f6ce6f94e835c9677ad1aa459d716; notice_behavior=implied,eu; p13n=%7B%22zipCode%22%3A%2230307%22%2C%22storeId%22%3A%221875%22%2C%22state%22%3A%22GA%22%2C%22audienceList%22%3A%5B%5D%7D; g_previous=%7B%22gpvPageLoadTime%22%3A%220.00%22%2C%22gpvPageScroll%22%3A%2226%7C27%7C0%7C3149%22%2C%22gpvSitesections%22%3A%22checkorderstatus%22%2C%22gpvSiteId%22%3A%22desktop%22%2C%22gpvPageType%22%3A%22check-order-status%22%7D; akaalb_prod_dual=1700428639~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=2cf1cd354d83c94f9da60e4ebbc25c6e; bm_sv=8B13230A1BED940DF1CD6E283A4D1610~YAAQruULF7R42duLAQAAVpBL5BUdn0LlPXETpnblyyruPK4VG5bVhjNMqHn059CHQH/1BiSLnADboIS3aZWm2HrbjSicvoG6MsTqumzNORm9VzKfH3+PRzhqk0m7XDglfg2qO03xrSoMhn2x0HtBaFHYUu+LPlZYRrrU+chMrVHtzp5i8JTx3grQiWcJnahnj5Dm2Nm6r3d22ifqZG1hcxA9oNG69Kbiwinwv2B0Dt7kbujRggMq+dV/rHHmdyNF~1; _abck=84784437A2290F7C7665B869C07C4FDE~-1~YAAQruULFyp82duLAQAAjltO5Aq5Z2Wy7IwrT8LGPETsMNBYgR3ioKo05jXyjh7pnHJE/6HuQ48H84Qlbz3pLV0XC0Em8SxGIWwx4/jtqFwVP2HseXKdmJJm7bO5DHvTg1K7wu1LyubY7qU+eSTAxOMgnJiKjMy10pGMnVIsgS5/3UWvZprfNvZWYVFT/q6FtVpK7EOXXyI+FIherVv1IQBngeQbxFFT3sZ9yGVgcpuXffHW5G2ph7UB3sKQCVyU+XovIpman//ZoiNIBUrp9NR5pOoIA6ui8Wg8N4cm/bBUGRfxBCw4je16mWTbZP5Jm0XQvREBYvBBR8mXhP/iZvReV8YCMg5zjerxzeT3MGyzIipoLQeLxLzr9I/SUG5cHN7mXh8YFvmbuppyhnBQCTKrnhm8wZ+6Ga0eHY0jz9zhgSijOECuGxpnV4mdtC/rX7hswdMyAmmj~0~-1~-1; ak_bmsc=A80C29BEB24AF3C79480B0F09D37CF62~000000000000000000000000000000~YAAQruULFyt82duLAQAAjltO5BUVgHseFizgyiwC7KNxfqvcDdkjtdW0+ykbMNKpCOBkYKvRomJO8hYi+7pVA6Oi5vIWP7qYR9hLzp5KZz8nWu3DkYMpaDqbMTD16nRwkh36KS/NYhosAjQABuYoOUYw1IbBsr1L/uKHHOJv+jLyZcdpI92BOATTt/x7ZmVxVTJMH3Po+92V7gsXFvbJr281h3e41RVJUpUD4KG+4OfnJTaHuGqK5z2+Iw0hRvJtKDnWaaG9/iCLxLwFm9tFO7+8hDMW7SdoolHwKZ0KeajzTbYkugFRiTbH0SyKnM2zqMIt0hJfvIYsPkwzvxXR23BYoEl//ocbzN1Egsiknd83AtUgDG0qTMNJ/fpS8ey0Lpic9jk+qxm1aIozuv6wqZMcN+pCVuOZXMrV1YYo6Iifzr2z9dtTtufBvFQI6UrLBYVStlorAkMNO1ieotC48iLQoZnWa7Cex0FFNQ==; akaalb_prod_dual=1700426449~op=PROD_GCP_EAST_CTRL_DFLT:PROD_DEFAULT_EAST|PROD_GCP_EAST_CTRL_A:PROD_EAST_A|~rv=89~m=PROD_DEFAULT_EAST:0|PROD_EAST_A:0|~os=352fb8a62db4e37e16b221fb4cefd635~id=987589ee78f2a6df0f0ac4a0eb2f0327',
171
+ 'referer': 'https://www.lowes.com/c/Departments',
 
 
172
  'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
173
  'sec-ch-ua-mobile': '?0',
174
  'sec-ch-ua-platform': '"Windows"',
175
+ 'sec-fetch-dest': 'document',
176
+ 'sec-fetch-mode': 'navigate',
177
  'sec-fetch-site': 'same-origin',
178
+ 'sec-fetch-user': '?1',
179
+ 'upgrade-insecure-requests': '1',
180
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  response = requests.request("GET", url, headers=headers, data=payload)
184
+ print("get_product_listing")
185
  return response.text
186
 
187
 
 
188
  def refer_to_human_agent(summary: str) -> str:
189
  return "I'm sorry, I don't know how to help you with that. I'll refer you to a human agent."
home_depot_data.csv ADDED
The diff for this file is too large to render. See raw diff
 
home_depot_result.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ home_depot_result = {
2
+ "orderDetails": {
3
+ "bopisCancelEnabled": False,
4
+ "id": "WG37810008",
5
+ "versionId": "v0:Cj4KAjEwEh1IRFByb2Nlc3NTVlNUcmFuc2FjdGlvblNlcnZlchoZMjAyMy0wNy0xNFQyMjoyNTozMi0wNDowMA==",
6
+ "orderRefNumber": "WG37810008",
7
+ "status": "Delivered",
8
+ "statusCode": 105,
9
+ "grandTotal": 128.5,
10
+ "subTotal": 118.0,
11
+ "taxTotal": 10.5,
12
+ "returnTotal": 0.0,
13
+ "shippingCharge": 0.0,
14
+ "deliveryCharge": 0.0,
15
+ "createDateTime": "2023-07-13T21:30:23-04:00",
16
+ "changeOwner": "COM",
17
+ "fulfillmentOwner": "COM",
18
+ "emailId": "colin.flueck@gmail.com",
19
+ "billingAddress": {
20
+ "addrIdentifier": 0,
21
+ "emailId": "colin.flueck@gmail.com",
22
+ "name": {
23
+ "firstName": "Colin",
24
+ "lastName": "Flueck"
25
+ },
26
+ "postalDetails": {
27
+ "addressLine1": "4237 Western Ave",
28
+ "city": "WESTERN SPRINGS",
29
+ "state": "IL",
30
+ "zipCode": "60558",
31
+ "country": "US"
32
+ },
33
+ "primaryPhone": {
34
+ "number": "6307508897"
35
+ }
36
+ },
37
+ "lineItems": {
38
+ "lineItem": [
39
+ {
40
+ "lineId": "1",
41
+ "lineSeqNum": "1",
42
+ "type": "Special Order Merchandise",
43
+ "statusCode": 105,
44
+ "statusUpdatedDate": "2023-07-15",
45
+ "status": "Delivered",
46
+ "omsId": 317984876,
47
+ "storeSKU": "1007491039",
48
+ "modelNumber": "PCL206B",
49
+ "department": "25",
50
+ "itemClass": "9",
51
+ "itemSubClass": 3,
52
+ "vendorNumber": "72793",
53
+ "poNumber": "84632203",
54
+ "upcCode": "033287200160",
55
+ "itemWeightUnitOfMeasure": "LB",
56
+ "itemWeight": 3.00,
57
+ "scac": "UPS",
58
+ "brandName": "RYOBI",
59
+ "description": "ONE+ 18V Cordless 1/2 in. Drill/Driver (Tool Only)",
60
+ "currentQuantity": 2,
61
+ "orginalOrderedQuantity": 2,
62
+ "cancelledQuantity": 0,
63
+ "deliveredDateArray": [
64
+ "2023-07-15"
65
+ ],
66
+ "unitPrice": 59.0,
67
+ "totalPrice": 118.0,
68
+ "pipSeoUrl": "/p/RYOBI-ONE-18V-Cordless-1-2-in-Drill-Driver-Tool-Only-PCL206B/317984876",
69
+ "imageUrl": "https://images.thdstatic.com/productImages/30cdd64e-b560-437c-8f90-3da447ed73d6/svn/ryobi-power-drills-pcl206b-64_100.jpg",
70
+ "productType": "MERCHANDISE",
71
+ "documents": {
72
+ "document": [
73
+ {
74
+ "name": "Warranty",
75
+ "url": "https://www.homedepot.com/catalog/pdfImages/61/61911e01-07fb-40d6-9b71-236f60d155bc.pdf"
76
+ },
77
+ {
78
+ "name": "Use and Care Manual",
79
+ "url": "https://www.homedepot.com/catalog/pdfImages/eb/eb728d57-8608-49cb-bfad-3760d0b4d9cf.pdf"
80
+ }
81
+ ]
82
+ },
83
+ "fulfillment": {
84
+ "fulfillmentMethod": "ShipToHome",
85
+ "shippingAndHandling": {
86
+ "shipmentModeCode": "SG",
87
+ "shippingDescription": "Standard Shipping",
88
+ "shippingProvider": "UPS",
89
+ "shippingProviderCode": "UPS",
90
+ "shippingStatus": "Delivered",
91
+ "isCarrierIntegrationAvailable": True,
92
+ "trackingURL": "http://www.ups.com/",
93
+ "comEstEndDeliveryDate": "2023-07-15T00:00:00-04:00",
94
+ "shipments": {
95
+ "shipment": [
96
+ {
97
+ "trackingNumber": "1ZRX95040358704846",
98
+ "shippingProviderCode": "UPS",
99
+ "isCarrierIntegrationAvailable": True,
100
+ "trackingURL": "http://www.ups.com/",
101
+ "shipmentModeCode": "SG",
102
+ "shippingProvider": "UPS",
103
+ "trackingType": "LastMile",
104
+ "estimatedDeliveryDate": "2023-07-15"
105
+ }
106
+ ]
107
+ },
108
+ "deliveryAddress": {
109
+ "name": {
110
+ "firstName": "Colin",
111
+ "lastName": "Flueck"
112
+ },
113
+ "postalDetails": {
114
+ "addressLine1": "176 5th St Nw",
115
+ "city": "ATLANTA",
116
+ "state": "GA",
117
+ "zipCode": "30313",
118
+ "country": "US"
119
+ },
120
+ "phoneNumbers": {
121
+ "dayPhone": "6307508897",
122
+ "mobilePhone": "6307508897"
123
+ }
124
+ },
125
+ "estStartDeliveryDate": "2023-07-15",
126
+ "estEndDeliveryDate": "2023-07-15",
127
+ "isLineHaul": False
128
+ }
129
+ },
130
+ "hideSKU": False,
131
+ "bossReorderZeroQuantity": False,
132
+ "isInstallItem": False,
133
+ "isCancelEnabled": False,
134
+ "isDFCSourced": True,
135
+ "isDFSCancelEnabled": False,
136
+ "isDFSRescheduleEnabled": False,
137
+ "actions": {
138
+ "buyAgain": True,
139
+ "isCancelEnabled": False,
140
+ "infoAndGuides": True,
141
+ "writeAReview": True,
142
+ "isDFSCancelEnabled": False,
143
+ "isDFSRescheduleEnabled": False
144
+ },
145
+ "isCOMAppliance": False,
146
+ "isBODFS": False,
147
+ "isDFS": False,
148
+ "delayedShipment": False,
149
+ "isGiftCard": False
150
+ }
151
+ ]
152
+ },
153
+ "paymentMethods": {
154
+ "paymentMethod": [
155
+ {
156
+ "amount": 128.5,
157
+ "lastFour": "2291",
158
+ "cardType": "VI"
159
+ }
160
+ ]
161
+ },
162
+ "trackingToLineAssociations": {
163
+ "trackingToLineAssociation": [
164
+ {
165
+ "trackingNumber": "1ZRX95040358704846",
166
+ "lineIds": "1"
167
+ }
168
+ ]
169
+ },
170
+ "lineIdsWithoutTracking": "",
171
+ "returnOnlineAllowed": False,
172
+ "authDeclined": False,
173
+ "workOrderToLineAssociations": {
174
+ "workOrderToLineAssociations": []
175
+ },
176
+ "isCancelEnabled": False,
177
+ "isDFCSourced": True,
178
+ "orderGroups": [
179
+ {
180
+ "fulfillment": "ShipToHome",
181
+ "status": "Delivered",
182
+ "name": {
183
+ "firstName": "Colin",
184
+ "lastName": "Flueck"
185
+ },
186
+ "postalDetails": {
187
+ "addressLine1": "176 5th St Nw",
188
+ "city": "ATLANTA",
189
+ "state": "GA",
190
+ "zipCode": "30313",
191
+ "country": "US"
192
+ },
193
+ "actions": {
194
+ "trackingEnabled": False
195
+ },
196
+ "lineAssociation": [
197
+ "1"
198
+ ],
199
+ "groupName": "ShipToHome_Delivered_1ZRX95040358704846",
200
+ "statusCode": 105,
201
+ "shipments": [
202
+ {
203
+ "trackingNumber": "1ZRX95040358704846",
204
+ "shippingProviderCode": "UPS",
205
+ "isCarrierIntegrationAvailable": True,
206
+ "trackingURL": "http://www.ups.com/",
207
+ "shipmentModeCode": "SG",
208
+ "shippingProvider": "UPS",
209
+ "trackingType": "LastMile",
210
+ "estimatedDeliveryDate": "2023-07-15"
211
+ }
212
+ ],
213
+ "estDeliveryDate": "2023-07-15"
214
+ }
215
+ ],
216
+ "trackingEnabled": False,
217
+ "cancellationRequested": False,
218
+ "isLineItemCancelEnabled": False,
219
+ "otherDiscountAmount": 0.00,
220
+ "isNEXOrder": False,
221
+ "isAAFESOrder": False,
222
+ "xAuthGuestToken": "If2SMV4Uhc6LadRhSbMf1wcvdgrbI1loyZFvAUHmrbjtOw53r22952ISw8UhvluZJjtcEfCdPid4KV7ph8vP8A=="
223
+ }
224
+ }
225
+
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  openai==1.3.3
2
- streamlit~=1.28.2
 
 
 
 
1
  openai==1.3.3
2
+ streamlit~=1.28.2
3
+ pandas~=2.1.3
4
+ requests~=2.31.0
5
+ fuzzywuzzy~=0.18.0