Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -72,19 +72,35 @@ def query_vectara(question):
|
|
72 |
verify=True,
|
73 |
headers=api_key_header
|
74 |
)
|
75 |
-
|
76 |
-
|
77 |
if response.status_code == 200:
|
78 |
query_data = response.json()
|
79 |
-
print(query_data)
|
80 |
if query_data:
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
else:
|
89 |
return "No data found in the response."
|
90 |
else:
|
|
|
72 |
verify=True,
|
73 |
headers=api_key_header
|
74 |
)
|
75 |
+
|
|
|
76 |
if response.status_code == 200:
|
77 |
query_data = response.json()
|
78 |
+
print(query_data)
|
79 |
if query_data:
|
80 |
+
sources_info = []
|
81 |
+
|
82 |
+
# Iterate over all response sets
|
83 |
+
for response_set in query_data.get('responseSet', []):
|
84 |
+
# Extract sources
|
85 |
+
for source in response_set.get('response', []):
|
86 |
+
source_metadata = source.get('metadata', [])
|
87 |
+
source_info = {}
|
88 |
+
|
89 |
+
for metadata in source_metadata:
|
90 |
+
metadata_name = metadata.get('name', '')
|
91 |
+
metadata_value = metadata.get('value', '')
|
92 |
+
|
93 |
+
if metadata_name == 'title':
|
94 |
+
source_info['title'] = metadata_value
|
95 |
+
elif metadata_name == 'author':
|
96 |
+
source_info['author'] = metadata_value
|
97 |
+
elif metadata_name == 'pageNumber':
|
98 |
+
source_info['page number'] = metadata_value
|
99 |
+
|
100 |
+
if source_info:
|
101 |
+
sources_info.append(source_info)
|
102 |
+
|
103 |
+
return f"Sources:\n{json.dumps(sources_info, indent=2)}"
|
104 |
else:
|
105 |
return "No data found in the response."
|
106 |
else:
|