Spaces:
Runtime error
Runtime error
Reverted back
Browse files
query.py
CHANGED
|
@@ -13,7 +13,7 @@ class VectaraQuery():
|
|
| 13 |
self.customer_id = customer_id
|
| 14 |
self.corpus_ids = corpus_ids
|
| 15 |
self.api_key = api_key
|
| 16 |
-
self.conv_id =
|
| 17 |
|
| 18 |
def submit_query(self, query_str: str):
|
| 19 |
corpora_key_list = [{
|
|
@@ -80,18 +80,18 @@ class VectaraQuery():
|
|
| 80 |
docs = res['responseSet'][0]['document']
|
| 81 |
chat = res['responseSet'][0]['summary'][0]['chat']
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
|
| 96 |
pattern = r'\[\d{1,2}\]'
|
| 97 |
matches = [match.span() for match in re.finditer(pattern, summary)]
|
|
|
|
| 13 |
self.customer_id = customer_id
|
| 14 |
self.corpus_ids = corpus_ids
|
| 15 |
self.api_key = api_key
|
| 16 |
+
self.conv_id = None
|
| 17 |
|
| 18 |
def submit_query(self, query_str: str):
|
| 19 |
corpora_key_list = [{
|
|
|
|
| 80 |
docs = res['responseSet'][0]['document']
|
| 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':
|
| 87 |
+
self.conv_id = None
|
| 88 |
+
return 'Sorry, Vectara chat turns exceeds plan limit.'
|
| 89 |
+
return 'Sorry, something went wrong in my brain. Please try again later.'
|
| 90 |
+
|
| 91 |
+
try:
|
| 92 |
+
self.conv_id = res['responseSet'][0]['summary'][0]['chat']['conversationId']
|
| 93 |
+
else:
|
| 94 |
+
print("I'm sorry. I am experiencing an error in Vectara API conversationId assignment")
|
| 95 |
|
| 96 |
pattern = r'\[\d{1,2}\]'
|
| 97 |
matches = [match.span() for match in re.finditer(pattern, summary)]
|