iamrobotbear commited on
Commit
23d19f4
1 Parent(s): d3f8557

Update query.py

Browse files
Files changed (1) hide show
  1. query.py +17 -4
query.py CHANGED
@@ -69,17 +69,30 @@ class VectaraQuery():
69
  pattern_max_length = 50 # Example heuristic
70
  for line in response.iter_lines():
71
  if line: # filter out keep-alive new lines
72
- data = json.loads(line.decode('utf-8'))
 
 
 
 
73
  res = data['result']
 
 
 
74
  response_set = res['responseSet']
75
 
76
  if response_set:
77
  for result in response_set:
 
 
78
  text = result['text']
79
  # Extract relevant information from the text
80
- reason = re.search(r"Reason Why it Can't be Used: (.*?)\n", text).group(1)
81
- alternative = re.search(r"Alternative: (.*?)\n", text).group(1)
82
- notes = re.search(r"Notes: (.*?)\n", text).group(1)
 
 
 
 
83
 
84
  response = f"Reason: {reason}\nAlternative: {alternative}\nNotes: {notes}"
85
  return response
 
69
  pattern_max_length = 50 # Example heuristic
70
  for line in response.iter_lines():
71
  if line: # filter out keep-alive new lines
72
+ data = json.loads(line.decode('utf-8'))
73
+
74
+ if 'result' not in data:
75
+ continue
76
+
77
  res = data['result']
78
+ if 'responseSet' not in res:
79
+ continue
80
+
81
  response_set = res['responseSet']
82
 
83
  if response_set:
84
  for result in response_set:
85
+ if 'text' not in result:
86
+ continue
87
  text = result['text']
88
  # Extract relevant information from the text
89
+ reason_match = re.search(r"Reason Why it Can't be Used: (.*?)\n", text)
90
+ alternative_match = re.search(r"Alternative: (.*?)\n", text)
91
+ notes_match = re.search(r"Notes: (.*?)\n", text)
92
+
93
+ reason = reason_match.group(1) if reason_match else "Not available"
94
+ alternative = alternative_match.group(1) if alternative_match else "Not available"
95
+ notes = notes_match.group(1) if notes_match else "Not available"
96
 
97
  response = f"Reason: {reason}\nAlternative: {alternative}\nNotes: {notes}"
98
  return response