fix: remove missing resource path from tauri.conf; add GPU detection and layer clamping

This commit is contained in:
Evandro Fonseca Junior committed 2026-03-26 21:22:08 -03:00
1 parent 99672b33d0
commit ae8d79e167
4 files changed
+230 -14

No files matched your search

+90 -11
View File
@@ -1,4 +1,5 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import { invoke } from "@tauri-apps/api/core";
import type { ProcessStatus, ServerConfig } from "../hooks/useServerProcess";
import "./ServerPanel.css";
@@ -9,6 +10,12 @@ interface Props {
onStop: () => void;
}
interface GpuInfo {
name: string;
vram_mib: number;
recommended_layers: number;
}
const STATUS_LABEL: Record<ProcessStatus, string> = {
stopped: "Stopped",
starting: "Starting…",
@@ -35,9 +42,31 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
const [gpuLayers, setGpuLayers] = useState(
() => parseInt(localStorage.getItem("forgelm_gpu_layers") || "0", 10)
);
const [gpuInfo, setGpuInfo] = useState<GpuInfo | null>(null);
const [gpuError, setGpuError] = useState<string>("");
const [expanded, setExpanded] = useState(false);
// Detect GPU on mount
useEffect(() => {
invoke<GpuInfo>("query_gpu")
.then((info) => {
setGpuInfo(info);
// Only auto-set if user hasn't saved a preference yet
if (!localStorage.getItem("forgelm_gpu_layers")) {
setGpuLayers(info.recommended_layers);
}
})
.catch((e) => {
setGpuError(String(e));
// Default to CPU-only if no GPU
if (!localStorage.getItem("forgelm_gpu_layers")) {
setGpuLayers(0);
}
});
}, []);
const isActive = status === "running" || status === "starting" || status === "stopping";
const maxLayers = gpuInfo ? gpuInfo.recommended_layers : 999;
const handleStart = () => {
localStorage.setItem("forgelm_model_path", modelPath);
@@ -46,6 +75,11 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
onStart({ modelPath, addr, gpuLayers });
};
const handleLayersChange = (val: number) => {
const clamped = Math.max(0, Math.min(val, maxLayers));
setGpuLayers(clamped);
};
return (
<div className="server-panel">
<div className="server-panel-header" onClick={() => setExpanded(!expanded)}>
@@ -64,6 +98,19 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
{expanded && (
<div className="server-panel-body">
{/* GPU info badge */}
{gpuInfo ? (
<div className="sp-gpu-badge">
🎮 {gpuInfo.name} — {(gpuInfo.vram_mib / 1024).toFixed(1)} GB VRAM
</div>
) : gpuError ? (
<div className="sp-gpu-badge sp-gpu-cpu">
💻 CPU only — {gpuError.includes("not found") ? "No NVIDIA GPU" : gpuError}
</div>
) : (
<div className="sp-gpu-badge sp-gpu-loading">🔍 Detecting GPU…</div>
)}
<label className="sp-label">Model path (.gguf)</label>
<input
className="sp-input"
@@ -84,16 +131,48 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
disabled={isActive}
/>
<label className="sp-label">GPU Layers (0 = CPU only)</label>
<input
className="sp-input sp-input-num"
type="number"
min={0}
max={999}
value={gpuLayers}
onChange={(e) => setGpuLayers(parseInt(e.target.value, 10) || 0)}
disabled={isActive}
/>
<label className="sp-label">
GPU Layers
{gpuInfo && (
<span className="sp-label-hint"> (max {gpuInfo.recommended_layers} for your GPU)</span>
)}
</label>
<div className="sp-layers-row">
<input
className="sp-input sp-input-num"
type="number"
min={0}
max={maxLayers}
value={gpuLayers}
onChange={(e) => handleLayersChange(parseInt(e.target.value, 10) || 0)}
disabled={isActive}
/>
{gpuInfo && (
<button
className="sp-btn-max"
onClick={() => handleLayersChange(gpuInfo.recommended_layers)}
disabled={isActive}
title="Set to maximum recommended"
>
Max
</button>
)}
{gpuLayers === 0 && (
<span className="sp-layers-hint">CPU only</span>
)}
</div>
{gpuInfo && gpuLayers > 0 && (
<div className="sp-vram-bar">
<div
className="sp-vram-fill"
style={{ width: `${Math.min(100, (gpuLayers / gpuInfo.recommended_layers) * 100)}%` }}
/>
<span className="sp-vram-label">
~{Math.round(gpuLayers * 80)} MB / {gpuInfo.vram_mib} MB VRAM
</span>
</div>
)}
<div className="sp-actions">
{status === "stopped" || status === "error" ? (