Tonic commited on
Commit
3661992
1 Parent(s): c417c59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -51
app.py CHANGED
@@ -6,64 +6,23 @@ from decouple import Config
6
  config = Config('.env')
7
 
8
  def query_vectara(question):
9
- # Get the user's message from the chat history
10
  user_message = question
11
 
12
- # Query Vectara API
13
- customer_id = config('CUSTOMER_ID') # Read from .env file
14
- corpus_id = config('CORPUS_ID') # Read from .env file
15
- api_key = config('API_KEY') # Read from .env file
16
 
17
- query_url = "https://api.vectara.io:443/v1/query"
 
18
 
19
  headers = {
20
- "Content-Type": "application/json",
21
- "authorization": f"Bearer {api_key}", # Corrected authorization header
22
- "customer-id": customer_id,
23
  }
24
 
25
  query_body = {
26
- "query": [
27
- {
28
- "query": user_message,
29
- "queryContext": "",
30
- "start": 0,
31
- "numResults": 10,
32
- "contextConfig": {
33
- "charsBefore": 0,
34
- "charsAfter": 0,
35
- "sentencesBefore": 2,
36
- "sentencesAfter": 2,
37
- "startTag": "%START_SNIPPET%",
38
- "endTag": "%END_SNIPPET%",
39
- },
40
- "rerankingConfig": {
41
- "rerankerId": 272725718,
42
- "mmrConfig": {
43
- "diversityBias": 0.3
44
- }
45
- },
46
- "corpusKey": [
47
- {
48
- "customerId": customer_id,
49
- "corpusId": corpus_id,
50
- "semantics": 0,
51
- "metadataFilter": "",
52
- "lexicalInterpolationConfig": {
53
- "lambda": 0
54
- },
55
- "dim": []
56
- }
57
- ],
58
- "summary": [
59
- {
60
- "maxSummarizedResults": 5,
61
- "responseLang": "eng",
62
- "summarizerPromptName": "vectara-summary-ext-v1.2.0"
63
- }
64
- ]
65
- }
66
- ]
67
  }
68
 
69
  query_response = requests.post(query_url, json=query_body, headers=headers)
@@ -76,7 +35,6 @@ def query_vectara(question):
76
 
77
  return response_message
78
 
79
- # Create a Gradio ChatInterface with only a text input
80
  iface = gr.Interface(
81
  fn=query_vectara,
82
  inputs=[gr.Textbox(label="Input Text")],
 
6
  config = Config('.env')
7
 
8
  def query_vectara(question):
 
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 query URL
17
+ query_url = f"https://api.vectara.io:443/v1/query?customer_id={customer_id}&corpus_id={corpus_id}"
18
 
19
  headers = {
20
+ "x-api-key": api_key, # Use the x-api-key header for authentication
 
 
21
  }
22
 
23
  query_body = {
24
+ "query": user_message,
25
+ "num_results": 10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
  query_response = requests.post(query_url, json=query_body, headers=headers)
 
35
 
36
  return response_message
37
 
 
38
  iface = gr.Interface(
39
  fn=query_vectara,
40
  inputs=[gr.Textbox(label="Input Text")],