Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,29 +9,46 @@ def query_vectara(question):
|
|
9 |
user_message = question
|
10 |
|
11 |
# Read authentication parameters from the .env file
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
# Define the
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
"
|
|
|
26 |
}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
response_message = f"Response from Vectara API: {json.dumps(query_data, indent=2)}"
|
33 |
else:
|
34 |
-
response_message = f"Error: {
|
35 |
|
36 |
return response_message
|
37 |
|
|
|
9 |
user_message = question
|
10 |
|
11 |
# Read authentication parameters from the .env file
|
12 |
+
CUSTOMER_ID = config('CUSTOMER_ID')
|
13 |
+
CORPUS_ID = config('CORPUS_ID')
|
14 |
+
API_KEY = config('API_KEY')
|
15 |
+
|
16 |
+
# Define the data dictionary
|
17 |
+
data_dict = {
|
18 |
+
"query": [
|
19 |
+
{
|
20 |
+
"query": user_message,
|
21 |
+
"num_results": 10,
|
22 |
+
"corpus_key": [
|
23 |
+
{
|
24 |
+
"customer_id": CUSTOMER_ID,
|
25 |
+
"corpus_id": CORPUS_ID
|
26 |
+
}
|
27 |
+
]
|
28 |
+
}
|
29 |
+
]
|
30 |
}
|
31 |
|
32 |
+
# Define the headers
|
33 |
+
api_key_header = {
|
34 |
+
"customer-id": CUSTOMER_ID,
|
35 |
+
"x-api-key": API_KEY
|
36 |
}
|
37 |
|
38 |
+
# Make the API request
|
39 |
+
response = requests.post(
|
40 |
+
"https://api.vectara.io/v1/query",
|
41 |
+
data=json.dumps(data_dict),
|
42 |
+
verify=True,
|
43 |
+
headers=api_key_header,
|
44 |
+
headers={"Content-Type": "application/json"} # Set Content-Type header
|
45 |
+
)
|
46 |
+
|
47 |
+
if response.status_code == 200:
|
48 |
+
query_data = response.json()
|
49 |
response_message = f"Response from Vectara API: {json.dumps(query_data, indent=2)}"
|
50 |
else:
|
51 |
+
response_message = f"Error: {response.status_code}"
|
52 |
|
53 |
return response_message
|
54 |
|