-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
226 lines (169 loc) · 6.81 KB
/
setup.py
File metadata and controls
226 lines (169 loc) · 6.81 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python3
"""
🚀 CrewAI Workshop - Automated Setup Script
Handles virtual environment creation, dependencies, and .env configuration
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
def print_header(text):
"""Print formatted header"""
print("\n" + "=" * 70)
print(f" {text}")
print("=" * 70 + "\n")
def print_success(text):
"""Print success message"""
print(f"[OK] {text}")
def print_error(text):
"""Print error message"""
print(f"[ERROR] {text}")
def print_info(text):
"""Print info message"""
print(f"[INFO] {text}")
def check_python_version():
"""Check if Python version is 3.11+"""
print_header("Checking Python Version")
version = sys.version_info
print(f"Current Python: {version.major}.{version.minor}.{version.micro}")
if version.major < 3 or (version.major == 3 and version.minor < 11):
print_error(f"Python 3.11+ required, but you have {version.major}.{version.minor}")
sys.exit(1)
print_success(f"Python {version.major}.{version.minor} is compatible!")
def create_virtual_env():
"""Create virtual environment"""
print_header("Setting Up Virtual Environment")
venv_path = "crewai_workshop"
if os.path.exists(venv_path):
print_info(f"Virtual environment '{venv_path}' already exists")
response = input("Do you want to recreate it? (y/n): ").strip().lower()
if response == 'y':
print_info(f"Removing existing environment...")
import shutil
shutil.rmtree(venv_path)
else:
print_success("Using existing virtual environment")
return venv_path
print_info(f"Creating virtual environment: {venv_path}")
subprocess.check_call([sys.executable, "-m", "venv", venv_path])
print_success(f"Virtual environment created: {venv_path}")
return venv_path
def get_activation_command(venv_path):
"""Get the activation command for the current OS"""
if platform.system() == "Windows":
return f"{venv_path}\\Scripts\\activate.bat"
else:
return f"source {venv_path}/bin/activate"
def install_dependencies(venv_path):
"""Install required dependencies"""
print_header("Installing Dependencies")
if platform.system() == "Windows":
pip_path = os.path.join(venv_path, "Scripts", "pip.exe")
else:
pip_path = os.path.join(venv_path, "bin", "pip")
print_info("Installing packages from requirements.txt...")
subprocess.check_call([pip_path, "install", "-r", "requirements.txt"])
print_success("All dependencies installed!")
def setup_env_file():
"""Create and configure .env file"""
print_header("Setting Up Environment Variables")
env_path = ".env"
if os.path.exists(env_path):
print_info(f"File '{env_path}' already exists")
response = input("Do you want to reconfigure it? (y/n): ").strip().lower()
if response != 'y':
print_success("Keeping existing .env file")
return
print("\n" + "=" * 70)
print(" GROQ API Key Setup (FREE)")
print("=" * 70)
print("\nGROQ provides free access to powerful AI models!")
print(" * Free tier available")
print(" * Fast inference")
print(" * No credit card required")
print(" * Get key: https://console.groq.com/keys\n")
print_info("\nGetting GROQ API Key:")
print(" 1. Visit: https://console.groq.com/keys")
print(" 2. Sign up (free)")
print(" 3. Create API key")
print(" 4. Copy the key\n")
groq_key = input("Enter your GROQ API Key: ").strip()
if not groq_key:
print_error("GROQ API Key is required!")
sys.exit(1)
env_content = "# CrewAI Workshop - Environment Configuration\n"
env_content += "# Generated by setup.py\n\n"
env_content += f"GROQ_API_KEY={groq_key}\n"
env_content += "\n# Model Configuration\n"
env_content += "GROQ_MODEL=llama-3.1-8b-instant\n"
env_content += "GROQ_TEMPERATURE=1\n"
env_content += "GROQ_MAX_TOKENS=1024\n"
with open(env_path, 'w') as f:
f.write(env_content)
print_success(f"Environment file created: {env_path}")
print_info("IMPORTANT: Never commit .env to version control!")
def verify_setup():
"""Verify the setup is complete"""
print_header("Verifying Setup")
checks = {
".env file": os.path.exists(".env"),
"requirements.txt": os.path.exists("requirements.txt"),
"main.py": os.path.exists("main.py"),
"config.py": os.path.exists("config.py"),
}
all_good = True
for check, result in checks.items():
status = "[OK]" if result else "[ERROR]"
print(f"{status} {check}")
if not result:
all_good = False
return all_good
def print_next_steps(venv_path):
"""Print next steps for the user"""
print_header("Setup Complete!")
print("Next Steps:\n")
if platform.system() == "Windows":
print(f"1. Activate virtual environment:")
print(f" {venv_path}\\Scripts\\activate\n")
else:
print(f"1. Activate virtual environment:")
print(f" source {venv_path}/bin/activate\n")
print("2. Verify your .env file has API keys\n")
print("3. Run the workshop:")
print(" python main.py\n")
print("4. Try the multi-agent example:")
print(" python test3agents.py\n")
print("Documentation:")
print(" * README.md - Project overview")
print(" * Instructions.md - Detailed guide\n")
print("Troubleshooting:")
print(" * Check .env file has correct API keys")
print(" * Ensure virtual environment is activated")
print(" * Run: pip install -r requirements.txt\n")
def main():
"""Main setup flow"""
print("\n")
print("=" * 70)
print(" CrewAI Workshop - Automated Setup".center(70))
print(" Learn Agentic AI with Free Tools".center(70))
print("=" * 70)
try:
check_python_version()
venv_path = create_virtual_env()
install_dependencies(venv_path)
setup_env_file()
if verify_setup():
print_next_steps(venv_path)
print_success("Workshop is ready to use!")
else:
print_error("Some setup steps failed. Please check the errors above.")
sys.exit(1)
except KeyboardInterrupt:
print_error("\n\nSetup cancelled by user")
sys.exit(1)
except Exception as e:
print_error(f"Setup failed: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()