'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: 'gateway', name: 'LLM Gateway', icon: '🌐', status: 'pending', category: 'gateway' }, { id: 'providers', name: 'Provider', icon: '🤖', status: 'pending', category: 'providers' }, { id: 'summary', name: 'Zusammenfassung', icon: '📊', status: 'pending' }, ] const EDUCATION_CONTENT: Record = { 'welcome': { title: 'Willkommen zum LLM Compare Wizard', content: [ 'Large Language Models (LLMs) sind das Herzstueck moderner KI.', '', 'BreakPilot unterstuetzt mehrere Provider:', '• OpenAI: GPT-4o, GPT-4, GPT-3.5-turbo', '• Anthropic: Claude 3.5 Sonnet, Claude 3 Opus', '• Lokale Modelle: Ollama (Llama 3, Mistral)', '', 'Das LLM Gateway abstrahiert die Provider:', '• Einheitliche API fuer alle Modelle', '• Automatisches Fallback bei Ausfaellen', '• Token-Counting und Kosten-Tracking', '• Playbooks fuer vordefinierte Prompts', ], }, 'gateway': { title: 'LLM Gateway - Zentrale Schnittstelle', content: [ 'Das Gateway routet Anfragen an die passenden Provider.', '', 'Features:', '• /llm/v1/chat - Unified Chat API', '• /llm/playbooks - Vordefinierte Prompts', '• /llm/health - Provider-Status', '', 'Vorteile:', '• Provider-Wechsel ohne Code-Aenderung', '• Caching fuer haeufige Anfragen', '• Rate-Limiting pro Benutzer', '• Audit-Log aller Anfragen', '', 'Aktivierung: LLM_GATEWAY_ENABLED=true', ], }, 'providers': { title: 'LLM Provider - Modell-Auswahl', content: [ 'Verschiedene Provider fuer verschiedene Anforderungen.', '', 'OpenAI:', '• Beste allgemeine Leistung', '• Hoechste Geschwindigkeit', '• ~$0.01-0.03 pro 1K Tokens', '', 'Anthropic (Claude):', '• Beste lange Kontexte (200K)', '• Sehr sicher und aligned', '• ~$0.01-0.015 pro 1K Tokens', '', 'Ollama (Lokal):', '• Kostenlos nach Hardware', '• Volle Datenkontrolle', '• Langsamer ohne GPU', ], }, 'summary': { title: 'Test-Zusammenfassung', content: [ 'Hier sehen Sie eine Uebersicht aller durchgefuehrten Tests:', '• Gateway-Verfuegbarkeit', '• Provider-Konnektivitaet', '• Lokale LLM-Optionen', ], }, } const ARCHITECTURE_CONTEXTS: Record = { 'gateway': { layer: 'api', services: ['backend'], dependencies: ['OpenAI API', 'Anthropic API', 'Ollama'], dataFlow: ['Browser', 'FastAPI', 'LLM Gateway', 'Provider API'], }, 'providers': { layer: 'service', services: ['backend'], dependencies: ['API Keys', 'Rate Limits', 'Token Counter'], dataFlow: ['LLM Gateway', 'Provider Selection', 'API Call', 'Response'], }, } // ============================================== // Main Component // ============================================== export default function LLMCompareWizardPage() { 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/llm-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/llm-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 */}
🤖

LLM Compare Wizard

OpenAI, Anthropic & Ollama

← Zurueck zu LLM Compare
{/* 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 LLM-Integration. Bei Fragen wenden Sie sich an das KI-Team.
) }