NCTCMumbai commited on
Commit
5fcec1c
·
verified ·
1 Parent(s): 03e03a6

Update middlewares/utils.py

Browse files
Files changed (1) hide show
  1. middlewares/utils.py +17 -25
middlewares/utils.py CHANGED
@@ -7,19 +7,14 @@ from middlewares.search_client import SearchClient
7
  import os
8
  from dotenv import load_dotenv
9
 
10
-
11
  load_dotenv()
12
- API_TOKEN = os.getenv("HF_TOKEN")
13
- GOOGLE_SEARCH_ENGINE_ID = os.getenv("GOOGLE_SEARCH_ENGINE_ID")
14
- GOOGLE_SEARCH_API_KEY = os.getenv("GOOGLE_SEARCH_API_KEY")
15
- #BING_SEARCH_API_KEY = os.getenv("BING_SEARCH_API_KEY")
16
- BING_SEARCH_API_KEY = os.environ.get('AZURE_SEARCH_KEY', 'b828219acd4f46d0b77d51b4564a8475')
17
 
18
- reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
 
19
 
20
- googleSearchClient = SearchClient(
21
- "google", api_key=GOOGLE_SEARCH_API_KEY, engine_id=GOOGLE_SEARCH_ENGINE_ID
22
- )
23
  bingSearchClient = SearchClient("bing", api_key=BING_SEARCH_API_KEY, engine_id=None)
24
 
25
 
@@ -71,20 +66,17 @@ def gen_augmented_prompt_via_websearch(
71
  chunk_size=512,
72
  ):
73
 
74
- try:
75
- search_results = []
76
- reranked_results = []
77
- if search_vendor == "Google":
78
- search_results = googleSearchClient.search(prompt, n_crawl)
79
- elif search_vendor == "Bing":
80
- print('[Bing search enabled]')
81
- search_results = bingSearchClient.search(prompt, n_crawl)
82
- print(search_results)
83
- print('[Bing search completed]')
84
- if len(search_results) > 0:
85
- reranked_results = rerank(prompt, top_k, search_results, chunk_size)
86
- except Exception as e:
87
- print(e)
88
 
89
  links = []
90
  context = ""
@@ -118,4 +110,4 @@ def gen_augmented_prompt_via_websearch(
118
  """
119
 
120
  print(augmented_prompt)
121
- return augmented_prompt, links
 
7
  import os
8
  from dotenv import load_dotenv
9
 
 
10
  load_dotenv()
 
 
 
 
 
11
 
12
+ start_date='1/05/2024'
13
+ end_date='26/05/2024'
14
 
15
+ BING_SEARCH_API_KEY = os.environ.get('AZURE_SEARCH_KEY', 'b828219acd4f46d0b77d51b4564a8475')
16
+ reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
17
+ googleSearchClient = SearchClient("google",api_key=None, engine_id=None)
18
  bingSearchClient = SearchClient("bing", api_key=BING_SEARCH_API_KEY, engine_id=None)
19
 
20
 
 
66
  chunk_size=512,
67
  ):
68
 
69
+
70
+ search_results = []
71
+ reranked_results = []
72
+ if search_vendor == "Google":
73
+ search_results =googleSearchClient.search_google(start_date,end_date,prompt, n_crawl)
74
+ elif search_vendor == "Bing":
75
+ search_results = bingSearchClient.search(prompt, n_crawl)
76
+ print('search_results',search_results)
77
+
78
+ if len(search_results) > 0:
79
+ reranked_results = rerank(prompt, top_k, search_results, chunk_size)
 
 
 
80
 
81
  links = []
82
  context = ""
 
110
  """
111
 
112
  print(augmented_prompt)
113
+ return augmented_prompt, links