Update query.py
Browse files
query.py
CHANGED
@@ -81,6 +81,7 @@ class VectaraQuery():
|
|
81 |
chat = res['responseSet'][0]['summary'][0]['chat']
|
82 |
|
83 |
# if chat['status'] != None:
|
|
|
84 |
# st_code = chat['status']
|
85 |
# print(f"Chat query failed with code {st_code}")
|
86 |
# if st_code == 'RESOURCE_EXHAUSTED':
|
@@ -88,11 +89,39 @@ class VectaraQuery():
|
|
88 |
# return 'Sorry, chat turns exceeds plan limit.'
|
89 |
# return 'Sorry, something went wrong in my brain. Please try again later.'
|
90 |
|
|
|
|
|
91 |
try:
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
except (TypeError):
|
94 |
-
|
|
|
95 |
|
|
|
|
|
|
|
96 |
pattern = r'\[\d{1,2}\]'
|
97 |
matches = [match.span() for match in re.finditer(pattern, summary)]
|
98 |
|
|
|
81 |
chat = res['responseSet'][0]['summary'][0]['chat']
|
82 |
|
83 |
# if chat['status'] != None:
|
84 |
+
# # chat['status'] = # I have no idea what to put here hahaha
|
85 |
# st_code = chat['status']
|
86 |
# print(f"Chat query failed with code {st_code}")
|
87 |
# if st_code == 'RESOURCE_EXHAUSTED':
|
|
|
89 |
# return 'Sorry, chat turns exceeds plan limit.'
|
90 |
# return 'Sorry, something went wrong in my brain. Please try again later.'
|
91 |
|
92 |
+
#Another Bard patch for diagnostics
|
93 |
+
|
94 |
try:
|
95 |
+
# Step 1a: Check for 'responseSet'
|
96 |
+
if res is not None and 'responseSet' in res:
|
97 |
+
response_set = res['responseSet']
|
98 |
+
|
99 |
+
# Step 1b: Check for 'summary' within the first item
|
100 |
+
if len(response_set) > 0 and 'summary' in response_set[0]:
|
101 |
+
summary = response_set[0]['summary']
|
102 |
+
|
103 |
+
# Step 1c: Check for 'chat' within the first summary
|
104 |
+
if len(summary) > 0 and 'chat' in summary[0]:
|
105 |
+
chat = summary[0]['chat']
|
106 |
+
|
107 |
+
# Step 1d: Finally, access 'conversationId'
|
108 |
+
self.conv_id = chat['conversationId']
|
109 |
+
else:
|
110 |
+
# Handle missing 'chat' in summary
|
111 |
+
print("Chat data not found in response summary")
|
112 |
+
else:
|
113 |
+
# Handle missing or empty 'summary'
|
114 |
+
print("Response summary missing or empty")
|
115 |
+
else:
|
116 |
+
# Handle missing or empty 'responseSet'
|
117 |
+
print("Response data unavailable")
|
118 |
except (TypeError):
|
119 |
+
# Handle TypeError if any of the access attempts fail
|
120 |
+
print('Sorry, something went wrong. Please try again later.')
|
121 |
|
122 |
+
|
123 |
+
#End diagnostics
|
124 |
+
|
125 |
pattern = r'\[\d{1,2}\]'
|
126 |
matches = [match.span() for match in re.finditer(pattern, summary)]
|
127 |
|