-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
115 lines (98 loc) · 3.52 KB
/
install.py
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
#!/usr/bin/env python3
import subprocess
import sys
import os
from pathlib import Path
def check_python_version():
"""Check if Python version is 3.8 or higher."""
if sys.version_info < (3, 8):
print("Error: Python 3.8 or higher is required.")
sys.exit(1)
def install_requirements():
"""Install required Python packages."""
requirements = [
"pysqlite3-binary", # For Chrome compatibility
"langchain",
"langchain-community",
"langchain-chroma",
"langchain-ollama",
"chromadb",
"rich", # For console formatting
"PyYAML", # For config file handling
]
print("Installing required packages...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
for package in requirements:
print(f"Installing {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
except subprocess.CalledProcessError as e:
print(f"Error installing packages: {str(e)}")
sys.exit(1)
def create_config():
"""Create default config.yaml if it doesn't exist."""
config_content = """
# Model Configuration
embedding_model: "nomic-embed-text"
llm_model: "llama3.2"
# Database Configuration
chroma_path: "chroma"
default_top_k: 5
# Prompt Template
prompt_template: |
Previous conversation:
{history}
Current context:
--- content ---
{context}
--- content ---
Please answer the following question using the provided context.
If referring to previous conversation, still ground your answer in the current context.
Question: {question}
"""
config_path = Path(__file__).parent / "config.yaml"
if not config_path.exists():
print("Creating default config.yaml...")
try:
with open(config_path, 'w') as f:
f.write(config_content.lstrip())
except Exception as e:
print(f"Error creating config file: {str(e)}")
sys.exit(1)
def check_ollama():
"""Check if Ollama is installed and running."""
print("Checking Ollama installation...")
try:
result = subprocess.run(['which', 'ollama'], capture_output=True, text=True)
if result.returncode != 0:
print("Warning: Ollama is not installed. Please install Ollama from https://ollama.ai")
print("After installing Ollama, run: 'ollama pull llama3.2' to download the default model")
return False
return True
except Exception:
print("Warning: Could not check Ollama installation")
return False
def main():
"""Main installation function."""
print("Starting installation...")
# Check Python version
check_python_version()
# Install required packages
install_requirements()
# Create config file
create_config()
# Check Ollama installation
check_ollama()
print("\nInstallation completed successfully!")
print("\nTo use the RAG CLI tool:")
print("1. Make sure Ollama is running ('ollama serve' in a separate terminal)")
print("2. Pull the required models:")
print(" - ollama pull llama3.2")
print(" - ollama pull nomic-embed-text")
print("3. Populate database:")
print(" - Populate database: python populate_database.py --data-path=/your/data/path")
print("4. Run the tool:")
print(" - Basic usage: python ask.py 'your question'")
print(" - Interactive mode: python ask.py --interactive")
if __name__ == "__main__":
main()