ofermend commited on
Commit
55fd9a2
1 Parent(s): 48f9851

Update query.py

Browse files
Files changed (1) hide show
  1. query.py +13 -18
query.py CHANGED
@@ -111,7 +111,7 @@ class VectaraQuery():
111
 
112
  endpoint = f"https://api.vectara.io/v1/query"
113
  body = self.get_body(query_str)
114
-
115
  response = requests.post(endpoint, data=json.dumps(body), verify=True, headers=self.get_headers())
116
  if response.status_code != 200:
117
  print(f"Query failed with code {response.status_code}, reason {response.reason}, text {response.text}")
@@ -141,7 +141,7 @@ class VectaraQuery():
141
 
142
  endpoint = f"https://api.vectara.io/v1/stream-query"
143
  body = self.get_body(query_str)
144
-
145
  response = requests.post(endpoint, data=json.dumps(body), verify=True, headers=self.get_headers(), stream=True)
146
  if response.status_code != 200:
147
  print(f"Query failed with code {response.status_code}, reason {response.reason}, text {response.text}")
@@ -154,14 +154,14 @@ class VectaraQuery():
154
  if line: # filter out keep-alive new lines
155
  data = json.loads(line.decode('utf-8'))
156
  res = data['result']
157
-
158
- # capture responses and docs if we get that first
159
- response_set = res['responseSet']
160
- if response_set is not None:
161
- # do we have chat conv_id to update?
162
- summary = response_set.get('summary', [])
163
- if len(summary)>0:
164
- chat = summary[0].get('chat', None)
165
  if chat and chat.get('status', None):
166
  st_code = chat['status']
167
  print(f"Chat query failed with code {st_code}")
@@ -172,13 +172,8 @@ class VectaraQuery():
172
  conv_id = chat.get('conversationId', None) if chat else None
173
  if conv_id:
174
  self.conv_id = conv_id
175
-
176
- else:
177
- # grab next chunk and yield it as output
178
- summary = res.get('summary', None)
179
- if summary is None:
180
- continue
181
- chunk = data['result']['summary']['text']
182
  accumulated_text += chunk # Append current chunk to accumulation
183
  if len(accumulated_text) > pattern_max_length:
184
  accumulated_text = re.sub(r"\[\d+\]", "", accumulated_text)
@@ -197,4 +192,4 @@ class VectaraQuery():
197
  chunks.append(accumulated_text)
198
  yield accumulated_text
199
 
200
- return ''.join(chunks)
 
111
 
112
  endpoint = f"https://api.vectara.io/v1/query"
113
  body = self.get_body(query_str)
114
+
115
  response = requests.post(endpoint, data=json.dumps(body), verify=True, headers=self.get_headers())
116
  if response.status_code != 200:
117
  print(f"Query failed with code {response.status_code}, reason {response.reason}, text {response.text}")
 
141
 
142
  endpoint = f"https://api.vectara.io/v1/stream-query"
143
  body = self.get_body(query_str)
144
+
145
  response = requests.post(endpoint, data=json.dumps(body), verify=True, headers=self.get_headers(), stream=True)
146
  if response.status_code != 200:
147
  print(f"Query failed with code {response.status_code}, reason {response.reason}, text {response.text}")
 
154
  if line: # filter out keep-alive new lines
155
  data = json.loads(line.decode('utf-8'))
156
  res = data['result']
157
+
158
+ if response_set is None:
159
+ # grab next chunk and yield it as output
160
+ summary = res.get('summary', None)
161
+ if summary is None or len(summary)==0:
162
+ continue
163
+ else:
164
+ chat = summary.get('chat', None)
165
  if chat and chat.get('status', None):
166
  st_code = chat['status']
167
  print(f"Chat query failed with code {st_code}")
 
172
  conv_id = chat.get('conversationId', None) if chat else None
173
  if conv_id:
174
  self.conv_id = conv_id
175
+
176
+ chunk = summary['text']
 
 
 
 
 
177
  accumulated_text += chunk # Append current chunk to accumulation
178
  if len(accumulated_text) > pattern_max_length:
179
  accumulated_text = re.sub(r"\[\d+\]", "", accumulated_text)
 
192
  chunks.append(accumulated_text)
193
  yield accumulated_text
194
 
195
+ return ''.join(chunks)