srivatsavdamaraju
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import requests
|
3 |
+
import traceback
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Function to query the external service
|
8 |
+
def query_external_service(query_text):
|
9 |
+
url = 'https://ig.aidtaas.com/python-pipelines/data/query'
|
10 |
+
|
11 |
+
headers = {
|
12 |
+
'openai_key': 'sk-proj-9wbKIiDGVjsScdYKX3EZT3BlbkFJk55rhX7cN3MLyBskELdr',
|
13 |
+
'Content-Type': 'application/json',
|
14 |
+
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI3Ny1NUVdFRTNHZE5adGlsWU5IYmpsa2dVSkpaWUJWVmN1UmFZdHl5ejFjIn0.eyJleHAiOjE3MzQzNzU0MjksImlhdCI6MTczNDMzOTQyOSwianRpIjoiODU4N2Y4ZjctYjViMi00NWZhLWFlNWUtNTliYzc1MTE1YTYwIiwiaXNzIjoiaHR0cDovL2tleWNsb2FrLXNlcnZpY2Uua2V5Y2xvYWsuc3ZjLmNsdXN0ZXIubG9jYWw6ODA4MC9yZWFsbXMvbWFzdGVyIiwiYXVkIjpbIkJPTFRaTUFOTl9CT1RfbW9iaXVzIiwiUEFTQ0FMX0lOVEVMTElHRU5DRV9tb2JpdXMiLC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0YJdSJN8CZGelyFThLIOKd35yt3kMTHGqIktd0gP1GsfeLorgaOkhu0tPXmbY1WO_0c8J6HAeYOhpdIz69sIOT_qRmTVX35FFmxBw8UZx3SBkAdTaQUZu4k_NETt3v-wofewiU_AOrEv-y8ktTE0A-H9Z0eG-tmIKxd2uAsnXPb8CP_02biKPd4oK4ogTdefVGYrE_CdaLuJiKGeylRqkKUJLBvuDD_FcTwbCNeFFrh36Z1BxcHhbR4OjO1wOVUt_TlVNvKYlg8M4CCZb8qCffI-6yjm9sSPORnW-GXzNboqZnLxkvQgSZomHDOnOj2A25hg', # Replace with actual token
|
15 |
+
}
|
16 |
+
|
17 |
+
# Payload with default values for other parameters, only 'query_text' is dynamic
|
18 |
+
payload = {
|
19 |
+
"collection_name": "vatsav1",
|
20 |
+
"query_text": query_text,
|
21 |
+
"top_k": 10,
|
22 |
+
"tenant_id": "str", # Set this as needed, or get from input
|
23 |
+
"metadata_filter_map": {},
|
24 |
+
"doc_filter_map": {},
|
25 |
+
"projection_fields": [
|
26 |
+
"documents",
|
27 |
+
"distances",
|
28 |
+
"metadatas"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
|
32 |
+
try:
|
33 |
+
# Sending the request to the external service
|
34 |
+
response = requests.post(url, json=payload, headers=headers)
|
35 |
+
|
36 |
+
# Check if the response was successful (status code 200)
|
37 |
+
response.raise_for_status()
|
38 |
+
|
39 |
+
# Return the response as JSON
|
40 |
+
return response.json()
|
41 |
+
|
42 |
+
except requests.exceptions.HTTPError as http_err:
|
43 |
+
print(f"HTTP error occurred: {http_err}")
|
44 |
+
return {"error": "External API error", "message": str(http_err)}, 500
|
45 |
+
except Exception as err:
|
46 |
+
print(f"Other error occurred: {err}")
|
47 |
+
print(traceback.format_exc())
|
48 |
+
return {"error": "An error occurred", "message": str(err)}, 500
|
49 |
+
|
50 |
+
|
51 |
+
# API route to handle queries
|
52 |
+
@app.route('/input_query', methods=['POST'])
|
53 |
+
def input_query():
|
54 |
+
# Get query_text from the JSON request body
|
55 |
+
data = request.get_json()
|
56 |
+
|
57 |
+
if not data:
|
58 |
+
return jsonify({"error": "Invalid JSON"}), 400
|
59 |
+
|
60 |
+
query_text = data.get('query_text', '')
|
61 |
+
|
62 |
+
# Check if the query_text is provided
|
63 |
+
if not query_text:
|
64 |
+
return jsonify({"error": "query_text is required"}), 400
|
65 |
+
|
66 |
+
# Query the external service
|
67 |
+
response = query_external_service(query_text)
|
68 |
+
|
69 |
+
# Return the response from the external API
|
70 |
+
return jsonify(response)
|
71 |
+
|
72 |
+
if __name__ == '__main__':
|
73 |
+
app.run(debug=True)
|