Construcción de un entorno ia

PHOTO EMBED

Wed Sep 16 2026 03:29:47 GMT+0000 (Coordinated Universal Time)

Saved by @jrg_300i

#!/data/data/com.termux/files/usr/bin/bash
# ai.sh — pregunta a modelos gratis de OpenRouter
# Uso: bash ai.sh tu pregunta aquí
# Puedes forzar un modelo: MODEL="slug:free" bash ai.sh pregunta

API="https://openrouter.ai/api/v1/chat/completions"
KEY_FILE="$HOME/.openrouter_key"

if [ ! -f "$KEY_FILE" ]; then
    echo "Error: falta el archivo $KEY_FILE"
    exit 1
fi
KEY=$(cat "$KEY_FILE")

PREGUNTA="$*"
if [ -z "$PREGUNTA" ]; then
    echo "Uso: bash ai.sh tu pregunta aquí"
    exit 1
fi

# Si no se eligió modelo, buscar uno gratis disponible ahora mismo
if [ -z "$MODEL" ]; then
    # Preferidos por calidad, en orden
    PREFERIDOS=(
        "meta-llama/llama-3.3-70b-instruct:free"
        "google/gemma-3-27b-it:free"
        "mistralai/mistral-small-3.1-24b-instruct:free"
        "qwen/qwen-2.5-72b-instruct:free"
        "deepseek/deepseek-r1-0528:free"
    )
    DISPONIBLES=$(curl -s https://openrouter.ai/api/v1/models | jq -r '.data[].id' | grep ':fre>

    for m in "${PREFERIDOS[@]}"; do
        if grep -qxF "$m" <<< "$DISPONIBLES"; then
            MODEL="$m"
            break
        fi
    done
    # Si ninguno de los preferidos está, usar el primero disponible
    [ -z "$MODEL" ] && MODEL=$(grep ':free' <<< "$DISPONIBLES" | head -n1)
fi

if [ -z "$MODEL" ]; then
    echo "❌ No encontré modelos gratis en este momento"
    exit 1
content_copyCOPY