pragneshbarik commited on
Commit
592fd3e
1 Parent(s): 3fbf93c

integrated notion database

Browse files
Files changed (3) hide show
  1. config.yaml +4 -2
  2. middlewares/utils.py +77 -1
  3. requirements.txt +1 -0
config.yaml CHANGED
@@ -1,12 +1,14 @@
1
  PROMPT_ENGINEERING_DICT:
2
  SYSTEM_INSTRUCTION: |
3
- YOU ARE A SEARCH ENGINE HAVING FULL ACCESS TO WEB PAGES, YOU GIVE EXTREMELY DETAILED AND ACCURATE INFORMATION ACCORDING TO USER PROMPTS.
 
 
4
  SYSTEM_RESPONSE: |
5
  Certainly! I'm here to help. What information are you looking for?
6
  Please provide me with a specific topic or question, and I'll do my
7
  best to provide you with detailed and accurate information.
8
 
9
- PRE_CONTEXT: NOW YOU ARE SEARCHING THE WEB, AND HERE ARE THE CHUNKS RETRIEVED FROM THE WEB.
10
  POST_CONTEXT: ""
11
  PRE_PROMPT: NOW ACCORDING TO THE CONTEXT RETRIEVED FROM THE GENERATE THE CONTENT FOR THE FOLLOWING SUBJECT
12
  POST_PROMPT: PRIORITIZE DATA, FACTS AND STATISTICS OVER PERSONAL EXPERIENCES AND OPINIONS, FOCUS MORE ON STATISTICS AND DATA.
 
1
  PROMPT_ENGINEERING_DICT:
2
  SYSTEM_INSTRUCTION: |
3
+ YOU ARE A SEARCH ENGINE AND AN INVENTORY MANAGER HAVING FULL ACCESS TO WEB PAGES AND NOTION DATABASE IN JSON,
4
+ YOU GIVE EXTREMELY DETAILED AND ACCURATE INFORMATION ACCORDING TO USER PROMPTS.
5
+
6
  SYSTEM_RESPONSE: |
7
  Certainly! I'm here to help. What information are you looking for?
8
  Please provide me with a specific topic or question, and I'll do my
9
  best to provide you with detailed and accurate information.
10
 
11
+ PRE_CONTEXT: NOW YOU ARE SEARCHING THE WEB, AND HERE ARE THE CHUNKS RETRIEVED FROM THE WEB, YOU ALSO HAVE ACCESS TO INVENTORY DATABASE IN JSON FORMAT.
12
  POST_CONTEXT: ""
13
  PRE_PROMPT: NOW ACCORDING TO THE CONTEXT RETRIEVED FROM THE GENERATE THE CONTENT FOR THE FOLLOWING SUBJECT
14
  POST_PROMPT: PRIORITIZE DATA, FACTS AND STATISTICS OVER PERSONAL EXPERIENCES AND OPINIONS, FOCUS MORE ON STATISTICS AND DATA.
middlewares/utils.py CHANGED
@@ -1,4 +1,7 @@
1
  from sentence_transformers import CrossEncoder
 
 
 
2
  import math
3
  import numpy as np
4
  from middlewares.search_client import SearchClient
@@ -20,6 +23,74 @@ googleSearchClient = SearchClient(
20
  )
21
  bingSearchClient = SearchClient("bing", api_key=BING_SEARCH_API_KEY, engine_id=None)
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def rerank(query, top_k, search_results, chunk_size=512):
25
  chunks = []
@@ -67,6 +138,7 @@ def gen_augmented_prompt_via_websearch(
67
  chunk_size=512,
68
  ):
69
 
 
70
 
71
  search_results = []
72
  reranked_results = []
@@ -91,12 +163,16 @@ def gen_augmented_prompt_via_websearch(
91
  prev_output = prev_output if pass_prev else ""
92
 
93
  augmented_prompt = f"""
94
- {pre_context}
 
95
 
96
  {context}
97
 
 
98
  {post_context}
99
 
 
 
100
  {pre_prompt}
101
 
102
  {prompt}
 
1
  from sentence_transformers import CrossEncoder
2
+ from pprint import pprint, pformat
3
+ from notion_client import Client
4
+ import json
5
  import math
6
  import numpy as np
7
  from middlewares.search_client import SearchClient
 
23
  )
24
  bingSearchClient = SearchClient("bing", api_key=BING_SEARCH_API_KEY, engine_id=None)
25
 
26
+ def safe_get(data, dot_chained_keys):
27
+ '''
28
+ {'a': {'b': [{'c': 1}]}}
29
+ safe_get(data, 'a.b.0.c') -> 1
30
+ '''
31
+ keys = dot_chained_keys.split('.')
32
+ for key in keys:
33
+ try:
34
+ if isinstance(data, list):
35
+ data = data[int(key)]
36
+ else:
37
+ data = data[key]
38
+ except (KeyError, TypeError, IndexError):
39
+ return None
40
+ return data
41
+
42
+ def get_notion_data() :
43
+ integration_token = "secret_lTOe0q9dqqKQLRRb2KJwi7QFSl0vqoztroRFHW6MeQE"
44
+ notion_database_id = "6c0d877b823a4e3699016fa7083f3006"
45
+
46
+ client = Client(auth=integration_token)
47
+
48
+ first_db_rows = client.databases.query(notion_database_id)
49
+ rows = []
50
+
51
+
52
+ for row in first_db_rows['results']:
53
+ price = safe_get(row, 'properties.($) Per Unit.number')
54
+ store_link = safe_get(row, 'properties.Store Link.url')
55
+ supplier_email = safe_get(row, 'properties.Supplier Email.email')
56
+ exp_del = safe_get(row, 'properties.Expected Delivery.date')
57
+
58
+ collections = safe_get(row, 'properties.Collection.multi_select')
59
+ collection_names = []
60
+ for collection in collections :
61
+ collection_names.append(collection['name'])
62
+
63
+ status = safe_get(row, 'properties.Status.select.name')
64
+ sup_phone = safe_get(row, 'properties.Supplier Phone.phone_number')
65
+ stock_alert = safe_get(row, 'properties.Stock Alert.status.name')
66
+ prod_name = safe_get(row, 'properties.Product .title.0.text.content')
67
+ sku = safe_get(row, 'properties.SKU.number')
68
+ shipped_date = safe_get(row, 'properties.Shipped On.date')
69
+ on_order = safe_get(row, 'properties.On Order.number')
70
+ on_hand = safe_get(row, 'properties.On Hand.number')
71
+ size_names = []
72
+ sizes = safe_get(row, 'properties.Size.multi_select')
73
+ for size in sizes :
74
+ size_names.append(size['name'])
75
+
76
+ rows.append({
77
+ 'Price Per unit': price,
78
+ 'Store Link' : store_link,
79
+ 'Supplier Email' : supplier_email,
80
+ 'Expected Delivery' : exp_del,
81
+ 'Collection' : collection_names,
82
+ 'Status' : status,
83
+ 'Supplier Phone' : sup_phone,
84
+ 'Stock Alert' : stock_alert,
85
+ 'Product Name' : prod_name,
86
+ 'SKU' : sku,
87
+ 'Sizes' : size_names,
88
+ })
89
+
90
+ notion_data_string = pformat(rows)
91
+ return notion_data_string
92
+
93
+
94
 
95
  def rerank(query, top_k, search_results, chunk_size=512):
96
  chunks = []
 
138
  chunk_size=512,
139
  ):
140
 
141
+ notion_data= get_notion_data()
142
 
143
  search_results = []
144
  reranked_results = []
 
163
  prev_output = prev_output if pass_prev else ""
164
 
165
  augmented_prompt = f"""
166
+
167
+ {pre_context}
168
 
169
  {context}
170
 
171
+ {notion_data}
172
  {post_context}
173
 
174
+
175
+
176
  {pre_prompt}
177
 
178
  {prompt}
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  altair==5.1.2
2
  asttokens==2.2.1
3
  attrs==23.1.0
 
1
+ notion-client==2.2.1
2
  altair==5.1.2
3
  asttokens==2.2.1
4
  attrs==23.1.0