Deployments: API keys, deploy from the library, reorganized form

- Settings → API keys (generate or paste, show again, delete). Deployments with
  "Require an API key" get them via LLAMA_API_KEY / VLLM_API_KEY (--api-key for
  several vLLM keys); values are masked in the stored/shown command and in logs.
  The chat proxy sends a key.
- "Deploy" in the library and on the model page preselects the model and a
  runtime that can serve it; library rows and the model page link to the
  model's deployments.
- Deployment form: grouped launch options with flags next to labels, command in
  its own step, extra arguments as flag/value rows (runtime form too).
- Native selects follow the dark theme (color-scheme), fixing unreadable options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-06 12:28:25 +02:00
1 parent 66e6a8c4f7
commit ea1f18cc74
32 files changed
+2478 -183

No files matched your search

+48 -1
View File
@@ -2,8 +2,9 @@ import "server-only";
import { and, asc, desc, eq, gt, inArray, isNull, ne } from "drizzle-orm";
import { z } from "zod";
import { db } from "@/lib/db/client";
import { deploymentLogs, deployments, type DeploymentOptions, modelFiles, models, runtimes } from "@/lib/db/schema";
import { apiKeys, deploymentLogs, deployments, type DeploymentOptions, modelFiles, models, runtimes } from "@/lib/db/schema";
import { type ModelCandidates, modelCandidates, servableBy } from "@/lib/deploy-candidates";
import { quantGroup } from "@/lib/selection";
export class DeploymentError extends Error {
constructor(
@@ -35,6 +36,7 @@ export const DeploymentBody = z.object({
cacheTypeV: z.enum(["f32", "f16", "bf16", "q8_0", "q4_0", "q4_1", "iq4_nl", "q5_0", "q5_1"]).nullable().optional(),
flashAttn: z.enum(["auto", "on", "off"]).nullable().optional(),
webui: z.boolean().nullable().optional(),
requireApiKey: z.boolean().nullable().optional(),
dtype: z.enum(["auto", "bfloat16", "float16", "float32"]).nullable().optional(),
maxNumSeqs: int(1, 1024).nullable().optional(),
kvCacheGb: z.number().min(0.25).max(1024).nullable().optional(),
@@ -92,6 +94,9 @@ async function validate(input: DeploymentInput, selfId?: string): Promise<Deploy
} else {
Object.assign(options, { modelFile: "", mmproj: null, draftFile: null, draftType: null, batchSize: null, ubatchSize: null, cacheTypeK: null, cacheTypeV: null, flashAttn: null, webui: null });
}
if (o.requireApiKey && (await db().select({ id: apiKeys.id }).from(apiKeys).limit(1)).length === 0) {
throw new DeploymentError("invalid", "Add an API key under Settings → API keys first.", 400);
}
if (input.hostPort) {
const clash = await db().query.deployments.findFirst({
columns: { name: true },
@@ -236,3 +241,45 @@ export async function deploymentsUsing(by: { modelId?: string; runtimeId?: strin
),
);
}
export type ModelDeployment = { id: string; name: string; state: DeploymentRow["state"]; desiredState: DeploymentRow["desiredState"]; runtimeName: string };
/** Deployments per model id (for links from the library and model pages). */
export async function deploymentsByModel(): Promise<Map<string, ModelDeployment[]>> {
const rows = await db()
.select({
modelId: deployments.modelId,
id: deployments.id,
name: deployments.name,
state: deployments.state,
desiredState: deployments.desiredState,
runtimeName: runtimes.name,
})
.from(deployments)
.innerJoin(runtimes, eq(runtimes.id, deployments.runtimeId))
.where(isNull(deployments.deleteRequestedAt))
.orderBy(asc(deployments.name));
const out = new Map<string, ModelDeployment[]>();
for (const { modelId, ...d } of rows) out.set(modelId, [...(out.get(modelId) ?? []), d]);
return out;
}
/** Form defaults for "Deploy" from the library: the first runtime with a pulled image that can serve the model. */
export async function deployPreset(modelId: string) {
const model = (await listDeployableModels()).find((m) => m.id === modelId);
if (!model) return null;
const rts = await db().select({ id: runtimes.id, engine: runtimes.engine }).from(runtimes).where(eq(runtimes.imageState, "present")).orderBy(asc(runtimes.createdAt));
const runtime = rts.find((r) => servableBy(model.candidates, r.engine));
if (!runtime) return null;
const gguf = runtime.engine === "llama.cpp" ? model.candidates.gguf[0] : undefined;
const quant = gguf ? quantGroup(gguf.path) : null;
return {
name: `${model.repoId.split("/")[1]}${quant ? ` ${quant}` : ""}`,
runtimeId: runtime.id,
modelId: model.id,
options: { modelFile: gguf?.path ?? "", mmproj: gguf ? (model.candidates.mmproj[0]?.path ?? null) : null, contextSize: 4096, extraArgs: [] },
cpus: null,
memoryMb: null,
hostPort: null,
};
}