Tonic commited on
Commit
4d079d2
1 Parent(s): 176b9ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -38,7 +38,7 @@ def query_vectara(question):
38
  "rerankingConfig": {
39
  "rerankerId": 272725718,
40
  "mmrConfig": {
41
- "diversityBias": 0.3
42
  }
43
  },
44
  "corpusKey": [
@@ -72,13 +72,16 @@ def query_vectara(question):
72
  headers=api_key_header
73
  )
74
 
 
75
  if response.status_code == 200:
76
  query_data = response.json()
77
- response_message = f"Response from Vectara API: {json.dumps(query_data, indent=2)}"
 
 
 
 
78
  else:
79
- response_message = f"Error: {response.status_code}"
80
-
81
- return response_message
82
 
83
  iface = gr.Interface(
84
  fn=query_vectara,
 
38
  "rerankingConfig": {
39
  "rerankerId": 272725718,
40
  "mmrConfig": {
41
+ "diversityBias": 0.27
42
  }
43
  },
44
  "corpusKey": [
 
72
  headers=api_key_header
73
  )
74
 
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
 
86
  iface = gr.Interface(
87
  fn=query_vectara,