This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring.sh
126 lines (109 loc) · 2.69 KB
/
ring.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
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
121
122
123
124
125
126
#!/bin/bash
# Load the .env file if it exists
if [ -f .env ]; then
source .env
fi
# Loading environmental variables from .env, and mission critical defaults in case it isn't found
LOCAL_PORT=${LOCAL_PORT:-3456}
DESTINATION_API=${DESTINATION_API:-"http://localhost:1234"}
ENDPOINT_COMPLETIONS=${ENDPOINT_COMPLETIONS:-"/v1/chat/completions"}
ENDPOINT_MODELS=${ENDPOINT_MODELS:-"/v1/models"}
API_KEYS=${API_KEYS:-""}
WAN_ENABLED=${WAN_ENABLED:-false}
AUTOSTYLE=${AUTOSTYLE:-true}
SYSTEM_MSG=${SYSTEM_MSG:-"You are a helpful AI."}
SYSTEM_OVERRIDE=${SYSTEM_OVERRIDE:-false}
NOSTREAM=${NOSTREAM:-false}
USE_TMUX=false
RELOAD=false
VENV_DIR="venv"
PYTHON_BIN=$(which python3 || echo "python3")
# Check if Python is available
if ! command -v $PYTHON_BIN &> /dev/null; then
echo "Python 3 is not installed or not in PATH. Please install Python 3 or provide the path to Python 3."
exit 1
fi
# Check if the virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment..."
$PYTHON_BIN -m venv "$VENV_DIR"
fi
PYTHON_BIN=./venv/bin/python
# Activate the virtual environment
source "$VENV_DIR/bin/activate"
which python
which pip
pip list
# Install or update dependencies
echo "Installing/Updating dependencies..."
pip install fastapi uvicorn httpx pytz pydantic python-dotenv h2
pip install 'httpx[http2]'
UVICORN_BIN=$(which uvicorn || echo "uvicorn")
TMUX_BIN=$(which tmux || echo "tmux")
# Parse command-line options
while [ "$#" -gt 0 ]; do
case "$1" in
--port)
LOCAL_PORT="$2"
shift 2
;;
--api-url)
DESTINATION_API="$2"
shift 2
;;
--sys)
SYSTEM_MSG="$2"
shift 2
;;
--forcesys)
SYSTEM_OVERRIDE=true
shift
;;
--tmux)
USE_TMUX=true
shift
;;
--nostream)
NOSTREAM=true
shift
;;
--wan)
WAN_ENABLED=true
shift
;;
--nostyle)
AUTOSTYLE=false
shift
;;
--reload)
RELOAD=true
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Export the environment variables
export DESTINATION_API
export SYSTEM_MSG
export SYSTEM_OVERRIDE
export AUTOSTYLE
export NOSTREAM
# Build the command to launch Uvicorn
COMMAND="$VENV_DIR/bin/python -m uvicorn BananaPhone:api --port $LOCAL_PORT"
# If WAN is enabled, modify the command
if [ "$WAN_ENABLED" = true ]; then
COMMAND="$COMMAND --host 0.0.0.0"
fi
# If reload is requested, modify the command
if [ "$RELOAD" = true ]; then
COMMAND="$COMMAND --reload"
fi
# If tmux is requested, modify the command
if [ "$USE_TMUX" = true ]; then
COMMAND="tmux new-session -d -s BananaPhone '$COMMAND'"
fi
# Execute the command
eval $COMMAND