henryhyunwookim commited on
Commit
ad89d13
·
verified ·
1 Parent(s): dc8f606

Update utils/utils.py

Browse files

update the summarize_search_result function to handle search results without a snippet

Files changed (1) hide show
  1. utils/utils.py +7 -1
utils/utils.py CHANGED
@@ -4,11 +4,17 @@ from langchain_core.messages import HumanMessage, SystemMessage
4
  def summarize_search_result(search_output: dict) -> list:
5
  search_results = []
6
  for result in search_output["organic_results"]:
 
 
 
 
 
 
7
  result_dict = {
8
  "rank": result["position"],
9
  "title": result["title"],
10
  "URL": result["link"],
11
- "snippet": result["snippet"]
12
  }
13
  search_results.append(result_dict)
14
  return search_results
 
4
  def summarize_search_result(search_output: dict) -> list:
5
  search_results = []
6
  for result in search_output["organic_results"]:
7
+ # This is to handle search results without a snippet
8
+ try:
9
+ snippet = result["snippet"]
10
+ except KeyError:
11
+ snippet = ""
12
+
13
  result_dict = {
14
  "rank": result["position"],
15
  "title": result["title"],
16
  "URL": result["link"],
17
+ "snippet": snippet
18
  }
19
  search_results.append(result_dict)
20
  return search_results