-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_llm.py
More file actions
executable file
·137 lines (111 loc) · 3.68 KB
/
setup_llm.py
File metadata and controls
executable file
·137 lines (111 loc) · 3.68 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
#!/usr/bin/env python3
"""
Setup script for DocMentor LLM integration.
Run this to install dependencies and download models.
"""
import sys
import logging
from pathlib import Path
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def main():
"""Main setup flow."""
print("=" * 60)
print(" DocMentor LLM Setup")
print(" MacBook M4 Optimized")
print("=" * 60)
print()
# Add core to path
sys.path.insert(0, str(Path(__file__).parent))
from core.llm.model_downloader import ModelDownloader
downloader = ModelDownloader(models_dir="./models")
# Step 1: Install dependencies
print("📦 Step 1: Installing dependencies...")
print("-" * 60)
print("This will install:")
print(" - llama-cpp-python (LLM inference)")
print(" - huggingface-hub (model downloads)")
print()
response = input("Continue? [Y/n]: ").strip().lower()
if response and response != 'y':
print("❌ Setup cancelled")
return
if not downloader.install_dependencies():
print("❌ Failed to install dependencies")
return
print()
# Step 2: Choose model
print("🤖 Step 2: Choose LLM model")
print("-" * 60)
print()
models = downloader.list_available_models()
print("Available models:")
for i, (key, info) in enumerate(models.items(), 1):
print(f"\n{i}. {info['name']}")
print(f" Size: ~{info['size_gb']} GB")
print(f" File: {info['file']}")
print(f" Description: {info['description']}")
print()
print("Recommendation for MacBook M4 16GB: Option 1 (Qwen2.5-7B)")
print()
while True:
choice = input("Choose model [1-3] or 'skip': ").strip()
if choice.lower() == 'skip':
print("⏭️ Skipping model download")
print(" You can download later using: python setup_llm.py")
break
try:
idx = int(choice) - 1
model_keys = list(models.keys())
if 0 <= idx < len(model_keys):
model_key = model_keys[idx]
break
else:
print(f"Please enter 1-{len(models)}")
except ValueError:
print("Please enter a number or 'skip'")
if choice.lower() != 'skip':
print()
print(f"📥 Downloading {models[model_key]['name']}...")
print(f" This may take 10-30 minutes depending on your internet speed")
print()
model_path = downloader.download_model(model_key)
if model_path:
print()
print("✅ Setup complete!")
print()
print(f"Model saved to: {model_path}")
print()
print("Next steps:")
print(" 1. Test the model: python test_llm.py")
print(" 2. Run DocMentor: streamlit run app/Home.py")
else:
print("❌ Model download failed")
print(" You can try again later with: python setup_llm.py")
# Step 3: Show local models
print()
print("📁 Local models:")
print("-" * 60)
local_models = downloader.list_local_models()
if local_models:
for model in local_models:
print(f" ✓ {model['filename']} ({model['size_mb']} MB)")
else:
print(" (none)")
print()
print("=" * 60)
print("Setup finished!")
print("=" * 60)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\n❌ Setup cancelled by user")
sys.exit(1)
except Exception as e:
logger.error(f"Setup failed: {str(e)}", exc_info=True)
sys.exit(1)