| #!/usr/bin/env python3 | |
| """ | |
| π FANTASYBOT + HERMES-3-LLAMA EN TU BUCKET | |
| Instalador interactivo para AWS/GCP/Azure/Local | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| from pathlib import Path | |
| class Colors: | |
| BLUE = '\033[94m' | |
| GREEN = '\033[92m' | |
| YELLOW = '\033[93m' | |
| RED = '\033[91m' | |
| END = '\033[0m' | |
| def print_header(): | |
| print(f"{Colors.BLUE}") | |
| print("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ") | |
| print("β π FantasyBot + Hermes-3-Llama en tu Bucket β") | |
| print("β (AWS S3 / GCP / Azure / Local) β") | |
| print("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ") | |
| print(f"{Colors.END}") | |
| def choose_provider(): | |
| print(f"\n{Colors.BLUE}Elige tu proveedor:{Colors.END}\n") | |
| providers = { | |
| "1": ("AWS S3 + ECS Fargate", "aws"), | |
| "2": ("Google Cloud Run", "gcp"), | |
| "3": ("Azure Container Instances", "azure"), | |
| "4": ("Local + Ollama (RECOMENDADO)", "local"), | |
| } | |
| for key, (name, _) in providers.items(): | |
| print(f" {key}. {name}") | |
| choice = input("\nElecciΓ³n (1-4): ").strip() | |
| if choice not in providers: | |
| print(f"{Colors.RED}β OpciΓ³n invΓ‘lida{Colors.END}") | |
| sys.exit(1) | |
| return providers[choice][1] | |
| def get_credentials(): | |
| print(f"\n{Colors.YELLOW}Configurando credenciales...{Colors.END}\n") | |
| refresh_token = input("REFRESH_TOKEN (LALIGA): ").strip() | |
| access_token = input("ACCESS_TOKEN (LALIGA): ").strip() | |
| anthropic_key = input("ANTHROPIC_API_KEY (opcional): ").strip() or "" | |
| return { | |
| "refresh_token": refresh_token, | |
| "access_token": access_token, | |
| "anthropic_key": anthropic_key, | |
| } | |
| def setup_aws(creds): | |
| print(f"\n{Colors.YELLOW}[1/6] AWS S3 Setup{Colors.END}") | |
| bucket_name = input("Nombre del bucket S3 (ej: tu-fantasybot-bucket): ").strip() | |
| aws_region = input("RegiΓ³n AWS (ej: us-east-1): ").strip() or "us-east-1" | |
| print(f"\n{Colors.GREEN}Ejecuta estos comandos:{Colors.END}\n") | |
| print(f"{Colors.YELLOW}1. Crear bucket:{Colors.END}") | |
| print(f" aws s3 mb s3://{bucket_name} --region {aws_region}\n") | |
| print(f"{Colors.YELLOW}2. Clonar y configurar:{Colors.END}") | |
| print(f""" git clone https://github.com/jonortega20/fantasybot.git | |
| cd fantasybot | |
| # Crear estructura | |
| mkdir -p deploy/aws\n""") | |
| print(f"{Colors.YELLOW}3. Crear Dockerfile:{Colors.END}") | |
| create_aws_dockerfile() | |
| print(f" β Dockerfile creado\n") | |
| print(f"{Colors.YELLOW}4. Actualizar requirements.txt:{Colors.END}") | |
| print(f""" pip install -r requirements.txt | |
| pip install boto3 transformers torch\n""") | |
| print(f"{Colors.YELLOW}5. Crear config Hermes:{Colors.END}") | |
| create_hermes_config_aws(bucket_name) | |
| print(f" β hermes/config.yaml creado\n") | |
| print(f"{Colors.YELLOW}6. Push a ECR y desplegar:{Colors.END}") | |
| print(f""" docker build -t fantasybot-hermes . | |
| aws ecr get-login-password --region {aws_region} | \\ | |
| docker login --username AWS --password-stdin YOUR_ACCOUNT_ID.dkr.ecr.{aws_region}.amazonaws.com | |
| docker push YOUR_ACCOUNT_ID.dkr.ecr.{aws_region}.amazonaws.com/fantasybot-hermes\n""") | |
| print(f"{Colors.GREEN}β Setup AWS completado{Colors.END}") | |
| def setup_gcp(creds): | |
| print(f"\n{Colors.YELLOW}[1/6] Google Cloud Setup{Colors.END}") | |
| bucket_name = input("Nombre del bucket GCS (ej: tu-fantasybot-bucket): ").strip() | |
| project_id = input("Google Cloud Project ID: ").strip() | |
| print(f"\n{Colors.GREEN}Ejecuta estos comandos:{Colors.END}\n") | |
| print(f"{Colors.YELLOW}1. Crear bucket:{Colors.END}") | |
| print(f" gsutil mb -l us-central1 gs://{bucket_name}/\n") | |
| print(f"{Colors.YELLOW}2. Clonar y configurar:{Colors.END}") | |
| print(f""" git clone https://github.com/jonortega20/fantasybot.git | |
| cd fantasybot\n""") | |
| print(f"{Colors.YELLOW}3. Crear Dockerfile:{Colors.END}") | |
| create_gcp_dockerfile() | |
| print(f" β Dockerfile creado\n") | |
| print(f"{Colors.YELLOW}4. Desplegar en Cloud Run:{Colors.END}") | |
| print(f""" gcloud builds submit --tag gcr.io/{project_id}/fantasybot-hermes | |
| gcloud run deploy fantasybot-hermes \\ | |
| --image gcr.io/{project_id}/fantasybot-hermes \\ | |
| --platform managed \\ | |
| --region us-central1 \\ | |
| --memory 4Gi \\ | |
| --cpu 2 \\ | |
| --set-env-vars REFRESH_TOKEN={creds['refresh_token']},ACCESS_TOKEN={creds['access_token']}\n""") | |
| print(f"{Colors.GREEN}β Setup GCP completado{Colors.END}") | |
| def setup_local(): | |
| print(f"\n{Colors.YELLOW}[1/4] Setup Local + Ollama{Colors.END}") | |
| print(f"\n{Colors.GREEN}OpciΓ³n MΓS FΓCIL y RECOMENDADA:{Colors.END}\n") | |
| print(f"{Colors.YELLOW}Paso 1: Instalar Ollama{Colors.END}") | |
| print(f""" # macOS | |
| brew install ollama | |
| # Linux | |
| curl https://ollama.ai/install.sh | sh | |
| # Windows | |
| Descarga desde https://ollama.ai\n""") | |
| print(f"{Colors.YELLOW}Paso 2: Descargar Hermes-3${Colors.END}") | |
| print(f""" ollama pull hermes-3-llama-3.1-8b | |
| # O versiΓ³n cuantizada (mΓ‘s rΓ‘pida) | |
| ollama pull nous-hermes2-mistral:7b-dpo-q4_K_M\n""") | |
| print(f"{Colors.YELLOW}Paso 3: Clonar fantasybot{Colors.END}") | |
| print(f""" git clone https://github.com/jonortega20/fantasybot.git | |
| cd fantasybot | |
| pip install -r requirements.txt\n""") | |
| print(f"{Colors.YELLOW}Paso 4: Configurar hermes{Colors.END}") | |
| create_hermes_config_local() | |
| print(f" β hermes/config.yaml creado\n") | |
| print(f"{Colors.YELLOW}Paso 5: Correr{Colors.END}") | |
| print(f""" # En otra terminal, inicia Ollama | |
| ollama serve | |
| # En tu terminal | |
| python -m fantasybot watch --hermes\n""") | |
| print(f"{Colors.GREEN}β Setup Local completado{Colors.END}") | |
| def setup_azure(creds): | |
| print(f"\n{Colors.YELLOW}[1/6] Azure Setup{Colors.END}") | |
| storage_name = input("Nombre de la cuenta Storage (ej: fantasybot): ").strip() | |
| resource_group = input("Resource Group: ").strip() | |
| print(f"\n{Colors.GREEN}Ejecuta estos comandos:{Colors.END}\n") | |
| print(f"{Colors.YELLOW}1. Crear Storage Account:{Colors.END}") | |
| print(f""" az storage account create \\ | |
| --name {storage_name} \\ | |
| --resource-group {resource_group} \\ | |
| --location eastus | |
| az storage container create \\ | |
| --account-name {storage_name} \\ | |
| --name fantasybot-bucket\n""") | |
| print(f"{Colors.YELLOW}2. Clonar y configurar:{Colors.END}") | |
| print(f""" git clone https://github.com/jonortega20/fantasybot.git | |
| cd fantasybot\n""") | |
| print(f"{Colors.YELLOW}3. Desplegar en Container Instances:{Colors.END}") | |
| print(f""" az container create \\ | |
| --resource-group {resource_group} \\ | |
| --name fantasybot-hermes \\ | |
| --image fantasybot-hermes:latest \\ | |
| --cpu 2 \\ | |
| --memory 4 \\ | |
| --environment-variables \\ | |
| REFRESH_TOKEN={creds['refresh_token']} \\ | |
| ACCESS_TOKEN={creds['access_token']}\n""") | |
| print(f"{Colors.GREEN}β Setup Azure completado{Colors.END}") | |
| def create_aws_dockerfile(): | |
| dockerfile = '''FROM public.ecr.aws/lambda/python:3.11 | |
| RUN yum install -y git curl | |
| COPY . ${LAMBDA_TASK_ROOT} | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| RUN pip install --no-cache-dir transformers torch ollama | |
| ENV HERMES_MODEL="NousResearch/Hermes-3-Llama-3.1-8B" | |
| CMD [ "app.lambda_handler" ] | |
| ''' | |
| with open("Dockerfile", "w") as f: | |
| f.write(dockerfile) | |
| def create_gcp_dockerfile(): | |
| dockerfile = '''FROM python:3.11-slim | |
| WORKDIR /app | |
| RUN apt-get update && apt-get install -y git curl && rm -rf /var/lib/apt/lists/* | |
| COPY . . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| RUN pip install --no-cache-dir google-cloud-storage | |
| ENV HERMES_MODEL="NousResearch/Hermes-3-Llama-3.1-8B" | |
| CMD ["python", "app.py"] | |
| ''' | |
| with open("Dockerfile", "w") as f: | |
| f.write(dockerfile) | |
| def create_hermes_config_aws(bucket_name): | |
| config = f'''model: | |
| provider: "transformers" | |
| name: "NousResearch/Hermes-3-Llama-3.1-8B" | |
| device: "cuda" | |
| dtype: "float16" | |
| quantize: true | |
| storage: | |
| type: "s3" | |
| bucket: "{bucket_name}" | |
| region: "us-east-1" | |
| prefix: ".state" | |
| laliga: | |
| refresh_token: "${{REFRESH_TOKEN}}" | |
| access_token: "${{ACCESS_TOKEN}}" | |
| ''' | |
| os.makedirs("hermes", exist_ok=True) | |
| with open("hermes/config.yaml", "w") as f: | |
| f.write(config) | |
| def create_hermes_config_local(): | |
| config = '''model: | |
| provider: "ollama" | |
| name: "hermes-3-llama-3.1-8b" | |
| base_url: "http://localhost:11434" | |
| temperature: 0.7 | |
| laliga: | |
| refresh_token: "${REFRESH_TOKEN}" | |
| access_token: "${ACCESS_TOKEN}" | |
| ''' | |
| os.makedirs("hermes", exist_ok=True) | |
| with open("hermes/config.yaml", "w") as f: | |
| f.write(config) | |
| def main(): | |
| print_header() | |
| provider = choose_provider() | |
| creds = get_credentials() | |
| if provider == "aws": | |
| setup_aws(creds) | |
| elif provider == "gcp": | |
| setup_gcp(creds) | |
| elif provider == "azure": | |
| setup_azure(creds) | |
| elif provider == "local": | |
| setup_local() | |
| print(f"\n{Colors.BLUE}{'='*60}{Colors.END}") | |
| print(f"{Colors.GREEN}β Β‘Setup completado!{Colors.END}") | |
| print(f"{Colors.BLUE}{'='*60}{Colors.END}\n") | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 9.64 kB
- Xet hash:
- 0abcd162164c2b427eb1810c22b955a7ba003b4ef8d0338fe037d522da9bfb8c
Β·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.