-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupothers.py
91 lines (64 loc) · 2.55 KB
/
setupothers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import requests
from dotenv import load_dotenv
import json
import re
import os
import argparse
load_dotenv()
#set up argparse
parser = argparse.ArgumentParser()
parser.add_argument('--capella', action='store_true', default=False, help='if the environment is Capella')
args = parser.parse_args()
IS_CAPELLA = args.capella
EVENTING_HOSTNAME = os.getenv("EVENTING_HOSTNAME")
SEARCH_HOSTNAME = os.getenv("SEARCH_HOSTNAME")
CB_USERNAME = os.getenv("CB_USERNAME")
CB_PASSWORD = os.getenv("CB_PASSWORD")
CHATBOT_APP_END_POINT= os.getenv("CHATBOT_APP_END_POINT")
#updating the endpoint in templates/index.html
index_file = "./templates/index.html"
try:
with open(index_file, 'r') as file:
content = file.read()
updated_content = content.replace("http://localhost:5000", f"http://{CHATBOT_APP_END_POINT}:5000")
with open(index_file, 'w') as file:
file.write(updated_content)
print("Endpoint updated successfully in index.html")
except Exception as e:
print(f"Error updating endpoint in index.html: {str(e)}")
# setup functions
def import_function(function_name):
if IS_CAPELLA:
return
print(f"Importing function {function_name}...")
try:
url = f"http://{EVENTING_HOSTNAME}:8096/api/v1/functions/{function_name}"
with open(f'./templates/assets/eventing/{function_name}.json', 'r') as file:
data = json.load(file)
data_str = json.dumps(data)
data_str = re.sub(r"ec2-.+\.com", CHATBOT_APP_END_POINT, data_str)
data = json.loads(data_str)
response = requests.post(url, json=data, auth=(CB_USERNAME, CB_PASSWORD))
response.raise_for_status()
print(f"Function {function_name} imported successfully")
except Exception as e:
print(f"Error importing function {function_name}: {str(e)}")
import_function("reformatting")
import_function("metadata_labelling")
import_function("embedding")
#setup fts index
def import_fts_index():
if IS_CAPELLA:
return
print(f"Importing fts index...")
try:
url = f"http://{SEARCH_HOSTNAME}:8094/api/bucket/main/scope/data/index/embedding-index"
with open(f'./templates/assets/fts-index.json', 'r') as file:
data = json.load(file)
requests.put(url, auth=(CB_USERNAME, CB_PASSWORD), json=data)
print('fts index imported successfully')
except Exception as e:
print(f"Error importing fts index: {str(e)}")
import_fts_index()
print("setup complete.")