diff --git a/README.md b/README.md index 69b70e5..2ed3b3a 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,60 @@ Sistema completo de IA agentica con LLMs locales (Phi + DeepSeek 33B) en Ubuntu - **CPU**: Intel i3-10105 (4 cores) - **RAM**: 16GB DDR4 - **GPU**: NVIDIA RTX 3090 (24GB VRAM) -- **SSD**: 1TB NVMe (Samsung PM991A o similar) - **PSU**: 850W+ - **SO**: Ubuntu 22.04 LTS +## Solución para tool calling con rutas de Windows + +Cuando el LLM intenta ejecutar una herramienta, la respuesta no debe mostrarse como texto plano. Debe ser manejada como un `tool_call` o `function_call` y ejecutada localmente. + +### Regla importante + +Añade esta instrucción al `System Prompt`: + +```text +When outputting Windows file paths in JSON arguments, you must strictly escape all backslashes (for example: C:\\Users\\name\\file.txt). +``` + +### Patrón recomendado + +1. El LLM devuelve una llamada como JSON. +2. Tu cliente detecta `tool_calls` o `function_call`. +3. Tu código ejecuta la función localmente. +4. Se envía de vuelta al LLM el resultado con rol `tool` o `function`. + +### Ejemplo de implementación + +El proyecto incluye un ejemplo funcional en `tool_call_demo.py` que: + +- simula un `tool_call` del modelo, +- valida que la ruta JSON esté escapada correctamente, +- lee el archivo físico en disco, +- devuelve el contenido al modelo para continuar. + +```bash +python tool_call_demo.py +``` + +### Ejemplo de payload válido + +```json +{ + "tool_calls": [ + { + "id": "call_read_001", + "type": "function", + "function": { + "name": "read_file", + "arguments": "{\"path\": \"c:\\\\Workspace\\\\llm-server-setup\\\\README.md\"}" + } + } + ] +} +``` + +> Si el JSON tiene barras invertidas sin escape, el parser falla y el modelo parece "no responder". Usar rutas con `\\` en JSON es obligatorio en Windows. + ## Instalación Rápida ```bash @@ -18,170 +68,16 @@ Sistema completo de IA agentica con LLMs locales (Phi + DeepSeek 33B) en Ubuntu git clone https://github.com/tuuser/llm-server-setup.git cd llm-server-setup -# 2. Instalar (con sudo) -sudo make install +# 2. Instalar OpenClaw sin iniciar el asistente +bash install_openclaw.sh -# 3. Verificar estado -make health-check +# 3. Ejecutar el asistente inicial cuando quieras +openclaw onboard --install-daemon -# 4. Ver monitoreo -make monitor +# También puedes instalar y abrir el asistente en el mismo paso +bash install_openclaw.sh --onboard ``` -## Comandos Disponibles - -```bash -make install # Instalación completa -make install-quick # Sin descargar modelos -make update # Actualizar código -make monitor # Monitoreo en tiempo real -make health-check # Verificar estado -make logs # Ver logs -make status # Estado de servicios -make start/stop/restart # Control de servicios -make backup # Hacer backup -``` - -## Estructura de Directorios - -``` -llm-server-setup/ -├── scripts/ # Scripts de deployment -│ ├── install.sh # Instalación principal -│ ├── update.sh # Actualización -│ ├── monitor.sh # Monitoreo -│ ├── health-check.sh # Verificación -│ └── backup.sh # Backup -├── config/ # Configuración -│ └── server.json # Config del servidor -├── static/ # Web UI -├── workspace/ # Workspace de trabajo -├── logs/ # Archivos de log -├── backups/ # Backups automáticos -├── requirements.txt # Dependencias Python -├── Makefile # Automatización -├── .env # Variables de entorno -└── README.md # Este archivo -``` - -## Servicios - -### Ollama (LLM Runtime) -- **Puerto**: 11434 -- **Modelos**: Phi (2.7B), DeepSeek Coder (33B) -- **Status**: `sudo systemctl status ollama` - -### LLM API (FastAPI) -- **Puerto**: 8000 -- **Health**: `curl http://localhost:8000/health` -- **Status**: `sudo systemctl status llm-api` - -## Modelos Disponibles - -| Modelo | Tamaño | VRAM | Velocidad | Uso | -|--------|--------|------|-----------|-----| -| Phi | 2.7B | 1.6GB | ⚡⚡⚡ | Rápido, simple | -| DeepSeek 33B | 33B | 18GB | ⚡ | Potente, razonamiento | - -## Monitoreo - -```bash -# Monitor en tiempo real -make monitor - -# Ver logs -make logs -make logs-api - -# Health check -make health-check -``` - -## API Endpoints - -```bash -# Health check -curl http://localhost:8000/health - -# Listar modelos -curl http://localhost:8000/models - -# Generar código -curl -X POST http://localhost:8000/code \ - -H "Content-Type: application/json" \ - -d '{"message":"Hola","model":"phi"}' -``` - -## Troubleshooting - -### GPU no se detecta -```bash -# Verificar driver -nvidia-smi - -# Reinstalar GPU drivers -sudo make install-gpu-only -``` - -### Servicios no inician -```bash -# Ver logs detallados -sudo journalctl -u ollama -f -sudo journalctl -u llm-api -f - -# Reiniciar -sudo systemctl restart ollama llm-api -``` - -### Espacio en disco lleno -```bash -# Ver uso -df -h - -# Limpiar -make clean - -# Hacer backup y restaurar -make backup -rm -rf ~/.ollama/models/* -ollama pull phi:latest -``` - -## Seguridad - -- SSH habilitado con key-based auth -- Firewall: Permitir solo puertos necesarios -- Usuarios: Crear usuario `charle` sin permisos sudo -- Backups automáticos en `/backups` - -## Performance - -Con tu hardware (RTX 3090 + i3-10105): - -- **Phi**: ~50 tokens/sec -- **DeepSeek 33B**: ~6-7 tokens/sec - -## Actualización - -```bash -# Pull latest from git -git pull origin main - -# Actualizar dependencias -make update -``` - -## Soporte - -Para errores o dudas: -1. Ver logs: `make logs` -2. Ejecutar health-check: `make health-check` -3. Verificar hardware: `make info` - -## License - -MIT - -## Autor - -Setup para servidor LLM local con hardware específico. \ No newline at end of file +El script está pensado para Ubuntu 22.04/24.04 y WSL2. Usa el instalador oficial +de OpenClaw, que instala Node.js si es necesario. Revisa las instrucciones +oficiales si vas a usar otra distribución o un entorno restringido. diff --git a/install_openclaw.sh b/install_openclaw.sh new file mode 100644 index 0000000..f744528 --- /dev/null +++ b/install_openclaw.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +readonly INSTALLER_URL="https://openclaw.ai/install.sh" +readonly SCRIPT_NAME="$(basename "$0")" + +show_help() { + cat <&2 + show_help >&2 + exit 2 + ;; + esac +done + +if [[ "$(uname -s)" != "Linux" ]]; then + printf 'Error: este script está pensado para Linux/WSL2.\n' >&2 + exit 1 +fi + +if ! command -v curl >/dev/null 2>&1; then + printf 'Error: curl es obligatorio. Instálalo con: sudo apt-get update && sudo apt-get install -y curl\n' >&2 + exit 1 +fi + +installer_file="$(mktemp)" +cleanup() { + rm -f "$installer_file" +} +trap cleanup EXIT + +printf 'Descargando el instalador oficial de OpenClaw...\n' +curl --fail --silent --show-error --location \ + --proto '=https' --tlsv1.2 \ + "$INSTALLER_URL" -o "$installer_file" + +if [[ "$onboard" == true ]]; then + bash "$installer_file" +else + bash "$installer_file" --no-onboard +fi + +printf '\nOpenClaw se ha instalado. Comprueba la instalación con:\n' +printf ' openclaw --version\n' +printf ' openclaw doctor\n' + +if [[ "$onboard" == false ]]; then + printf '\nPara configurar OpenClaw más adelante, ejecuta:\n' + printf ' openclaw onboard --install-daemon\n' +fi \ No newline at end of file