feat: add llama dashboard for managing launch config via web UI
Adds a small Next.js dashboard as a new Docker service () that replaces the need to manually edit and call over SSH every time you want to tweak llama launch parameters. Features: - Live status panel for all GPU-node containers (auto-refresh) - Models list with file sizes, click-to-select active model - Structured launch config form: * Model, ctx-size, parallel, batch-size, n-gpu-layers, threads * Context overflow (none / shift / evict) * Speculative decoding (spec-type, draft model, spec-draft-n-max) * Free-form extra args textarea for anything else - Named presets (save / load / delete) - Start / Restart / Stop / Remove llama actions - Live streaming logs viewer (docker logs -f) - GPU status (nvidia-smi via docker exec on llama) - Auto-writes LLAMA_MODEL and LLAMA_EXTRA_ARGS back to .env so the existing workflow keeps working, and persists full structured config to gpu/dashboard/config.json for reload on next visit Integration: - New service in compose.yaml (no profile, runs always) - Mounts /var/run/docker.sock + HOST_PROJECT_PATH - Tailscale serve exposes port 8090 -> dashboard:3000 - build.sh extended to build the dashboard image Tech: Next.js 16 standalone, React 19, TypeScript 5, Tailwind 4, shadcn-style components, Radix UI primitives.
This commit is contained in:
112
dashboard/src/app/api/config/route.ts
Normal file
112
dashboard/src/app/api/config/route.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import {
|
||||
loadConfig,
|
||||
saveConfig,
|
||||
DEFAULT_CONFIG,
|
||||
type DashboardConfig,
|
||||
type Preset,
|
||||
} from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET() {
|
||||
const config = await loadConfig();
|
||||
return NextResponse.json({ config, defaults: DEFAULT_CONFIG });
|
||||
}
|
||||
|
||||
export async function PUT(req: NextRequest) {
|
||||
const body = (await req.json()) as Partial<DashboardConfig>;
|
||||
const current = await loadConfig();
|
||||
|
||||
// Merge: keep existing presets unless explicitly overwritten
|
||||
const next: DashboardConfig = {
|
||||
model: body.model ?? current.model,
|
||||
ctxSize: body.ctxSize ?? current.ctxSize,
|
||||
parallel: body.parallel ?? current.parallel,
|
||||
nGpuLayers: body.nGpuLayers ?? current.nGpuLayers,
|
||||
threads: body.threads ?? current.threads,
|
||||
draftModel: body.draftModel ?? current.draftModel,
|
||||
specType: body.specType ?? current.specType,
|
||||
specDraftNMax: body.specDraftNMax ?? current.specDraftNMax,
|
||||
batchSize: body.batchSize ?? current.batchSize,
|
||||
contextOverflow: body.contextOverflow ?? current.contextOverflow,
|
||||
extraArgs: body.extraArgs ?? current.extraArgs,
|
||||
presets: body.presets ?? current.presets,
|
||||
};
|
||||
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
}
|
||||
|
||||
// ----- Presets -------------------------------------------------------------
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = (await req.json()) as {
|
||||
action: "save-preset" | "delete-preset" | "load-preset" | "reset";
|
||||
name?: string;
|
||||
id?: string;
|
||||
};
|
||||
const current = await loadConfig();
|
||||
|
||||
if (body.action === "save-preset") {
|
||||
if (!body.name) {
|
||||
return NextResponse.json(
|
||||
{ error: "name is required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
const preset: Preset = {
|
||||
id: `preset-${Date.now()}`,
|
||||
name: body.name,
|
||||
config: stripPresets(current),
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
const next: DashboardConfig = {
|
||||
...current,
|
||||
presets: [...current.presets.filter((p) => p.name !== body.name), preset],
|
||||
};
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
}
|
||||
|
||||
if (body.action === "delete-preset") {
|
||||
if (!body.id) {
|
||||
return NextResponse.json({ error: "id is required" }, { status: 400 });
|
||||
}
|
||||
const next: DashboardConfig = {
|
||||
...current,
|
||||
presets: current.presets.filter((p) => p.id !== body.id),
|
||||
};
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
}
|
||||
|
||||
if (body.action === "load-preset") {
|
||||
if (!body.id) {
|
||||
return NextResponse.json({ error: "id is required" }, { status: 400 });
|
||||
}
|
||||
const preset = current.presets.find((p) => p.id === body.id);
|
||||
if (!preset) {
|
||||
return NextResponse.json({ error: "preset not found" }, { status: 404 });
|
||||
}
|
||||
const next: DashboardConfig = {
|
||||
...preset.config,
|
||||
presets: current.presets,
|
||||
};
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
}
|
||||
|
||||
if (body.action === "reset") {
|
||||
await saveConfig({ ...DEFAULT_CONFIG, presets: current.presets });
|
||||
return NextResponse.json({ config: { ...DEFAULT_CONFIG, presets: current.presets } });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||
}
|
||||
|
||||
function stripPresets(cfg: DashboardConfig): Omit<DashboardConfig, "presets"> {
|
||||
const { presets: _presets, ...rest } = cfg;
|
||||
return rest;
|
||||
}
|
||||
11
dashboard/src/app/api/gpu/route.ts
Normal file
11
dashboard/src/app/api/gpu/route.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getGpuStatus } from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 60;
|
||||
|
||||
export async function GET(_req: NextRequest) {
|
||||
const status = await getGpuStatus();
|
||||
return NextResponse.json(status, { status: status.ok ? 200 : 500 });
|
||||
}
|
||||
46
dashboard/src/app/api/llama/route.ts
Normal file
46
dashboard/src/app/api/llama/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import {
|
||||
loadConfig,
|
||||
startLlama,
|
||||
stopLlama,
|
||||
restartLlama,
|
||||
removeLlama,
|
||||
type DashboardConfig,
|
||||
} from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = (await req.json()) as {
|
||||
action: "start" | "stop" | "restart" | "remove";
|
||||
config?: Partial<DashboardConfig>;
|
||||
};
|
||||
|
||||
if (body.action === "start") {
|
||||
const current = await loadConfig();
|
||||
const cfg: DashboardConfig = {
|
||||
...current,
|
||||
...(body.config || {}),
|
||||
} as DashboardConfig;
|
||||
const result = await startLlama(cfg);
|
||||
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||
}
|
||||
|
||||
if (body.action === "stop") {
|
||||
const result = await stopLlama();
|
||||
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||
}
|
||||
|
||||
if (body.action === "restart") {
|
||||
const result = await restartLlama();
|
||||
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||
}
|
||||
|
||||
if (body.action === "remove") {
|
||||
const result = await removeLlama();
|
||||
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||
}
|
||||
76
dashboard/src/app/api/logs/route.ts
Normal file
76
dashboard/src/app/api/logs/route.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { getLlamaContainerName } from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 300;
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const name = await getLlamaContainerName();
|
||||
if (!name) {
|
||||
return new Response("[llama container not found]", {
|
||||
headers: {
|
||||
"Content-Type": "text/plain; charset=utf-8",
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const tail = Number(req.nextUrl.searchParams.get("tail") || 500);
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
async start(controller) {
|
||||
controller.enqueue(
|
||||
encoder.encode(
|
||||
`=== Streaming logs for ${name} (tail=${tail}) ===\n`
|
||||
)
|
||||
);
|
||||
|
||||
const { spawn } = await import("node:child_process");
|
||||
const child = spawn("docker", ["logs", "-f", "--tail", String(tail), "--timestamps", name]);
|
||||
|
||||
const enqueue = (chunk: Buffer | string) => {
|
||||
try {
|
||||
controller.enqueue(encoder.encode(chunk.toString()));
|
||||
} catch {
|
||||
/* stream closed */
|
||||
}
|
||||
};
|
||||
|
||||
child.stdout.on("data", enqueue);
|
||||
child.stderr.on("data", enqueue);
|
||||
|
||||
child.on("error", (err) => {
|
||||
controller.enqueue(encoder.encode(`[stream error: ${err.message}]\n`));
|
||||
controller.close();
|
||||
});
|
||||
child.on("exit", () => {
|
||||
try {
|
||||
controller.close();
|
||||
} catch {
|
||||
/* already closed */
|
||||
}
|
||||
});
|
||||
|
||||
// Abort signal from client disconnect
|
||||
req.signal.addEventListener("abort", () => {
|
||||
try {
|
||||
child.kill("SIGTERM");
|
||||
} catch {
|
||||
/* noop */
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
"Content-Type": "text/plain; charset=utf-8",
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"X-Accel-Buffering": "no",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
});
|
||||
}
|
||||
10
dashboard/src/app/api/models/route.ts
Normal file
10
dashboard/src/app/api/models/route.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { listModels } from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET() {
|
||||
const models = await listModels();
|
||||
return NextResponse.json({ models });
|
||||
}
|
||||
18
dashboard/src/app/api/status/route.ts
Normal file
18
dashboard/src/app/api/status/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { listContainers, getLlamaHealth, NODE_INSTANCE } from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET() {
|
||||
const [containers, llamaHealth] = await Promise.all([
|
||||
listContainers(),
|
||||
getLlamaHealth(),
|
||||
]);
|
||||
return NextResponse.json({
|
||||
instance: NODE_INSTANCE,
|
||||
containers,
|
||||
llamaHealth,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user