-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (182 loc) · 6.94 KB
/
Makefile
File metadata and controls
206 lines (182 loc) · 6.94 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Tokligence LocalSQLAgent Makefile
# Simplifies setup and testing for users
.PHONY: help install setup-ollama setup-db start stop test clean quick-start benchmark
# Default target
help:
@echo "╔══════════════════════════════════════════════════════════════╗"
@echo "║ Tokligence LocalSQLAgent ║"
@echo "║ Local Text-to-SQL Intelligent Agent ║"
@echo "║ by Tokligence Organization ║"
@echo "║ https://github.com/tokligence/LocalSQLAgent ║"
@echo "╚══════════════════════════════════════════════════════════════╝"
@echo ""
@echo "Available commands:"
@echo " make venv - Create Python virtual environment"
@echo " make venv-setup - Setup venv with all dependencies"
@echo " make install - Install Python dependencies"
@echo " make setup-ollama - Install Ollama and download models"
@echo " make setup-db - Start all databases with Docker"
@echo " make start - Start everything (Ollama + DBs)"
@echo " make stop - Stop all services"
@echo " make web-ui - Launch interactive Web UI (port 8501)"
@echo " make api-server - Start OpenAI-compatible API (port 8711)"
@echo " make test - Run all tests"
@echo " make quick-start - Run quick start demo"
@echo " make benchmark - Run full benchmark tests"
@echo " make clean - Clean up containers and volumes"
@echo ""
@echo "Quick start:"
@echo " make start && make web-ui"
# Create virtual environment
venv:
@echo "🐍 Creating Python virtual environment..."
python3 -m venv venv
@echo "✅ Virtual environment created!"
@echo ""
@echo "To activate the virtual environment, run:"
@echo " source venv/bin/activate"
# Install Python dependencies
install:
@echo "📦 Installing Python dependencies..."
pip install -r requirements.txt
@echo "✅ Dependencies installed!"
# Setup with virtual environment
venv-setup: venv
@echo "🔧 Setting up virtual environment..."
./venv/bin/pip install --upgrade pip
./venv/bin/pip install -r requirements.txt
@echo "✅ Virtual environment setup complete!"
# Setup Ollama and download models
setup-ollama:
@echo "🤖 Setting up Ollama..."
@if ! command -v ollama &> /dev/null; then \
echo "Installing Ollama..."; \
if [[ "$$(uname)" == "Darwin" ]]; then \
brew install ollama || curl -fsSL https://ollama.com/install.sh | sh; \
else \
curl -fsSL https://ollama.com/install.sh | sh; \
fi; \
else \
echo "Ollama already installed"; \
fi
@echo "📥 Downloading recommended model (Qwen2.5-Coder:7b)..."
ollama pull qwen2.5-coder:7b
@echo "✅ Ollama setup complete!"
# Start databases
setup-db:
@echo "🗄️ Starting databases..."
docker-compose up -d
@echo "⏳ Waiting for databases to be ready..."
@sleep 10
@docker-compose ps
@echo "✅ Databases are running!"
# Start everything
start: setup-ollama setup-db
@echo "🚀 Tokligence LocalSQLAgent is ready!"
@echo ""
@echo "Databases running at:"
@echo " PostgreSQL: localhost:5432"
@echo " MySQL: localhost:3306"
@echo " MongoDB: localhost:27017"
@echo " ClickHouse: localhost:8123"
@echo ""
@echo "Run 'make quick-start' to try it out!"
@echo ""
@echo "───────────────────────────────────────────────────────────────"
@echo " Tokligence LocalSQLAgent | github.com/tokligence"
@echo "───────────────────────────────────────────────────────────────"
# Stop all services
stop:
@echo "🛑 Stopping services..."
docker-compose down
@echo "✅ Services stopped!"
# Run quick start demo
quick-start: install
@echo "🎯 Running quick start demo..."
@if [ -d "venv" ]; then \
./venv/bin/python quick_start.py; \
else \
python quick_start.py; \
fi
# Launch Web UI
web-ui: install
@echo "🌐 Launching Web UI..."
@echo "📍 Opening at http://localhost:8501"
@echo ""
@if [ -d "venv" ]; then \
./venv/bin/pip install streamlit flask flask-cors pymongo 2>/dev/null || true; \
./venv/bin/streamlit run web/app.py --server.address=0.0.0.0 --server.port=8501 --server.headless=true --browser.gatherUsageStats=false; \
else \
pip install streamlit flask flask-cors pymongo 2>/dev/null || true; \
streamlit run web/app.py --server.address=0.0.0.0 --server.port=8501 --server.headless=true --browser.gatherUsageStats=false; \
fi
# Start API Server
api-server: install
@echo "🔌 Starting OpenAI-Compatible API Server..."
@echo "📍 API endpoint: http://localhost:8711"
@echo ""
@if [ -d "venv" ]; then \
./venv/bin/pip install flask flask-cors 2>/dev/null || true; \
./venv/bin/python web/api_server.py; \
else \
pip install flask flask-cors 2>/dev/null || true; \
python web/api_server.py; \
fi
# Run benchmarks
benchmark: install
@echo "📊 Running benchmark tests..."
@echo ""
@echo "1. SQL Benchmark (PostgreSQL, MySQL, ClickHouse):"
python benchmarks/sql_benchmark.py --model ollama:qwen2.5-coder:7b
@echo ""
@echo "2. MongoDB Benchmark:"
python src/mongodb/mongodb_benchmark_v2.py --model ollama:qwen2.5-coder:7b
# Run specific database tests
test-postgres:
python benchmarks/sql_benchmark.py --model ollama:qwen2.5-coder:7b --database postgres
test-mysql:
python benchmarks/sql_benchmark.py --model ollama:qwen2.5-coder:7b --database mysql
test-mongodb:
python src/mongodb/mongodb_benchmark_v2.py --model ollama:qwen2.5-coder:7b
# Run all tests
test: install
@echo "🧪 Running all tests..."
pytest tests/ -v
# Clean up
clean:
@echo "🧹 Cleaning up..."
docker-compose down -v
rm -rf __pycache__ .pytest_cache
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
@echo "✅ Cleanup complete!"
# Development helpers
dev-setup: install setup-ollama setup-db
@echo "🛠️ Development environment ready!"
# Check system requirements
check-requirements:
@echo "🔍 Checking system requirements..."
@echo -n "Python: "
@python --version
@echo -n "Docker: "
@docker --version || echo "Not installed ⚠️"
@echo -n "Docker Compose: "
@docker-compose --version || echo "Not installed ⚠️"
@echo -n "Ollama: "
@ollama --version || echo "Not installed ⚠️"
@echo ""
@echo "Memory available:"
@if [[ "$$(uname)" == "Darwin" ]]; then \
echo "$$(( $$(sysctl -n hw.memsize) / 1024 / 1024 / 1024 )) GB"; \
else \
free -h | grep Mem | awk '{print $$2}'; \
fi
# Docker compose shortcuts
up:
docker-compose up -d
down:
docker-compose down
logs:
docker-compose logs -f
ps:
docker-compose ps