Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,35 +13,63 @@ def query_vectara(question):
|
|
13 |
CORPUS_ID = config('CORPUS_ID')
|
14 |
API_KEY = config('API_KEY')
|
15 |
|
16 |
-
# Define the
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"query": [
|
19 |
{
|
20 |
"query": user_message,
|
21 |
-
"
|
22 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
{
|
24 |
-
"
|
25 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
]
|
28 |
}
|
29 |
]
|
30 |
}
|
31 |
|
32 |
-
#
|
33 |
-
api_key_header = {
|
34 |
-
"customer-id": CUSTOMER_ID,
|
35 |
-
"x-api-key": API_KEY,
|
36 |
-
"Content-Type": "application/json" # Set Content-Type header
|
37 |
-
}
|
38 |
-
|
39 |
-
# Make the API request
|
40 |
response = requests.post(
|
41 |
"https://api.vectara.io/v1/query",
|
42 |
-
|
43 |
verify=True,
|
44 |
-
headers=api_key_header
|
45 |
)
|
46 |
|
47 |
if response.status_code == 200:
|
@@ -55,7 +83,7 @@ def query_vectara(question):
|
|
55 |
iface = gr.Interface(
|
56 |
fn=query_vectara,
|
57 |
inputs=[gr.Textbox(label="Input Text")],
|
58 |
-
outputs=
|
59 |
title="Vectara Chatbot",
|
60 |
description="Ask me anything using the Vectara API!"
|
61 |
)
|
|
|
13 |
CORPUS_ID = config('CORPUS_ID')
|
14 |
API_KEY = config('API_KEY')
|
15 |
|
16 |
+
# Define the headers
|
17 |
+
api_key_header = {
|
18 |
+
"customer-id": CUSTOMER_ID,
|
19 |
+
"x-api-key": API_KEY
|
20 |
+
}
|
21 |
+
|
22 |
+
# Define the request body in the structure provided in the example
|
23 |
+
request_body = {
|
24 |
"query": [
|
25 |
{
|
26 |
"query": user_message,
|
27 |
+
"queryContext": "",
|
28 |
+
"start": 0,
|
29 |
+
"numResults": 25,
|
30 |
+
"contextConfig": {
|
31 |
+
"charsBefore": 0,
|
32 |
+
"charsAfter": 0,
|
33 |
+
"sentencesBefore": 2,
|
34 |
+
"sentencesAfter": 2,
|
35 |
+
"startTag": "%START_SNIPPET%",
|
36 |
+
"endTag": "%END_SNIPPET%",
|
37 |
+
},
|
38 |
+
"rerankingConfig": {
|
39 |
+
"rerankerId": 272725718,
|
40 |
+
"mmrConfig": {
|
41 |
+
"diversityBias": 0.3
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"corpusKey": [
|
45 |
{
|
46 |
+
"customerId": CUSTOMER_ID,
|
47 |
+
"corpusId": CORPUS_ID,
|
48 |
+
"semantics": 0,
|
49 |
+
"metadataFilter": "",
|
50 |
+
"lexicalInterpolationConfig": {
|
51 |
+
"lambda": 0
|
52 |
+
},
|
53 |
+
"dim": []
|
54 |
+
}
|
55 |
+
],
|
56 |
+
"summary": [
|
57 |
+
{
|
58 |
+
"maxSummarizedResults": 1,
|
59 |
+
"responseLang": "eng",
|
60 |
+
"summarizerPromptName": "vectara-summary-ext-v1.2.0"
|
61 |
}
|
62 |
]
|
63 |
}
|
64 |
]
|
65 |
}
|
66 |
|
67 |
+
# Make the API request using Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
response = requests.post(
|
69 |
"https://api.vectara.io/v1/query",
|
70 |
+
json=request_body, # Use json to automatically serialize the request body
|
71 |
verify=True,
|
72 |
+
headers=api_key_header
|
73 |
)
|
74 |
|
75 |
if response.status_code == 200:
|
|
|
83 |
iface = gr.Interface(
|
84 |
fn=query_vectara,
|
85 |
inputs=[gr.Textbox(label="Input Text")],
|
86 |
+
outputs=gr.Textbox(label="Output Text"),
|
87 |
title="Vectara Chatbot",
|
88 |
description="Ask me anything using the Vectara API!"
|
89 |
)
|