Spaces:
Running
on
T4
Running
on
T4
ubi integration
Browse files- semantic_search/all_search_execute.py +17 -0
- utilities/ubi_lambda.py +23 -0
semantic_search/all_search_execute.py
CHANGED
@@ -19,6 +19,7 @@ from datetime import datetime
|
|
19 |
import boto3
|
20 |
import streamlit as st
|
21 |
import utilities.mvectors as cb
|
|
|
22 |
current_date_time = (datetime.now()).isoformat()
|
23 |
today_ = datetime.today().strftime('%Y-%m-%d')
|
24 |
|
@@ -514,6 +515,22 @@ def handler(input_,session_id):
|
|
514 |
arr.append(res_)
|
515 |
dup.append(doc['_source']['image_url'])
|
516 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
return arr[0:k_]
|
518 |
|
519 |
|
|
|
19 |
import boto3
|
20 |
import streamlit as st
|
21 |
import utilities.mvectors as cb
|
22 |
+
import utilities.ubi_lambda as ubi
|
23 |
current_date_time = (datetime.now()).isoformat()
|
24 |
today_ = datetime.today().strftime('%Y-%m-%d')
|
25 |
|
|
|
515 |
arr.append(res_)
|
516 |
dup.append(doc['_source']['image_url'])
|
517 |
|
518 |
+
########### ubi lambda call for query logging ###########
|
519 |
+
query_payload = {
|
520 |
+
"query_id": "abc123",
|
521 |
+
"user_query": json.dumps(hybrid_payload),
|
522 |
+
|
523 |
+
}
|
524 |
+
|
525 |
+
status = ubi.send_to_lambda("ubi_queries", query_payload)
|
526 |
+
|
527 |
+
if status == 202:
|
528 |
+
st.success("Query sent to Lambda")
|
529 |
+
else:
|
530 |
+
st.warning("Lambda did not accept the request")
|
531 |
+
|
532 |
+
########### end of ubi lambda call for query logging ###########
|
533 |
+
|
534 |
return arr[0:k_]
|
535 |
|
536 |
|
utilities/ubi_lambda.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import boto3
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
|
5 |
+
lambda_client = boto3.client(
|
6 |
+
'lambda',
|
7 |
+
aws_access_key_id=st.secrets['user_access_key_us_west_2'],
|
8 |
+
aws_secret_access_key=st.secrets['user_secret_key_us_west_2'], region_name = 'us-west-2'
|
9 |
+
)
|
10 |
+
|
11 |
+
def send_to_lambda(index, document):
|
12 |
+
payload = {
|
13 |
+
"target_index": index,
|
14 |
+
"document": document
|
15 |
+
}
|
16 |
+
|
17 |
+
response = lambda_client.invoke(
|
18 |
+
FunctionName='proxy-observability-opensearch-ubi',
|
19 |
+
InvocationType='Event', # async!
|
20 |
+
Payload=json.dumps(payload)
|
21 |
+
)
|
22 |
+
|
23 |
+
return response['StatusCode'] # 202 if accepted
|