Tonic commited on
Commit
1866b5b
1 Parent(s): 4d079d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -75,11 +75,14 @@ def query_vectara(question):
75
 
76
  if response.status_code == 200:
77
  query_data = response.json()
78
- # Extract summary and the first 5 sources
79
- summary_text = query_data[0]["summary"]["text"]
80
- sources = query_data[0]["responseSet"]["responseList"][:5]
81
- sources_text = [source["text"] for source in sources]
82
- return f"Summary: {summary_text}\n\nSources:\n{json.dumps(sources_text, indent=2)}"
 
 
 
83
  else:
84
  return f"Error: {response.status_code}"
85
 
 
75
 
76
  if response.status_code == 200:
77
  query_data = response.json()
78
+ if query_data:
79
+ # Extract summary and the first 5 sources
80
+ summary_text = query_data[0]["summary"]["text"]
81
+ sources = query_data[0]["responseSet"]["responseList"][:5]
82
+ sources_text = [source["text"] for source in sources]
83
+ return f"Summary: {summary_text}\n\nSources:\n{json.dumps(sources_text, indent=2)}"
84
+ else:
85
+ return "No data found in the response."
86
  else:
87
  return f"Error: {response.status_code}"
88