llmctl-cli 0.4.1__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/PKG-INFO +16 -11
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/README.md +15 -10
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/pyproject.toml +1 -1
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/pyproject.toml.orig +1 -1
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/__init__.py +1 -1
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/cli.py +62 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/completions.py +3 -0
- llmctl_cli-0.5.0/src/llmctl/importer.py +406 -0
- llmctl_cli-0.5.0/src/llmctl/top.py +138 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/LICENSE +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/__main__.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/bench.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/cache.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/chat.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/config.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/doctor.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/hardware.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/hf.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/http_client.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/presets.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/server_installer.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/__init__.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/base.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/launchd.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/process.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/remote.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/service/systemd.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/skills.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/tester.py +0 -0
- {llmctl_cli-0.4.1 → llmctl_cli-0.5.0}/src/llmctl/ui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: llmctl-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Cross-platform CLI to manage llama-server router presets, Hugging Face GGUF models, hardware probes, skills, and local/remote services.
|
|
5
5
|
Keywords: llm,llama.cpp,llama-server,gguf,huggingface,cli
|
|
6
6
|
Author: Ana Alonso
|
|
@@ -27,24 +27,26 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
|
|
28
28
|
# llmctl
|
|
29
29
|
|
|
30
|
-
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-linux.yml)
|
|
31
|
+
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-macos.yml)
|
|
32
|
+
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-windows.yml)
|
|
31
33
|
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/release.yml)
|
|
32
34
|
[](https://pypi.org/project/llmctl-cli/)
|
|
33
35
|
[](https://www.python.org/)
|
|
34
36
|
[](pyproject.toml)
|
|
35
37
|
[](LICENSE)
|
|
36
38
|
|
|
37
|
-
CLI multiplataforma (**Linux, macOS y Windows**) en Python puro (sin dependencias externas en runtime) para gestionar presets del router de `llama-server`, modelos GGUF de Hugging Face o locales, hardware (NVIDIA, Apple Silicon/Metal, AMD, Vulkan/iGPU y CPU), chat/benchmarks en terminal, perfiles locales/remotos con API key, binarios oficiales de `llama.cpp` y skills centralizadas (`SKILL.md`).
|
|
39
|
+
CLI multiplataforma (**Linux, macOS y Windows**) en Python puro (sin dependencias externas en runtime) para gestionar presets del router de `llama-server`, modelos GGUF de Hugging Face, Ollama o carpetas locales, hardware (NVIDIA, Apple Silicon/Metal, AMD, Vulkan/iGPU y CPU), panel `top` en vivo, chat/benchmarks en terminal, perfiles locales/remotos con API key, binarios oficiales de `llama.cpp` y skills centralizadas (`SKILL.md`).
|
|
38
40
|
|
|
39
41
|
## Estado por plataforma y empaquetado (CI en vivo)
|
|
40
42
|
|
|
41
43
|
| Objetivo | Estado en `main` | Backend / Artefacto |
|
|
42
44
|
| :--- | :---: | :--- |
|
|
43
|
-
| **Linux** (Ubuntu, Python 3.11–3.13 + lint + `ty`) | [ | [ | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-linux.yml) | `systemd --user` / `process` |
|
|
46
|
+
| **macOS** (Python 3.11–3.13) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-macos.yml) | `launchd` + Apple Silicon Metal |
|
|
47
|
+
| **Windows** (Python 3.11–3.13) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-windows.yml) | `process` + NVIDIA/Vulkan/CPU |
|
|
48
|
+
| **Paquete `.deb`** (Debian / Ubuntu) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-deb.yml) | `llmctl_<ver>_all.deb` |
|
|
49
|
+
| **Paquete `.rpm`** (Fedora / RHEL) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-rpm.yml) | `llmctl-<ver>-1.*.noarch.rpm` |
|
|
48
50
|
|
|
49
51
|
## Instalación en 1 comando (sin descargar ni clonar el repo)
|
|
50
52
|
|
|
@@ -68,8 +70,8 @@ irm https://raw.githubusercontent.com/Ana-Alonso/llmctl/main/install.ps1 | iex
|
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
### Paquetes nativos (desde [GitHub Releases](https://github.com/Ana-Alonso/llmctl/releases))
|
|
71
|
-
- **Fedora / RHEL (`.rpm`):** `sudo dnf install ./llmctl-0.
|
|
72
|
-
- **Debian / Ubuntu (`.deb`):** `sudo apt install ./llmctl_0.
|
|
73
|
+
- **Fedora / RHEL (`.rpm`):** `sudo dnf install ./llmctl-0.5.0-1.*.noarch.rpm`
|
|
74
|
+
- **Debian / Ubuntu (`.deb`):** `sudo apt install ./llmctl_0.5.0_all.deb`
|
|
73
75
|
- **macOS / Linux (Homebrew):** fórmula `llmctl.rb` adjunta en cada release.
|
|
74
76
|
- **Windows (Scoop):** manifiesto `llmctl.json` adjunto en cada release.
|
|
75
77
|
|
|
@@ -111,13 +113,16 @@ llmctl status
|
|
|
111
113
|
|
|
112
114
|
- **Modelos y presets:**
|
|
113
115
|
- `llmctl add [repo|archivo.gguf]` — Añade un modelo de Hugging Face o un `.gguf` local (`-i` búsqueda en vivo con auto-`mmproj` y optimización CPU-only, `-n <alias>`, `--file`, `--mmproj`, `--auto-mmproj`, `--mmproj-url`, `--cpu-optimize`, `--cpu-moe`, `--n-cpu-moe <N>`, `--no-restart`)
|
|
116
|
+
- `llmctl import ollama` — Importa a `models.ini` los modelos GGUF (y proyectores de visión) ya descargados por **Ollama** sin duplicar espacio en disco (`--all`, `--dir`, `--cpu-optimize`)
|
|
117
|
+
- `llmctl scan <carpeta>` — Escanea recursivamente cualquier carpeta (LM Studio, Jan, descargas) en busca de `.gguf` y los registra con `--add`
|
|
114
118
|
- `llmctl set <alias> clave=valor [...] [--unset clave]` — Edita o elimina parámetros de un preset en `models.ini` de forma atómica (p. ej. `llmctl set qwen ctx-size=16384 threads=8`)
|
|
115
119
|
- `llmctl rm [alias]` — Elimina un preset (`-i` interactivo, `--purge` borra caché solo si ningún otro preset comparte el repo)
|
|
116
120
|
- `llmctl ls` — Lista presets (HF y locales) y tamaño de caché (`--json`, `--names-only`)
|
|
117
121
|
- `llmctl ps` — Lista modelos cargados y disponibles en el router (`--json`)
|
|
118
122
|
- `llmctl pull <alias>` — Pre-descarga y carga un modelo vía `llama-server` con indicador de progreso en vivo
|
|
119
123
|
- `llmctl clean` — Detecta y borra carpetas huérfanas en caché (`--dry-run`, `--yes`)
|
|
120
|
-
- **
|
|
124
|
+
- **Monitor, chat, benchmark y diagnóstico:**
|
|
125
|
+
- `llmctl top` — Panel en vivo de VRAM/Metal/Vulkan, RAM, CPU, estado del servicio y modelos cargados (`-n 1.5`, `--once`, `--json`)
|
|
121
126
|
- `llmctl chat <alias> [prompt...]` — Chat interactivo o *one-shot* con streaming SSE y soporte de pipes (`git diff | llmctl chat qwen "revisa este diff"`)
|
|
122
127
|
- `llmctl bench <alias1> [alias2 ...]` — Compara TTFT, `prompt tok/s`, `gen tok/s` y VRAM entre modelos (`--runs N`, `--max-tokens N`, `--json`)
|
|
123
128
|
- `llmctl test <alias>` — Suite auto-detectada (`--text`, `--vision`, `--tools`, `--embed`, `--fim`, `--all`, `--json`)
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
# llmctl
|
|
2
2
|
|
|
3
|
-
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-linux.yml)
|
|
4
|
+
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-macos.yml)
|
|
5
|
+
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-windows.yml)
|
|
4
6
|
[](https://github.com/Ana-Alonso/llmctl/actions/workflows/release.yml)
|
|
5
7
|
[](https://pypi.org/project/llmctl-cli/)
|
|
6
8
|
[](https://www.python.org/)
|
|
7
9
|
[](pyproject.toml)
|
|
8
10
|
[](LICENSE)
|
|
9
11
|
|
|
10
|
-
CLI multiplataforma (**Linux, macOS y Windows**) en Python puro (sin dependencias externas en runtime) para gestionar presets del router de `llama-server`, modelos GGUF de Hugging Face o locales, hardware (NVIDIA, Apple Silicon/Metal, AMD, Vulkan/iGPU y CPU), chat/benchmarks en terminal, perfiles locales/remotos con API key, binarios oficiales de `llama.cpp` y skills centralizadas (`SKILL.md`).
|
|
12
|
+
CLI multiplataforma (**Linux, macOS y Windows**) en Python puro (sin dependencias externas en runtime) para gestionar presets del router de `llama-server`, modelos GGUF de Hugging Face, Ollama o carpetas locales, hardware (NVIDIA, Apple Silicon/Metal, AMD, Vulkan/iGPU y CPU), panel `top` en vivo, chat/benchmarks en terminal, perfiles locales/remotos con API key, binarios oficiales de `llama.cpp` y skills centralizadas (`SKILL.md`).
|
|
11
13
|
|
|
12
14
|
## Estado por plataforma y empaquetado (CI en vivo)
|
|
13
15
|
|
|
14
16
|
| Objetivo | Estado en `main` | Backend / Artefacto |
|
|
15
17
|
| :--- | :---: | :--- |
|
|
16
|
-
| **Linux** (Ubuntu, Python 3.11–3.13 + lint + `ty`) | [ | [ | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-linux.yml) | `systemd --user` / `process` |
|
|
19
|
+
| **macOS** (Python 3.11–3.13) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-macos.yml) | `launchd` + Apple Silicon Metal |
|
|
20
|
+
| **Windows** (Python 3.11–3.13) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-windows.yml) | `process` + NVIDIA/Vulkan/CPU |
|
|
21
|
+
| **Paquete `.deb`** (Debian / Ubuntu) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-deb.yml) | `llmctl_<ver>_all.deb` |
|
|
22
|
+
| **Paquete `.rpm`** (Fedora / RHEL) | [](https://github.com/Ana-Alonso/llmctl/actions/workflows/ci-rpm.yml) | `llmctl-<ver>-1.*.noarch.rpm` |
|
|
21
23
|
|
|
22
24
|
## Instalación en 1 comando (sin descargar ni clonar el repo)
|
|
23
25
|
|
|
@@ -41,8 +43,8 @@ irm https://raw.githubusercontent.com/Ana-Alonso/llmctl/main/install.ps1 | iex
|
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
### Paquetes nativos (desde [GitHub Releases](https://github.com/Ana-Alonso/llmctl/releases))
|
|
44
|
-
- **Fedora / RHEL (`.rpm`):** `sudo dnf install ./llmctl-0.
|
|
45
|
-
- **Debian / Ubuntu (`.deb`):** `sudo apt install ./llmctl_0.
|
|
46
|
+
- **Fedora / RHEL (`.rpm`):** `sudo dnf install ./llmctl-0.5.0-1.*.noarch.rpm`
|
|
47
|
+
- **Debian / Ubuntu (`.deb`):** `sudo apt install ./llmctl_0.5.0_all.deb`
|
|
46
48
|
- **macOS / Linux (Homebrew):** fórmula `llmctl.rb` adjunta en cada release.
|
|
47
49
|
- **Windows (Scoop):** manifiesto `llmctl.json` adjunto en cada release.
|
|
48
50
|
|
|
@@ -84,13 +86,16 @@ llmctl status
|
|
|
84
86
|
|
|
85
87
|
- **Modelos y presets:**
|
|
86
88
|
- `llmctl add [repo|archivo.gguf]` — Añade un modelo de Hugging Face o un `.gguf` local (`-i` búsqueda en vivo con auto-`mmproj` y optimización CPU-only, `-n <alias>`, `--file`, `--mmproj`, `--auto-mmproj`, `--mmproj-url`, `--cpu-optimize`, `--cpu-moe`, `--n-cpu-moe <N>`, `--no-restart`)
|
|
89
|
+
- `llmctl import ollama` — Importa a `models.ini` los modelos GGUF (y proyectores de visión) ya descargados por **Ollama** sin duplicar espacio en disco (`--all`, `--dir`, `--cpu-optimize`)
|
|
90
|
+
- `llmctl scan <carpeta>` — Escanea recursivamente cualquier carpeta (LM Studio, Jan, descargas) en busca de `.gguf` y los registra con `--add`
|
|
87
91
|
- `llmctl set <alias> clave=valor [...] [--unset clave]` — Edita o elimina parámetros de un preset en `models.ini` de forma atómica (p. ej. `llmctl set qwen ctx-size=16384 threads=8`)
|
|
88
92
|
- `llmctl rm [alias]` — Elimina un preset (`-i` interactivo, `--purge` borra caché solo si ningún otro preset comparte el repo)
|
|
89
93
|
- `llmctl ls` — Lista presets (HF y locales) y tamaño de caché (`--json`, `--names-only`)
|
|
90
94
|
- `llmctl ps` — Lista modelos cargados y disponibles en el router (`--json`)
|
|
91
95
|
- `llmctl pull <alias>` — Pre-descarga y carga un modelo vía `llama-server` con indicador de progreso en vivo
|
|
92
96
|
- `llmctl clean` — Detecta y borra carpetas huérfanas en caché (`--dry-run`, `--yes`)
|
|
93
|
-
- **
|
|
97
|
+
- **Monitor, chat, benchmark y diagnóstico:**
|
|
98
|
+
- `llmctl top` — Panel en vivo de VRAM/Metal/Vulkan, RAM, CPU, estado del servicio y modelos cargados (`-n 1.5`, `--once`, `--json`)
|
|
94
99
|
- `llmctl chat <alias> [prompt...]` — Chat interactivo o *one-shot* con streaming SSE y soporte de pipes (`git diff | llmctl chat qwen "revisa este diff"`)
|
|
95
100
|
- `llmctl bench <alias1> [alias2 ...]` — Compara TTFT, `prompt tok/s`, `gen tok/s` y VRAM entre modelos (`--runs N`, `--max-tokens N`, `--json`)
|
|
96
101
|
- `llmctl test <alias>` — Suite auto-detectada (`--text`, `--vision`, `--tools`, `--embed`, `--fim`, `--all`, `--json`)
|
|
@@ -54,7 +54,7 @@ addopts = ["-ra"]
|
|
|
54
54
|
|
|
55
55
|
[project]
|
|
56
56
|
name = "llmctl-cli"
|
|
57
|
-
version = "0.
|
|
57
|
+
version = "0.5.0"
|
|
58
58
|
description = "Cross-platform CLI to manage llama-server router presets, Hugging Face GGUF models, hardware probes, skills, and local/remote services."
|
|
59
59
|
readme = "README.md"
|
|
60
60
|
license = "MIT"
|
|
@@ -7,7 +7,7 @@ module-name = "llmctl"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "llmctl-cli"
|
|
10
|
-
version = "0.
|
|
10
|
+
version = "0.5.0"
|
|
11
11
|
description = "Cross-platform CLI to manage llama-server router presets, Hugging Face GGUF models, hardware probes, skills, and local/remote services."
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
license = "MIT"
|
|
@@ -34,12 +34,14 @@ from llmctl.doctor import run_doctor
|
|
|
34
34
|
from llmctl.hardware import detect_hardware
|
|
35
35
|
from llmctl.hf import add_local_model_preset, add_model_preset, run_interactive_add
|
|
36
36
|
from llmctl.http_client import HttpError, request_json
|
|
37
|
+
from llmctl.importer import run_import_ollama, run_scan_directory
|
|
37
38
|
from llmctl.presets import ensure_ini, list_presets, remove_preset, set_preset_options
|
|
38
39
|
from llmctl.server_installer import install_llama_server, server_install_info
|
|
39
40
|
from llmctl.service import select_backend
|
|
40
41
|
from llmctl.service.base import list_router_models
|
|
41
42
|
from llmctl.skills import add_skill, import_local_skills, list_skills, remove_skill, run_skill
|
|
42
43
|
from llmctl.tester import run_test_suite
|
|
44
|
+
from llmctl.top import run_top
|
|
43
45
|
from llmctl.ui import Console, open_in_editor
|
|
44
46
|
|
|
45
47
|
|
|
@@ -245,6 +247,39 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
245
247
|
"gpu", aliases=["vram"], parents=[shared], help="Ver uso actual de VRAM/Metal y RAM"
|
|
246
248
|
)
|
|
247
249
|
|
|
250
|
+
# top
|
|
251
|
+
p_top = sub.add_parser(
|
|
252
|
+
"top", parents=[shared], help="Panel en vivo de VRAM, RAM, CPU y modelos cargados"
|
|
253
|
+
)
|
|
254
|
+
p_top.add_argument(
|
|
255
|
+
"-n", "--interval", type=float, default=1.5, help="Intervalo de refresco en segundos"
|
|
256
|
+
)
|
|
257
|
+
p_top.add_argument("--once", action="store_true", help="Mostrar una sola instantánea y salir")
|
|
258
|
+
|
|
259
|
+
# import
|
|
260
|
+
p_imp = sub.add_parser(
|
|
261
|
+
"import", parents=[shared], help="Importar modelos GGUF sin copiar archivos (ej: ollama)"
|
|
262
|
+
)
|
|
263
|
+
imp_sub = p_imp.add_subparsers(dest="import_src", metavar="<fuente>")
|
|
264
|
+
p_imp_ol = imp_sub.add_parser(
|
|
265
|
+
"ollama", parents=[shared], help="Importar modelos GGUF descargados por Ollama"
|
|
266
|
+
)
|
|
267
|
+
p_imp_ol.add_argument("--dir", dest="ollama_dir", help="Ruta alternativa a ~/.ollama/models")
|
|
268
|
+
p_imp_ol.add_argument("--all", dest="import_all", action="store_true", help="Sin confirmar")
|
|
269
|
+
p_imp_ol.add_argument("--cpu-optimize", action="store_true", help="Añadir threads y ctx-size")
|
|
270
|
+
p_imp_ol.add_argument("--no-restart", action="store_true", help="No reiniciar el router")
|
|
271
|
+
|
|
272
|
+
# scan
|
|
273
|
+
p_scan = sub.add_parser(
|
|
274
|
+
"scan", parents=[shared], help="Escanear una carpeta local buscando modelos .gguf"
|
|
275
|
+
)
|
|
276
|
+
p_scan.add_argument("directory", help="Directorio local a escanear recursivamente")
|
|
277
|
+
p_scan.add_argument(
|
|
278
|
+
"--add", dest="register", action="store_true", help="Registrar en models.ini"
|
|
279
|
+
)
|
|
280
|
+
p_scan.add_argument("--cpu-optimize", action="store_true", help="Añadir threads y ctx-size")
|
|
281
|
+
p_scan.add_argument("--no-restart", action="store_true", help="No reiniciar el router")
|
|
282
|
+
|
|
248
283
|
# doctor
|
|
249
284
|
sub.add_parser(
|
|
250
285
|
"doctor", parents=[shared], help="Comprobar dependencias, hardware, rutas y servicio"
|
|
@@ -1210,6 +1245,33 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
1210
1245
|
if cmd in {"gpu", "vram"}:
|
|
1211
1246
|
return _cmd_gpu(config, console)
|
|
1212
1247
|
|
|
1248
|
+
if cmd == "top":
|
|
1249
|
+
return run_top(config, console, interval=args.interval, once=args.once)
|
|
1250
|
+
|
|
1251
|
+
if cmd == "import":
|
|
1252
|
+
if args.import_src == "ollama":
|
|
1253
|
+
ol_dir = Path(args.ollama_dir).expanduser() if args.ollama_dir else None
|
|
1254
|
+
return run_import_ollama(
|
|
1255
|
+
config,
|
|
1256
|
+
console,
|
|
1257
|
+
ollama_dir=ol_dir,
|
|
1258
|
+
import_all=args.import_all,
|
|
1259
|
+
cpu_optimize=args.cpu_optimize,
|
|
1260
|
+
no_restart=args.no_restart,
|
|
1261
|
+
)
|
|
1262
|
+
console.line("Uso: llmctl import ollama [--dir <ruta>] [--all] [--cpu-optimize]")
|
|
1263
|
+
return 0
|
|
1264
|
+
|
|
1265
|
+
if cmd == "scan":
|
|
1266
|
+
return run_scan_directory(
|
|
1267
|
+
Path(args.directory),
|
|
1268
|
+
config,
|
|
1269
|
+
console,
|
|
1270
|
+
register=args.register,
|
|
1271
|
+
cpu_optimize=args.cpu_optimize,
|
|
1272
|
+
no_restart=args.no_restart,
|
|
1273
|
+
)
|
|
1274
|
+
|
|
1213
1275
|
if cmd == "doctor":
|
|
1214
1276
|
return run_doctor(config, console)
|
|
1215
1277
|
|
|
@@ -14,6 +14,9 @@ SUBCOMMANDS: list[tuple[str, str]] = [
|
|
|
14
14
|
("bench", "Comparar rendimiento (TTFT y tok/s) entre modelos"),
|
|
15
15
|
("test", "Probar capacidades y velocidad de un modelo"),
|
|
16
16
|
("gpu", "Mostrar uso de VRAM/Metal/Vulkan, CPU y RAM"),
|
|
17
|
+
("top", "Panel en vivo de VRAM, RAM, CPU y modelos cargados"),
|
|
18
|
+
("import", "Importar modelos GGUF sin duplicar espacio (ej: ollama)"),
|
|
19
|
+
("scan", "Escanear una carpeta local buscando modelos .gguf"),
|
|
17
20
|
("doctor", "Comprobar dependencias, hardware, perfil y servicio"),
|
|
18
21
|
("free", "Descargar modelo activo de la VRAM"),
|
|
19
22
|
("on", "Iniciar llama-server"),
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"""Zero-copy importers for Ollama models and local GGUF directories (`import` / `scan`)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from dataclasses import asdict, dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from llmctl.cache import format_bytes
|
|
12
|
+
from llmctl.config import AppConfig
|
|
13
|
+
from llmctl.hardware import (
|
|
14
|
+
detect_hardware,
|
|
15
|
+
recommended_cpu_ctx_size,
|
|
16
|
+
recommended_cpu_threads,
|
|
17
|
+
)
|
|
18
|
+
from llmctl.hf import default_alias_for_local_file, pick_best_mmproj
|
|
19
|
+
from llmctl.presets import add_preset, get_preset
|
|
20
|
+
from llmctl.service import select_backend
|
|
21
|
+
from llmctl.ui import Console
|
|
22
|
+
|
|
23
|
+
GIB = 1024**3
|
|
24
|
+
OLLAMA_MODEL_MEDIA_TYPE = "application/vnd.ollama.image.model"
|
|
25
|
+
OLLAMA_PROJECTOR_MEDIA_TYPE = "application/vnd.ollama.image.projector"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class DiscoveredModel:
|
|
30
|
+
"""A GGUF model discovered on disk (from Ollama blobs or a local folder)."""
|
|
31
|
+
|
|
32
|
+
alias: str
|
|
33
|
+
source: str
|
|
34
|
+
model_path: Path
|
|
35
|
+
size_bytes: int
|
|
36
|
+
mmproj_path: Path | None = None
|
|
37
|
+
fit_tag: str = ""
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def size_gb(self) -> float:
|
|
41
|
+
return self.size_bytes / GIB
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict[str, object]:
|
|
44
|
+
data = asdict(self)
|
|
45
|
+
data["model_path"] = str(self.model_path)
|
|
46
|
+
data["mmproj_path"] = str(self.mmproj_path) if self.mmproj_path else None
|
|
47
|
+
data["size_gb"] = round(self.size_gb, 3)
|
|
48
|
+
return data
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _is_gguf_file(path: Path) -> bool:
|
|
52
|
+
if not path.is_file():
|
|
53
|
+
return False
|
|
54
|
+
try:
|
|
55
|
+
with path.open("rb") as fh:
|
|
56
|
+
return fh.read(4) == b"GGUF"
|
|
57
|
+
except OSError:
|
|
58
|
+
return False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _fit_tag_for_size(size_gb: float, vram_safe_gb: float) -> str:
|
|
62
|
+
if vram_safe_gb > 0 and size_gb <= vram_safe_gb:
|
|
63
|
+
return "100% GPU"
|
|
64
|
+
if vram_safe_gb > 0:
|
|
65
|
+
return "GPU + RAM"
|
|
66
|
+
return "CPU / RAM"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def resolve_ollama_models_dir(
|
|
70
|
+
*,
|
|
71
|
+
env: Mapping[str, str] | None = None,
|
|
72
|
+
home: Path | None = None,
|
|
73
|
+
) -> Path | None:
|
|
74
|
+
"""Locate Ollama's models directory across Linux, macOS, and Windows."""
|
|
75
|
+
environ = os.environ if env is None else env
|
|
76
|
+
user_home = Path.home() if home is None else home
|
|
77
|
+
|
|
78
|
+
candidates: list[Path] = []
|
|
79
|
+
override = environ.get("OLLAMA_MODELS", "").strip()
|
|
80
|
+
if override:
|
|
81
|
+
candidates.append(Path(override).expanduser())
|
|
82
|
+
candidates.extend(
|
|
83
|
+
[
|
|
84
|
+
user_home / ".ollama" / "models",
|
|
85
|
+
Path("/usr/share/ollama/.ollama/models"),
|
|
86
|
+
Path("/var/lib/ollama/.ollama/models"),
|
|
87
|
+
]
|
|
88
|
+
)
|
|
89
|
+
for cand in candidates:
|
|
90
|
+
if (cand / "manifests").is_dir() and (cand / "blobs").is_dir():
|
|
91
|
+
return cand
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _digest_to_blob_path(blobs_dir: Path, digest: str) -> Path:
|
|
96
|
+
filename = digest.strip().replace(":", "-")
|
|
97
|
+
return blobs_dir / filename
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def discover_ollama_models(
|
|
101
|
+
ollama_dir: Path,
|
|
102
|
+
*,
|
|
103
|
+
vram_safe_gb: float = 0.0,
|
|
104
|
+
) -> list[DiscoveredModel]:
|
|
105
|
+
"""Parse Ollama manifests and resolve underlying GGUF model & projector blobs."""
|
|
106
|
+
manifests_dir = ollama_dir / "manifests"
|
|
107
|
+
blobs_dir = ollama_dir / "blobs"
|
|
108
|
+
if not manifests_dir.is_dir() or not blobs_dir.is_dir():
|
|
109
|
+
return []
|
|
110
|
+
|
|
111
|
+
found: list[DiscoveredModel] = []
|
|
112
|
+
seen_aliases: set[str] = set()
|
|
113
|
+
|
|
114
|
+
for root, _, files in os.walk(manifests_dir):
|
|
115
|
+
for tag_file in sorted(files):
|
|
116
|
+
manifest_path = Path(root) / tag_file
|
|
117
|
+
try:
|
|
118
|
+
data = json.loads(manifest_path.read_text(encoding="utf-8", errors="replace"))
|
|
119
|
+
except (OSError, json.JSONDecodeError):
|
|
120
|
+
continue
|
|
121
|
+
layers = data.get("layers") if isinstance(data, dict) else None
|
|
122
|
+
if not isinstance(layers, list):
|
|
123
|
+
continue
|
|
124
|
+
|
|
125
|
+
model_blob: Path | None = None
|
|
126
|
+
mmproj_blob: Path | None = None
|
|
127
|
+
for layer in layers:
|
|
128
|
+
if not isinstance(layer, dict):
|
|
129
|
+
continue
|
|
130
|
+
media_type = str(layer.get("mediaType") or "")
|
|
131
|
+
digest = str(layer.get("digest") or "")
|
|
132
|
+
if not digest:
|
|
133
|
+
continue
|
|
134
|
+
blob_path = _digest_to_blob_path(blobs_dir, digest)
|
|
135
|
+
if media_type == OLLAMA_MODEL_MEDIA_TYPE and _is_gguf_file(blob_path):
|
|
136
|
+
model_blob = blob_path
|
|
137
|
+
elif media_type == OLLAMA_PROJECTOR_MEDIA_TYPE and blob_path.is_file():
|
|
138
|
+
mmproj_blob = blob_path
|
|
139
|
+
|
|
140
|
+
if model_blob is None:
|
|
141
|
+
continue
|
|
142
|
+
|
|
143
|
+
model_name = manifest_path.parent.name.lower()
|
|
144
|
+
tag_name = manifest_path.name.lower()
|
|
145
|
+
alias = model_name if tag_name == "latest" else f"{model_name}-{tag_name}"
|
|
146
|
+
if alias in seen_aliases:
|
|
147
|
+
continue
|
|
148
|
+
seen_aliases.add(alias)
|
|
149
|
+
|
|
150
|
+
size_bytes = model_blob.stat().st_size
|
|
151
|
+
found.append(
|
|
152
|
+
DiscoveredModel(
|
|
153
|
+
alias=alias,
|
|
154
|
+
source=f"ollama:{model_name}:{tag_name}",
|
|
155
|
+
model_path=model_blob.resolve(),
|
|
156
|
+
size_bytes=size_bytes,
|
|
157
|
+
mmproj_path=mmproj_blob.resolve() if mmproj_blob else None,
|
|
158
|
+
fit_tag=_fit_tag_for_size(size_bytes / GIB, vram_safe_gb),
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
found.sort(key=lambda item: item.alias)
|
|
163
|
+
return found
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def scan_gguf_directory(
|
|
167
|
+
directory: Path,
|
|
168
|
+
*,
|
|
169
|
+
vram_safe_gb: float = 0.0,
|
|
170
|
+
) -> list[DiscoveredModel]:
|
|
171
|
+
"""Recursively scan *directory* for local .gguf models and pair sibling mmproj files."""
|
|
172
|
+
root_dir = directory.expanduser().resolve()
|
|
173
|
+
if not root_dir.is_dir():
|
|
174
|
+
return []
|
|
175
|
+
|
|
176
|
+
by_dir: dict[Path, list[Path]] = {}
|
|
177
|
+
for cur_root, dirnames, filenames in os.walk(root_dir):
|
|
178
|
+
dirnames[:] = sorted(d for d in dirnames if not d.startswith("."))
|
|
179
|
+
cur_path = Path(cur_root)
|
|
180
|
+
ggufs = [cur_path / f for f in sorted(filenames) if f.lower().endswith(".gguf")]
|
|
181
|
+
if ggufs:
|
|
182
|
+
by_dir[cur_path] = ggufs
|
|
183
|
+
|
|
184
|
+
discovered: list[DiscoveredModel] = []
|
|
185
|
+
seen_aliases: set[str] = set()
|
|
186
|
+
|
|
187
|
+
for folder, files in sorted(by_dir.items()):
|
|
188
|
+
mmprojs = [f.name for f in files if "mmproj" in f.name.lower()]
|
|
189
|
+
best_mmproj_name = pick_best_mmproj(mmprojs)
|
|
190
|
+
best_mmproj_path = (folder / best_mmproj_name).resolve() if best_mmproj_name else None
|
|
191
|
+
|
|
192
|
+
for file_path in files:
|
|
193
|
+
if "mmproj" in file_path.name.lower():
|
|
194
|
+
continue
|
|
195
|
+
base_alias = default_alias_for_local_file(file_path)
|
|
196
|
+
alias = base_alias
|
|
197
|
+
suffix = 2
|
|
198
|
+
while alias in seen_aliases:
|
|
199
|
+
alias = f"{base_alias}-{suffix}"
|
|
200
|
+
suffix += 1
|
|
201
|
+
seen_aliases.add(alias)
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
size_bytes = file_path.stat().st_size
|
|
205
|
+
except OSError:
|
|
206
|
+
continue
|
|
207
|
+
|
|
208
|
+
discovered.append(
|
|
209
|
+
DiscoveredModel(
|
|
210
|
+
alias=alias,
|
|
211
|
+
source=str(file_path.parent),
|
|
212
|
+
model_path=file_path.resolve(),
|
|
213
|
+
size_bytes=size_bytes,
|
|
214
|
+
mmproj_path=best_mmproj_path,
|
|
215
|
+
fit_tag=_fit_tag_for_size(size_bytes / GIB, vram_safe_gb),
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
return discovered
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _register_discovered_models(
|
|
223
|
+
models: list[DiscoveredModel],
|
|
224
|
+
config: AppConfig,
|
|
225
|
+
console: Console,
|
|
226
|
+
*,
|
|
227
|
+
cpu_optimize: bool = False,
|
|
228
|
+
no_restart: bool = False,
|
|
229
|
+
) -> tuple[list[str], list[str]]:
|
|
230
|
+
"""Register discovered models into models.ini, skipping existing aliases."""
|
|
231
|
+
hw = detect_hardware(sys_platform=config.sys_platform) if cpu_optimize else None
|
|
232
|
+
added: list[str] = []
|
|
233
|
+
skipped: list[str] = []
|
|
234
|
+
|
|
235
|
+
for item in models:
|
|
236
|
+
if get_preset(config.models_ini, item.alias) is not None:
|
|
237
|
+
skipped.append(item.alias)
|
|
238
|
+
continue
|
|
239
|
+
extra: dict[str, str] = {}
|
|
240
|
+
if item.mmproj_path is not None:
|
|
241
|
+
extra["mmproj"] = str(item.mmproj_path)
|
|
242
|
+
if hw is not None:
|
|
243
|
+
extra["threads"] = str(recommended_cpu_threads(hw))
|
|
244
|
+
extra["ctx-size"] = str(recommended_cpu_ctx_size(hw))
|
|
245
|
+
add_preset(
|
|
246
|
+
config.models_ini,
|
|
247
|
+
item.alias,
|
|
248
|
+
model_path=str(item.model_path),
|
|
249
|
+
extra_options=extra or None,
|
|
250
|
+
)
|
|
251
|
+
added.append(item.alias)
|
|
252
|
+
|
|
253
|
+
if added and not no_restart:
|
|
254
|
+
backend = select_backend(config)
|
|
255
|
+
if backend.name != "remote":
|
|
256
|
+
res = backend.restart()
|
|
257
|
+
if not console.json_mode:
|
|
258
|
+
if res.ok:
|
|
259
|
+
console.ok(res.message)
|
|
260
|
+
else:
|
|
261
|
+
console.warn(res.message)
|
|
262
|
+
return added, skipped
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def run_import_ollama(
|
|
266
|
+
config: AppConfig,
|
|
267
|
+
console: Console,
|
|
268
|
+
*,
|
|
269
|
+
ollama_dir: Path | None = None,
|
|
270
|
+
import_all: bool = False,
|
|
271
|
+
cpu_optimize: bool = False,
|
|
272
|
+
no_restart: bool = False,
|
|
273
|
+
) -> int:
|
|
274
|
+
"""Discover and zero-copy import Ollama GGUF models into models.ini."""
|
|
275
|
+
resolved_dir = ollama_dir or resolve_ollama_models_dir()
|
|
276
|
+
if resolved_dir is None or not resolved_dir.is_dir():
|
|
277
|
+
msg = (
|
|
278
|
+
"No se encontró el directorio de modelos de Ollama (~/.ollama/models o OLLAMA_MODELS)."
|
|
279
|
+
)
|
|
280
|
+
if console.json_mode:
|
|
281
|
+
console.emit_json({"found": [], "added": [], "skipped": [], "error": msg})
|
|
282
|
+
else:
|
|
283
|
+
console.warn(msg)
|
|
284
|
+
return 1
|
|
285
|
+
|
|
286
|
+
hw = detect_hardware(sys_platform=config.sys_platform)
|
|
287
|
+
found = discover_ollama_models(resolved_dir, vram_safe_gb=hw.vram_safe_gb)
|
|
288
|
+
if not found:
|
|
289
|
+
if console.json_mode:
|
|
290
|
+
console.emit_json({"ollama_dir": str(resolved_dir), "found": [], "added": []})
|
|
291
|
+
else:
|
|
292
|
+
console.info(f"No se encontraron modelos GGUF en {resolved_dir}.")
|
|
293
|
+
return 0
|
|
294
|
+
|
|
295
|
+
if not console.json_mode:
|
|
296
|
+
console.header(f"Modelos Ollama detectados ({resolved_dir})")
|
|
297
|
+
rows = [
|
|
298
|
+
[
|
|
299
|
+
m.alias,
|
|
300
|
+
format_bytes(m.size_bytes),
|
|
301
|
+
m.fit_tag,
|
|
302
|
+
"sí" if m.mmproj_path else "-",
|
|
303
|
+
]
|
|
304
|
+
for m in found
|
|
305
|
+
]
|
|
306
|
+
console.print_table(["ALIAS", "TAMAÑO", "AJUSTE", "MMPROJ"], rows)
|
|
307
|
+
|
|
308
|
+
if (
|
|
309
|
+
not import_all
|
|
310
|
+
and not console.assume_yes
|
|
311
|
+
and not console.json_mode
|
|
312
|
+
and not console.confirm(
|
|
313
|
+
f"\n¿Importar {len(found)} modelo(s) a {config.models_ini} (sin copiar archivos)?",
|
|
314
|
+
default=True,
|
|
315
|
+
)
|
|
316
|
+
):
|
|
317
|
+
console.line("Cancelado.")
|
|
318
|
+
return 0
|
|
319
|
+
|
|
320
|
+
added, skipped = _register_discovered_models(
|
|
321
|
+
found,
|
|
322
|
+
config,
|
|
323
|
+
console,
|
|
324
|
+
cpu_optimize=cpu_optimize,
|
|
325
|
+
no_restart=no_restart,
|
|
326
|
+
)
|
|
327
|
+
if console.json_mode:
|
|
328
|
+
console.emit_json(
|
|
329
|
+
{
|
|
330
|
+
"ollama_dir": str(resolved_dir),
|
|
331
|
+
"found": [m.to_dict() for m in found],
|
|
332
|
+
"added": added,
|
|
333
|
+
"skipped": skipped,
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
return 0
|
|
337
|
+
|
|
338
|
+
console.ok(f"Importados {len(added)} modelo(s) (omitidos ya existentes: {len(skipped)}).")
|
|
339
|
+
return 0
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def run_scan_directory(
|
|
343
|
+
directory: Path,
|
|
344
|
+
config: AppConfig,
|
|
345
|
+
console: Console,
|
|
346
|
+
*,
|
|
347
|
+
register: bool = False,
|
|
348
|
+
cpu_optimize: bool = False,
|
|
349
|
+
no_restart: bool = False,
|
|
350
|
+
) -> int:
|
|
351
|
+
"""Scan a local directory for GGUF files and optionally register them in models.ini."""
|
|
352
|
+
target = directory.expanduser()
|
|
353
|
+
if not target.is_dir():
|
|
354
|
+
console.error(f"El directorio no existe: {target}")
|
|
355
|
+
return 1
|
|
356
|
+
|
|
357
|
+
hw = detect_hardware(sys_platform=config.sys_platform)
|
|
358
|
+
found = scan_gguf_directory(target, vram_safe_gb=hw.vram_safe_gb)
|
|
359
|
+
if not found:
|
|
360
|
+
if console.json_mode:
|
|
361
|
+
console.emit_json({"directory": str(target), "found": [], "added": []})
|
|
362
|
+
else:
|
|
363
|
+
console.info(f"No se encontraron archivos .gguf en {target}.")
|
|
364
|
+
return 0
|
|
365
|
+
|
|
366
|
+
if not console.json_mode:
|
|
367
|
+
console.header(f"Archivos GGUF encontrados en {target}")
|
|
368
|
+
rows = [
|
|
369
|
+
[
|
|
370
|
+
m.alias,
|
|
371
|
+
m.model_path.name,
|
|
372
|
+
format_bytes(m.size_bytes),
|
|
373
|
+
m.fit_tag,
|
|
374
|
+
"sí" if m.mmproj_path else "-",
|
|
375
|
+
]
|
|
376
|
+
for m in found
|
|
377
|
+
]
|
|
378
|
+
console.print_table(["ALIAS", "ARCHIVO", "TAMAÑO", "AJUSTE", "MMPROJ"], rows)
|
|
379
|
+
|
|
380
|
+
added: list[str] = []
|
|
381
|
+
skipped: list[str] = []
|
|
382
|
+
if register:
|
|
383
|
+
added, skipped = _register_discovered_models(
|
|
384
|
+
found,
|
|
385
|
+
config,
|
|
386
|
+
console,
|
|
387
|
+
cpu_optimize=cpu_optimize,
|
|
388
|
+
no_restart=no_restart,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
if console.json_mode:
|
|
392
|
+
console.emit_json(
|
|
393
|
+
{
|
|
394
|
+
"directory": str(target),
|
|
395
|
+
"found": [m.to_dict() for m in found],
|
|
396
|
+
"added": added,
|
|
397
|
+
"skipped": skipped,
|
|
398
|
+
}
|
|
399
|
+
)
|
|
400
|
+
return 0
|
|
401
|
+
|
|
402
|
+
if register:
|
|
403
|
+
console.ok(f"Registrados {len(added)} modelo(s) (omitidos ya existentes: {len(skipped)}).")
|
|
404
|
+
else:
|
|
405
|
+
console.info("Usa '--add' para registrar todos los modelos encontrados en models.ini.")
|
|
406
|
+
return 0
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Live terminal monitor (`llmctl top`) for hardware, llama-server, and loaded models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
|
|
8
|
+
from llmctl.config import AppConfig
|
|
9
|
+
from llmctl.hardware import HardwareInfo, detect_hardware
|
|
10
|
+
from llmctl.service import select_backend
|
|
11
|
+
from llmctl.service.base import ServiceStatus, list_router_models
|
|
12
|
+
from llmctl.ui import Console
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def render_bar(used: float, total: float, *, width: int = 24) -> str:
|
|
16
|
+
"""Render an ASCII/Unicode progress bar for memory or utilization metrics."""
|
|
17
|
+
if total <= 0:
|
|
18
|
+
return "[" + "-" * width + "] N/A"
|
|
19
|
+
ratio = max(0.0, min(1.0, used / total))
|
|
20
|
+
filled = round(ratio * width)
|
|
21
|
+
bar = "#" * filled + "-" * (width - filled)
|
|
22
|
+
return f"[{bar}] {ratio * 100:5.1f}%"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def collect_snapshot(config: AppConfig) -> tuple[HardwareInfo, ServiceStatus, list[dict[str, str]]]:
|
|
26
|
+
"""Gather one point-in-time hardware + service + router-models snapshot."""
|
|
27
|
+
hw = detect_hardware(sys_platform=config.sys_platform)
|
|
28
|
+
backend = select_backend(config)
|
|
29
|
+
svc = backend.status()
|
|
30
|
+
reachable, models = list_router_models(config, timeout=1.5)
|
|
31
|
+
if reachable and not svc.api_reachable:
|
|
32
|
+
svc.api_reachable = True
|
|
33
|
+
return hw, svc, models
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def format_snapshot_lines(
|
|
37
|
+
config: AppConfig,
|
|
38
|
+
hw: HardwareInfo,
|
|
39
|
+
svc: ServiceStatus,
|
|
40
|
+
models: list[dict[str, str]],
|
|
41
|
+
*,
|
|
42
|
+
now_str: str | None = None,
|
|
43
|
+
) -> list[str]:
|
|
44
|
+
"""Format a human-readable dashboard frame as a list of lines."""
|
|
45
|
+
ts = now_str or datetime.now().strftime("%H:%M:%S")
|
|
46
|
+
lines = [
|
|
47
|
+
f"llmctl top | {ts} | perfil: {config.profile or 'default'} | {svc.api_root}",
|
|
48
|
+
"=" * 74,
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# Service summary
|
|
52
|
+
api_state = "ONLINE" if svc.api_reachable else "OFFLINE"
|
|
53
|
+
pid_part = f" | PID {svc.pid}" if svc.pid else ""
|
|
54
|
+
lines.append(f"Servicio: [{api_state}] backend={svc.backend} ({svc.detail}){pid_part}")
|
|
55
|
+
lines.append("")
|
|
56
|
+
|
|
57
|
+
# GPU / VRAM
|
|
58
|
+
lines.append("Acelerador / VRAM:")
|
|
59
|
+
if hw.gpus:
|
|
60
|
+
for gpu in hw.gpus:
|
|
61
|
+
if gpu.vram_used_gb is not None and gpu.vram_total_gb > 0:
|
|
62
|
+
bar = render_bar(gpu.vram_used_gb, gpu.vram_total_gb)
|
|
63
|
+
util = (
|
|
64
|
+
f" | GPU {gpu.utilization_pct:.0f}%" if gpu.utilization_pct is not None else ""
|
|
65
|
+
)
|
|
66
|
+
lines.append(
|
|
67
|
+
f" {gpu.name}: {bar} {gpu.vram_used_gb:.2f}/{gpu.vram_total_gb:.2f} GiB{util}"
|
|
68
|
+
)
|
|
69
|
+
else:
|
|
70
|
+
kind = "unificada" if gpu.unified_memory else "total"
|
|
71
|
+
lines.append(f" {gpu.name}: {gpu.vram_total_gb:.2f} GiB ({kind})")
|
|
72
|
+
else:
|
|
73
|
+
lines.append(" Sin GPU dedicada/Metal/Vulkan (modo CPU/RAM)")
|
|
74
|
+
|
|
75
|
+
# RAM & CPU
|
|
76
|
+
lines.append("")
|
|
77
|
+
lines.append("Sistema (RAM / CPU):")
|
|
78
|
+
if hw.ram_available_gb is not None and hw.ram_total_gb > 0:
|
|
79
|
+
ram_used = max(0.0, hw.ram_total_gb - hw.ram_available_gb)
|
|
80
|
+
ram_bar = render_bar(ram_used, hw.ram_total_gb)
|
|
81
|
+
lines.append(f" RAM: {ram_bar} {ram_used:.2f}/{hw.ram_total_gb:.2f} GiB")
|
|
82
|
+
else:
|
|
83
|
+
lines.append(f" RAM: {hw.ram_total_gb:.2f} GiB total")
|
|
84
|
+
lines.append(
|
|
85
|
+
f" CPU: {hw.cpu_cores_physical} núcleos físicos / {hw.cpu_cores_logical} hilos lógicos"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Router models
|
|
89
|
+
lines.append("")
|
|
90
|
+
lines.append("Modelos en router:")
|
|
91
|
+
if not models:
|
|
92
|
+
lines.append(" (Sin modelos reportados o servidor detenido)")
|
|
93
|
+
else:
|
|
94
|
+
for m in models[:15]:
|
|
95
|
+
status = m.get("status", "unknown")
|
|
96
|
+
marker = "*" if status.lower() == "loaded" else " "
|
|
97
|
+
lines.append(f" {marker} {m['id']:<36} [{status}]")
|
|
98
|
+
|
|
99
|
+
return lines
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def run_top(
|
|
103
|
+
config: AppConfig,
|
|
104
|
+
console: Console,
|
|
105
|
+
*,
|
|
106
|
+
interval: float = 1.5,
|
|
107
|
+
once: bool = False,
|
|
108
|
+
) -> int:
|
|
109
|
+
"""Display a live-refreshing (or single-shot) hardware & router monitor."""
|
|
110
|
+
safe_interval = max(0.25, interval)
|
|
111
|
+
|
|
112
|
+
if console.json_mode or once or not console.is_interactive():
|
|
113
|
+
hw, svc, models = collect_snapshot(config)
|
|
114
|
+
if console.json_mode:
|
|
115
|
+
console.emit_json(
|
|
116
|
+
{
|
|
117
|
+
"profile": config.profile or "default",
|
|
118
|
+
"hardware": hw.to_dict(),
|
|
119
|
+
"service": svc.to_dict(),
|
|
120
|
+
"models": models,
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
return 0
|
|
124
|
+
for line in format_snapshot_lines(config, hw, svc, models):
|
|
125
|
+
console.line(line)
|
|
126
|
+
return 0
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
while True:
|
|
130
|
+
hw, svc, models = collect_snapshot(config)
|
|
131
|
+
frame = "\n".join(format_snapshot_lines(config, hw, svc, models))
|
|
132
|
+
console.stdout.write("\033[2J\033[H")
|
|
133
|
+
console.stdout.write(frame + "\n\nPulsa Ctrl+C para salir.\n")
|
|
134
|
+
console.stdout.flush()
|
|
135
|
+
time.sleep(safe_interval)
|
|
136
|
+
except KeyboardInterrupt:
|
|
137
|
+
console.line("")
|
|
138
|
+
return 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|