-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.sh
More file actions
executable file
·69 lines (60 loc) · 1.71 KB
/
server.sh
File metadata and controls
executable file
·69 lines (60 loc) · 1.71 KB
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
# API Server - Start OpenAI-compatible API server
# Usage: ./server.sh
# Runs at http://127.0.0.1:8080/v1 (configure in config.sh)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/config.sh"
# Check if llama.cpp is built
if [ ! -f "${LLAMA_CPP_DIR}/build/bin/llama-server" ]; then
echo "ERROR: llama.cpp not built. Run ./setup.sh first."
exit 1
fi
# Check if model exists
if [ ! -f "$MODEL_PATH" ]; then
echo "ERROR: Model not found: $MODEL_PATH"
echo ""
echo "Download it first:"
echo " ./download-model.sh $ACTIVE_MODEL"
exit 1
fi
echo "=== Starting OpenAI-Compatible API Server ==="
echo "Model: $ACTIVE_MODEL"
echo "File: $MODEL_FILE"
echo "Template: $CHAT_TEMPLATE"
echo "Address: http://${SERVER_HOST}:${SERVER_PORT}"
echo "Threads: $N_THREADS"
echo "Context: $CONTEXT_SIZE"
echo "Temp: $TEMPERATURE"
echo ""
echo "Configure OpenCode/Droid to use:"
echo " API Base URL: http://${SERVER_HOST}:${SERVER_PORT}/v1"
echo ""
# Start server in background
"${LLAMA_CPP_DIR}/build/bin/llama-server" \
--model "$MODEL_PATH" \
--host "$SERVER_HOST" \
--port "$SERVER_PORT" \
--ctx-size "$CONTEXT_SIZE" \
--threads "$N_THREADS" \
--temp "$TEMPERATURE" \
--top-p "$TOP_P" \
--repeat-penalty "$REPEAT_PENALTY" \
--chat-template "$CHAT_TEMPLATE" \
--log-disable &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
echo ""
echo "Press Ctrl+C to stop the server"
echo ""
# Set up trap to handle Ctrl+C
cleanup() {
echo ""
echo "Stopping server..."
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
echo "Server stopped."
exit 0
}
trap cleanup SIGINT
# Wait for server process
wait $SERVER_PID