-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathChatGee_Mac
executable file
·120 lines (101 loc) · 2.91 KB
/
ChatGee_Mac
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/zsh
cleanup(){
kill -9 `ps -ef | grep ' chatgee/run_server.py' | grep -v grep | awk '{print $2}'`
}
trap cleanup INT TERM
mypath=${0:a}
dirname=$mypath:h
cd $dirname
find_python(){
for python in `which python3.10`
do
if [[ ! -f "$python" ]]; then continue; fi
var=`$python -c 'import sys;print(sys.version_info.minor==10)' 2>&1`
if [[ 'True' == $var ]]
then
echo $python
break
fi
done
echo ""
}
check_python(){
if [[ '' == $1 ]]
then
echo
echo Pyton 3.10 is not installed !
exit 1
else
echo
echo Python 3.10 Installation Confirmed !
fi
}
ngrok_yaml_path(){
echo "/Users/"$USER"/Library/Application Support/ngrok/ngrok.yml"
}
check_ngrok(){
if [[ -f "ngrok" ]]; then
return 1
fi
arch=`uname -m`
if [[ $arch != "arm64" ]]; then arch="amd64"; fi
zip="ngrok-v3-stable-darwin-"$arch".zip"
url="https://bin.equinox.io/c/bNyj1mQVY4c/"$zip
echo "========== Downloading ngrok =========="
curl -O $url
unzip $zip
}
check_token_and_api(){
if [[ $1 == "YOUR_OPEN_AI_API_KEY" ]]; then
echo ""
echo "You should input OPEN_API \"API_KEY\" in settings.yaml"
exit 1
fi
if [[ $2 == "YOUR_NGROK_TOKEN" ]]; then
echo ""
echo "You should input NGROK \"TOKEN\" in settings.yaml"
exit 1
fi
}
echo
echo
echo "========== ChatGee AI Chatbot =========="
if [[ ! -f "venv_chatgee/bin/activate" ]]; then
python=$(find_python)
check_python $python
basename=$python:h
pip=$basename/pip3.10
if [[ `which $pip` == $pip ]]
then
echo pip3 Installation Confirmed !
else
$python -m ensurepip --upgrade > /dev/null 2>&1
fi
echo
echo "Initiate Virtual Environment for ChatGee"
$python -m pip install --upgrade pip > /dev/null 2>&1
$pip install virtualenv > /dev/null 2>&1
$python -m venv venv_chatgee > /dev/null 2>&1
fi
source venv_chatgee/bin/activate
check_ngrok
echo
echo "========= Virtual Environment =========="
echo
echo "(1/4) Install ChatGee Library"
# 가상환경을 source 했으니 경로가 상관이 없어졌다.
pip install -r requirements.txt > /dev/null 2>&1
open_api_key=`python -c "import yaml; stream=open('settings.yaml', 'r'); print(yaml.load(stream,yaml.FullLoader)['OPEN_AI']['API_KEY'])"`
ngrok_token=`python -c "import yaml; stream=open('settings.yaml', 'r'); print(yaml.load(stream,yaml.FullLoader)['NGROK']['TOKEN'])"`
check_token_and_api $open_api_key $ngrok_token
echo
echo "(2/4) Run ChatGee Server"
python chatgee/run_server.py > /dev/null 2>&1 &
echo
echo "(3/4) Reading settings.yaml file..."
port_number=`python -c "import yaml; stream=open('settings.yaml', 'r'); print(yaml.load(stream,yaml.FullLoader)['SERVER']['PORT_NUMBER'])"`
echo
echo "(4/4) Run ngrok"
./ngrok config add-authtoken $ngrok_token
./ngrok http $port_number
wait