-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.sh
69 lines (53 loc) · 1.54 KB
/
setup.sh
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
#!/bin/bash
# Check if config.py exists
if [ ! -f config.py ]; then
# config.py doesn't exist, create a new one with default values
cat <<EOF > config.py
# Configuration file
# OpenAI API key
OPENAI_API_KEY = ""
# MML model file path
MML_MODEL_FILE = ""
# Prompt file path
PROMPT_FILE = "prompt.txt"
# IP address and port
IP_ADDRESS = ""
PORT = 8081
EOF
fi
# Read the existing values from config.py
EXISTING_OPENAI_API_KEY=$(grep -oP 'OPENAI_API_KEY = "\K[^"]*' config.py)
EXISTING_MML_MODEL_FILE=$(grep -oP 'MML_MODEL_FILE = "\K[^"]*' config.py)
EXISTING_IP_ADDRESS=$(grep -oP 'IP_ADDRESS = "\K[^"]*' config.py)
EXISTING_PORT=$(grep -oP 'PORT = \K[^"]*' config.py)
# Prompt the user for new values if they don't exist or ask to use existing values
OPENAI_API_KEY=${EXISTING_OPENAI_API_KEY}
if [ -z "$OPENAI_API_KEY" ]; then
read -p "Enter the OpenAI API key: " OPENAI_API_KEY
fi
MML_MODEL_FILE=${EXISTING_MML_MODEL_FILE}
if [ -z "$MML_MODEL_FILE" ]; then
read -p "Enter the MML model file path: " MML_MODEL_FILE
fi
PROMPT_FILE="prompt.txt"
IP_ADDRESS=${EXISTING_IP_ADDRESS}
if [ -z "$IP_ADDRESS" ]; then
read -p "Enter the IP address: " IP_ADDRESS
fi
PORT=${EXISTING_PORT}
if [ -z "$PORT" ]; then
read -p "Enter the port: " PORT
fi
# Write the updated values to config.py
cat <<EOF > config.py
# Configuration file
# OpenAI API key
OPENAI_API_KEY = "$OPENAI_API_KEY"
# MML model file path
MML_MODEL_FILE = "$MML_MODEL_FILE"
# Prompt file path
PROMPT_FILE = "$PROMPT_FILE"
# IP address and port
IP_ADDRESS = "$IP_ADDRESS"
PORT = $PORT
EOF