'use client' import { useState } from 'react' import AdminLayout from '@/components/admin/AdminLayout' import { WizardStepper, WizardNavigation, EducationCard, ArchitectureContext, TestRunner, TestSummary, type WizardStep, type TestCategoryResult, type FullTestResults, type EducationContent, type ArchitectureContextType, } from '@/components/wizard' // ============================================== // Constants // ============================================== const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000' const STEPS: WizardStep[] = [ { id: 'welcome', name: 'Willkommen', icon: '👋', status: 'pending' }, { id: 'api-health', name: 'API Status', icon: '💚', status: 'pending', category: 'api-health' }, { id: 'detection', name: 'GPU Erkennung', icon: '🔍', status: 'pending', category: 'detection' }, { id: 'cloud', name: 'Cloud GPU', icon: '☁️', status: 'pending', category: 'cloud' }, { id: 'summary', name: 'Zusammenfassung', icon: '📊', status: 'pending' }, ] const EDUCATION_CONTENT: Record = { 'welcome': { title: 'Willkommen zum GPU Wizard', content: [ 'GPUs beschleunigen KI-Workloads um das 10-100fache.', '', 'BreakPilot unterstuetzt:', '• NVIDIA GPUs (CUDA) - GeForce, Tesla, A100', '• AMD GPUs (ROCm) - Radeon, Instinct', '• Cloud GPUs (vast.ai) - On-Demand Miete', '', 'Anwendungsfaelle:', '• LLM Inference (lokale Modelle)', '• Embedding-Generierung', '• Fine-Tuning von Modellen', '• OCR und Bildverarbeitung', ], }, 'api-health': { title: 'GPU Admin API - Verwaltungsschnittstelle', content: [ 'Die GPU API verwaltet lokale und Cloud-GPUs.', '', 'Endpunkte:', '• /api/gpu/status - Aktueller GPU-Status', '• /api/gpu/jobs - Laufende GPU-Jobs', '• /api/gpu/metrics - Auslastung und Temperatur', '', 'vast.ai Integration:', '• /vast/instances - Gemietete Instanzen', '• /vast/offers - Verfuegbare Angebote', '• /vast/start - Instanz starten', ], }, 'detection': { title: 'GPU Hardware-Erkennung', content: [ 'Automatische Erkennung verfuegbarer GPUs.', '', 'NVIDIA (nvidia-smi):', '• GPU-Modell und VRAM', '• Treiber-Version', '• Aktuelle Auslastung', '• Temperatur und Stromverbrauch', '', 'AMD (rocm-smi):', '• ROCm-Version', '• GPU-Modell', '• Memory-Statistiken', '', 'PyTorch CUDA Check:', '• torch.cuda.is_available()', '• torch.cuda.device_count()', ], }, 'cloud': { title: 'Cloud GPUs mit vast.ai', content: [ 'vast.ai bietet guenstige Cloud-GPUs auf Abruf.', '', 'Vorteile:', '• 3-10x guenstiger als AWS/GCP', '• Peer-to-Peer Marktplatz', '• Minutengenaue Abrechnung', '• Zugriff auf A100, H100, etc.', '', 'Typische Preise:', '• RTX 3090: ~$0.20/Stunde', '• A100 40GB: ~$1.00/Stunde', '• H100: ~$2.50/Stunde', '', 'Konfiguration: VAST_API_KEY Umgebungsvariable', ], }, 'summary': { title: 'Test-Zusammenfassung', content: [ 'Hier sehen Sie eine Uebersicht aller durchgefuehrten Tests:', '• Lokale GPU-Erkennung', '• Cloud-GPU Verfuegbarkeit', '• API-Status', ], }, } const ARCHITECTURE_CONTEXTS: Record = { 'api-health': { layer: 'api', services: ['backend'], dependencies: ['PostgreSQL', 'vast.ai API'], dataFlow: ['Browser', 'FastAPI', 'GPU Manager', 'PostgreSQL'], }, 'detection': { layer: 'service', services: ['backend'], dependencies: ['nvidia-smi', 'rocm-smi', 'PyTorch'], dataFlow: ['FastAPI', 'Subprocess', 'GPU Driver', 'Hardware'], }, 'cloud': { layer: 'service', services: ['backend'], dependencies: ['vast.ai API', 'SSH', 'Docker'], dataFlow: ['FastAPI', 'vast.ai API', 'Cloud Instance', 'GPU'], }, } // ============================================== // Main Component // ============================================== export default function GPUWizardPage() { const [currentStep, setCurrentStep] = useState(0) const [steps, setSteps] = useState(STEPS) const [categoryResults, setCategoryResults] = useState>({}) const [fullResults, setFullResults] = useState(null) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const currentStepData = steps[currentStep] const isTestStep = currentStepData?.category !== undefined const isWelcome = currentStepData?.id === 'welcome' const isSummary = currentStepData?.id === 'summary' const runCategoryTest = async (category: string) => { setIsLoading(true) setError(null) try { const response = await fetch(`${BACKEND_URL}/api/admin/gpu-tests/${category}`, { method: 'POST', }) if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`) } const result: TestCategoryResult = await response.json() setCategoryResults((prev) => ({ ...prev, [category]: result })) setSteps((prev) => prev.map((step) => step.category === category ? { ...step, status: result.failed === 0 ? 'completed' : 'failed' } : step ) ) } catch (err) { setError(err instanceof Error ? err.message : 'Unbekannter Fehler') } finally { setIsLoading(false) } } const runAllTests = async () => { setIsLoading(true) setError(null) try { const response = await fetch(`${BACKEND_URL}/api/admin/gpu-tests/run-all`, { method: 'POST', }) if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`) } const results: FullTestResults = await response.json() setFullResults(results) setSteps((prev) => prev.map((step) => { if (step.category) { const catResult = results.categories.find((c) => c.category === step.category) if (catResult) { return { ...step, status: catResult.failed === 0 ? 'completed' : 'failed' } } } return step }) ) const newCategoryResults: Record = {} results.categories.forEach((cat) => { newCategoryResults[cat.category] = cat }) setCategoryResults(newCategoryResults) } catch (err) { setError(err instanceof Error ? err.message : 'Unbekannter Fehler') } finally { setIsLoading(false) } } const goToNext = () => { if (currentStep < steps.length - 1) { setSteps((prev) => prev.map((step, idx) => idx === currentStep && step.status === 'pending' ? { ...step, status: 'completed' } : step ) ) setCurrentStep((prev) => prev + 1) } } const goToPrev = () => { if (currentStep > 0) { setCurrentStep((prev) => prev - 1) } } const handleStepClick = (index: number) => { if (index <= currentStep || steps[index - 1]?.status !== 'pending') { setCurrentStep(index) } } return ( {/* Header */}
🎮

GPU Infrastructure Wizard

CUDA, ROCm & vast.ai

← Zurueck zu GPU Management
{/* Stepper */}
{/* Content */}
{currentStepData?.icon}

Schritt {currentStep + 1}: {currentStepData?.name}

{currentStep + 1} von {steps.length}

{isTestStep && currentStepData?.category && ARCHITECTURE_CONTEXTS[currentStepData.category] && ( )} {error && (
Fehler: {error}
)} {isWelcome && (
)} {isTestStep && currentStepData?.category && ( runCategoryTest(currentStepData.category!)} /> )} {isSummary && (
{!fullResults ? (

Fuehren Sie alle Tests aus um eine Zusammenfassung zu sehen.

) : ( )}
)}
Diese Tests pruefen die GPU-Infrastruktur. Bei Fragen wenden Sie sich an das DevOps-Team.
) }