Spaces:
Sleeping
Sleeping
Update query.py
Browse files
query.py
CHANGED
@@ -70,10 +70,12 @@ class VectaraQuery():
|
|
70 |
print(f"Received data chunk: {json.dumps(data, indent=2)}") # Debugging line
|
71 |
|
72 |
if 'result' not in data:
|
|
|
73 |
continue
|
74 |
|
75 |
res = data['result']
|
76 |
if 'responseSet' not in res:
|
|
|
77 |
continue
|
78 |
|
79 |
response_set = res['responseSet']
|
@@ -81,15 +83,24 @@ class VectaraQuery():
|
|
81 |
if response_set:
|
82 |
for result in response_set['response']:
|
83 |
if 'text' not in result:
|
|
|
84 |
continue
|
85 |
text = result['text']
|
86 |
print(f"Processing text: {text}") # Debugging line
|
87 |
|
88 |
# Adjusting regex patterns to be more flexible
|
89 |
-
reason_match = re.search(r"Reason Why it Can't be Used:\s*(.*?)(
|
90 |
-
alternative_match = re.search(r"Alternative:\s*(.*?)(
|
91 |
-
notes_match = re.search(r"Notes:\s*(.*?)(
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
reason = reason_match.group(1).strip() if reason_match else "Not available"
|
94 |
alternative = alternative_match.group(1).strip() if alternative_match else "Not available"
|
95 |
notes = notes_match.group(1).strip() if notes_match else "Not available"
|
|
|
70 |
print(f"Received data chunk: {json.dumps(data, indent=2)}") # Debugging line
|
71 |
|
72 |
if 'result' not in data:
|
73 |
+
print("No 'result' in data")
|
74 |
continue
|
75 |
|
76 |
res = data['result']
|
77 |
if 'responseSet' not in res:
|
78 |
+
print("No 'responseSet' in result")
|
79 |
continue
|
80 |
|
81 |
response_set = res['responseSet']
|
|
|
83 |
if response_set:
|
84 |
for result in response_set['response']:
|
85 |
if 'text' not in result:
|
86 |
+
print("No 'text' in result")
|
87 |
continue
|
88 |
text = result['text']
|
89 |
print(f"Processing text: {text}") # Debugging line
|
90 |
|
91 |
# Adjusting regex patterns to be more flexible
|
92 |
+
reason_match = re.search(r"Reason Why it Can't be Used:\s*(.*?)(?:\n|$)", text, re.DOTALL)
|
93 |
+
alternative_match = re.search(r"Alternative:\s*(.*?)(?:\n|$)", text, re.DOTALL)
|
94 |
+
notes_match = re.search(r"Notes:\s*(.*?)(?:\n|$)", text, re.DOTALL)
|
95 |
|
96 |
+
# Improved regex to capture multiline fields
|
97 |
+
if not reason_match:
|
98 |
+
reason_match = re.search(r"DISCUSSION\s*-\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
|
99 |
+
if not alternative_match:
|
100 |
+
alternative_match = re.search(r"Alternative\s*:\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
|
101 |
+
if not notes_match:
|
102 |
+
notes_match = re.search(r"Notes\s*:\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
|
103 |
+
|
104 |
reason = reason_match.group(1).strip() if reason_match else "Not available"
|
105 |
alternative = alternative_match.group(1).strip() if alternative_match else "Not available"
|
106 |
notes = notes_match.group(1).strip() if notes_match else "Not available"
|