# Automatización

### \[Ejemplo 1] LMStudio + N8N - Conexión con una IA Local

{% hint style="info" %}
Este es un ejemplo sencillo de cómo realizar peticiones desde un nodo de n8n hacia una IA ejecutada en local.
{% endhint %}

Si dispones de un equipo con recursos suficientes, puedes ejecutar modelos de IA de forma local y conectarlos directamente con n8n . Esto permite crear y probar workflows integrados con IA sin depender de servicios externos ni incurrir en costes por consumo de tokens y en un entorno de pruebas privado.

n8n: <https://github.com/n8n-io/n8n>

Ejemplo sencillo:

* **n8n:** Se ejecuta en un docker (<http://localhost:5678/>).
* **LMStudio:** Se ejecuta en el host principal.

Dado que el servidor de LMStudio se ejecutará en el host principal, para que el docker pueda realizar peticiones, es necesario sustituir `127.0.0.1` por `host.docker.internal`.

<figure><img src="/files/mU6QqPI3xGrnTpPNq2AP" alt=""><figcaption></figcaption></figure>

Si se desea realizar la conexión desde una VM en vez de desde el host principal, se puede usar el plugin `remote-lmstudio`, que permite exponer el puerto en la red (ej: `http://192.168.1.100:1234/`): <https://lmstudio.ai/lmstudio/remote-lmstudio>

<figure><img src="/files/0NV1rm1ofxKfBL3V0rjj" alt="" width="437"><figcaption></figcaption></figure>

#### LMStudio

Para ello, habrá que cargar y ejecutar el servidor con el modelo deseado en LMStudio.

Este servidor por defecto se encontrará en: <http://127.0.0.1:1234>

<figure><img src="/files/Dj7PAMLkDKrMFnPPyXbO" alt=""><figcaption></figcaption></figure>

Se realiza una petición POST contra el endpoint `/v1/chat/completions`.

#### n8n

Se crea un workflow y se incluye un nodo de HTTP Request.

En dicho nodo se configura:

* Método: `POST`
* URL: [`http://host.docker.internal:1234/v1/chat/completions`](http://host.docker.internal:1234/v1/chat/completions)
* Body Content Type: `JSON`
* Specify Body: `Using JSON`
* JSON:

```json
{
  "model": "google/gemma-3-12b",
  "messages": [
    {
      "role": "user",
      "content": "Tell me a hacker freak joke"
    }
  ]
}
```

<figure><img src="/files/BLOKnGM7ygdPFTbPSskc" alt=""><figcaption></figcaption></figure>

Si en el contenido se quiere incluir un input desde otro nodo, por ejemplo, un chat, se puede:

* Incluir un nodo previo de Chat.
* Editar la petición HTTP y ejecutar el nodo anterior.
* Arrastrar la variable con el contenido al valor de la clave "content" del JSON.

#### Ejemplo de flujo

Si se quiere cargar directamente el ejemplo del flujo:

1. Clona el repo.
2. Importa el `.json` en n8n (opción `Import workflow`).

<https://github.com/xtormin/n8n-pentest-workflows/blob/5f70e5bbf782ac6f0435ffb98e28b674dabec7b3/workflows/local-AI-connection.json>

<figure><img src="/files/T7a4NoB4R4zPZ8eBSTHq" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.xtormin.com/general/automatizacion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
