-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch-model.sh
More file actions
executable file
·122 lines (108 loc) · 3.77 KB
/
switch-model.sh
File metadata and controls
executable file
·122 lines (108 loc) · 3.77 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
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
#!/bin/bash
# switch-model.sh - Switch between text2sql models
# Make executable: chmod +x switch-model.sh
# Usage: ./switch-model.sh [arctic|qwen7b|distil]
# switches between SQL models to test models
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
show_usage() {
echo "Usage: ./switch-model.sh [arctic|qwen7b|distil]"
echo ""
echo "Options:"
echo " arctic - Switch to Arctic-Text2SQL (4.7GB) + qwen2.5-coder:7b judge"
echo " qwen7b - Switch to qwen2.5-coder:7b for all tasks (single model)"
echo " distil - Switch to distil-qwen3-4b:latest + qwen2.5-coder:7b judge"
echo ""
echo "Current models in Ollama:"
docker compose exec ollama ollama list | grep -E "arctic|qwen|distil|sqlcoder|phi" || echo " (no matching models found)"
}
if [ $# -eq 0 ]; then
show_usage
exit 1
fi
case "$1" in
"arctic")
cat > .env << 'ENV_CONTENT'
# Arctic Text2SQL + qwen2.5-coder:7b AI response / Judge
TEXT2SQL_MODEL=arctic-text2sql:latest
AI_RESPONSE_MODEL=qwen2.5-coder:7b
JUDGE_MODEL=qwen2.5-coder:7b
MODEL_URL=http://ollama:11434/v1/chat/completions
OLLAMA_MODELS_PATH=/home/cynth/ollama_models_shared
COMPOSE_PROJECT_NAME=offline-ai
ENV_CONTENT
echo -e "${GREEN}✓ Switched to Arctic model (judge: qwen2.5-coder:7b)${NC}"
;;
"qwen7b")
cat > .env << 'ENV_CONTENT'
# qwen2.5-coder:7b as Text2SQL and AI response / Judge (1 model performs all tasks)
TEXT2SQL_MODEL=qwen2.5-coder:7b
AI_RESPONSE_MODEL=qwen2.5-coder:7b
JUDGE_MODEL=qwen2.5-coder:7b
MODEL_URL=http://ollama:11434/v1/chat/completions
OLLAMA_MODELS_PATH=/home/cynth/ollama_models_shared
COMPOSE_PROJECT_NAME=offline-ai
ENV_CONTENT
echo -e "${GREEN}✓ Switched to qwen2.5-coder:7b model (all tasks)${NC}"
;;
"distil")
cat > .env << 'ENV_CONTENT'
# distil-qwen3-4b:latest Text2SQL + qwen2.5-coder:7b AI response / Judge
TEXT2SQL_MODEL=distil-qwen3-4b:latest
AI_RESPONSE_MODEL=qwen2.5-coder:7b
JUDGE_MODEL=qwen2.5-coder:7b
MODEL_URL=http://ollama:11434/v1/chat/completions
OLLAMA_MODELS_PATH=/home/cynth/ollama_models_shared
COMPOSE_PROJECT_NAME=offline-ai
ENV_CONTENT
echo -e "${GREEN}✓ Switched to distil-qwen3-4b:latest model (judge: qwen2.5-coder:7b)${NC}"
;;
*)
echo -e "${YELLOW}Unknown option: $1${NC}"
show_usage
exit 1
;;
esac
# Show new .env content
echo -e "\n${YELLOW}=== New .env file ===${NC}"
cat .env
echo "====================="
# Verify models are pulled (will pull if missing)
echo -e "\n${YELLOW}Checking if models are available...${NC}"
TEXT2SQL_MODEL=$(grep TEXT2SQL_MODEL .env | cut -d '=' -f2)
JUDGE_MODEL=$(grep JUDGE_MODEL .env | cut -d '=' -f2)
# Check if models exist using EXACT names
if ! docker compose exec ollama ollama list | grep -q "$TEXT2SQL_MODEL"; then
echo "Pulling $TEXT2SQL_MODEL (first time only)..."
docker compose exec ollama ollama pull $TEXT2SQL_MODEL
if [ $? -eq 0 ]; then
echo "$TEXT2SQL_MODEL pulled successfully"
else
echo "Failed to pull $TEXT2SQL_MODEL"
exit 1
fi
else
echo "$TEXT2SQL_MODEL already exists"
fi
if ! docker compose exec ollama ollama list | grep -q "$JUDGE_MODEL"; then
echo "Pulling $JUDGE_MODEL (first time only)..."
docker compose exec ollama ollama pull $JUDGE_MODEL
if [ $? -eq 0 ]; then
echo "$JUDGE_MODEL pulled successfully"
else
echo "Failed to pull $JUDGE_MODEL"
exit 1
fi
else
echo "$JUDGE_MODEL already exists"
fi
# Restart just the backend (ollama stays running)
echo -e "\n${YELLOW}Restarting backend container...${NC}"
docker compose up -d backend --no-deps
# Wait a moment and verify
sleep 3
echo -e "\n${YELLOW}=== Recent logs (should show model initialization) ===${NC}"
docker compose logs backend --tail=10 | grep -E "model.*initialized|using model|Model.*:" || echo " (wait a moment for model to load)"
echo -e "\n${GREEN}Done!${NC}"