feat: add gpu options
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { AccessType } from "../../../lib/AccessType";
|
||||
import { MachineList } from "@/components/MachineList";
|
||||
import { db } from "@/db/db";
|
||||
import { machinesTable } from "@/db/schema";
|
||||
import { auth } from "@clerk/nextjs";
|
||||
import { clerkClient } from "@clerk/nextjs/server";
|
||||
import { desc, eq, isNull, and } from "drizzle-orm";
|
||||
|
||||
export default function Page() {
|
||||
@@ -15,6 +17,8 @@ async function MachineListServer() {
|
||||
return <div>No auth</div>;
|
||||
}
|
||||
|
||||
const user = await clerkClient.users.getUser(userId);
|
||||
|
||||
const machines = await db.query.machinesTable.findMany({
|
||||
orderBy: desc(machinesTable.updated_at),
|
||||
where:
|
||||
@@ -26,7 +30,10 @@ async function MachineListServer() {
|
||||
return (
|
||||
<div className="w-full">
|
||||
{/* <div>Machines</div> */}
|
||||
<MachineList data={machines} />
|
||||
<MachineList
|
||||
data={machines}
|
||||
userMetadata={AccessType.parse(user.privateMetadata ?? {})}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { type MachineType } from "@/db/schema";
|
||||
import type { AccessType } from "@/lib/AccessType";
|
||||
import {
|
||||
addCustomMachineSchema,
|
||||
addMachineSchema,
|
||||
@@ -53,6 +54,7 @@ import {
|
||||
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useState } from "react";
|
||||
import type { z } from "zod";
|
||||
|
||||
export type Machine = MachineType;
|
||||
|
||||
@@ -237,6 +239,9 @@ export const columns: ColumnDef<Machine>[] = [
|
||||
models: {
|
||||
fieldType: "models",
|
||||
},
|
||||
gpu: {
|
||||
inputProps: {},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
@@ -263,7 +268,13 @@ export const columns: ColumnDef<Machine>[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export function MachineList({ data }: { data: Machine[] }) {
|
||||
export function MachineList({
|
||||
data,
|
||||
userMetadata,
|
||||
}: {
|
||||
data: Machine[];
|
||||
userMetadata: z.infer<typeof AccessType>;
|
||||
}) {
|
||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||
[]
|
||||
@@ -332,6 +343,14 @@ export function MachineList({ data }: { data: Machine[] }) {
|
||||
models: {
|
||||
fieldType: "models",
|
||||
},
|
||||
gpu: {
|
||||
fieldType: !userMetadata.betaFeaturesAccess
|
||||
? "fallback"
|
||||
: "select",
|
||||
inputProps: {
|
||||
disabled: !userMetadata.betaFeaturesAccess,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<InsertModal
|
||||
|
||||
@@ -59,7 +59,7 @@ function SnapshotPresetPicker({
|
||||
|
||||
React.useEffect(() => {
|
||||
findAllDeployments().then((a) => {
|
||||
console.log(a);
|
||||
// console.log(a);
|
||||
|
||||
const frameworks = a
|
||||
.map((item) => {
|
||||
|
||||
@@ -104,6 +104,8 @@ export const workflowRunOrigin = pgEnum("workflow_run_origin", [
|
||||
"api",
|
||||
]);
|
||||
|
||||
export const machineGPUOptions = pgEnum("machine_gpu", ["T4", "A10G", "A100"]);
|
||||
|
||||
export const machinesType = pgEnum("machine_type", [
|
||||
"classic",
|
||||
"runpod-serverless",
|
||||
@@ -205,6 +207,7 @@ export const machinesTable = dbSchema.table("machines", {
|
||||
status: machinesStatus("status").notNull().default("ready"),
|
||||
snapshot: jsonb("snapshot").$type<any>(),
|
||||
models: jsonb("models").$type<any>(),
|
||||
gpu: machineGPUOptions("gpu"),
|
||||
build_machine_instance_id: text("build_machine_instance_id"),
|
||||
build_log: text("build_log"),
|
||||
});
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const AccessType = z.object({
|
||||
betaFeaturesAccess: z.boolean().default(false),
|
||||
});
|
||||
@@ -11,6 +11,7 @@ export const addMachineSchema = insertMachineSchema.pick({
|
||||
export const insertCustomMachineSchema = createInsertSchema(machinesTable, {
|
||||
name: (schema) => schema.name.default("My Machine"),
|
||||
type: (schema) => schema.type.default("comfy-deploy-serverless"),
|
||||
gpu: (schema) => schema.gpu.default("T4"),
|
||||
snapshot: (schema) =>
|
||||
schema.snapshot.default({
|
||||
comfyui: "d0165d819afe76bd4e6bdd710eb5f3e571b6a804",
|
||||
@@ -37,4 +38,5 @@ export const addCustomMachineSchema = insertCustomMachineSchema.pick({
|
||||
type: true,
|
||||
snapshot: true,
|
||||
models: true,
|
||||
gpu: true,
|
||||
});
|
||||
|
||||
@@ -93,6 +93,7 @@ export const updateCustomMachine = withServerPromise(
|
||||
JSON.stringify(data.snapshot) !== JSON.stringify(currentMachine.snapshot);
|
||||
const modelsChanged =
|
||||
JSON.stringify(data.models) !== JSON.stringify(currentMachine.models);
|
||||
const gpuChanged = data.gpu !== currentMachine.gpu;
|
||||
|
||||
// return {
|
||||
// message: `snapshotChanged: ${snapshotChanged}, modelsChanged: ${modelsChanged}`,
|
||||
@@ -101,7 +102,7 @@ export const updateCustomMachine = withServerPromise(
|
||||
await db.update(machinesTable).set(data).where(eq(machinesTable.id, id));
|
||||
|
||||
// If there are changes
|
||||
if (snapshotChanged || modelsChanged) {
|
||||
if (snapshotChanged || modelsChanged || gpuChanged) {
|
||||
// Update status to building
|
||||
await db
|
||||
.update(machinesTable)
|
||||
@@ -174,7 +175,7 @@ async function buildMachine(
|
||||
snapshot: data.snapshot, //JSON.parse( as string),
|
||||
callback_url: `${protocol}://${domain}/api/machine-built`,
|
||||
models: data.models, //JSON.parse(data.models as string),
|
||||
gpu: "T4",
|
||||
gpu: data.gpu ?? "T4",
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user