({ isVisible })
| 51 | }; |
| 52 | |
| 53 | const BenchmarkPanel: React.FC<BenchmarkPanelProps> = ({ isVisible }) => { |
| 54 | // Conversation state |
| 55 | interface ChatMessage { |
| 56 | role: 'user' | 'assistant'; |
| 57 | text: string; |
| 58 | image?: string; |
| 59 | metrics?: GenerationMetrics | null; |
| 60 | error?: boolean; |
| 61 | } |
| 62 | const [messages, setMessages] = useState<ChatMessage[]>([]); |
| 63 | const [input, setInput] = useState(''); |
| 64 | const [isGenerating, setIsGenerating] = useState(false); |
| 65 | const [capturedImage, setCapturedImage] = useState<string | null>(null); |
| 66 | const fileInputRef = useRef<HTMLInputElement>(null); |
| 67 | const scrollRef = useRef<HTMLDivElement>(null); |
| 68 | |
| 69 | // Backend detection state |
| 70 | const [backendInfo, setBackendInfo] = useState<BackendInfo>({ backend: null, modelName: '', isMultimodal: false }); |
| 71 | |
| 72 | const abortControllerRef = useRef<AbortController | null>(null); |
| 73 | |
| 74 | // Detect which backend has a loaded model |
| 75 | const detectActiveBackend = useCallback((): BackendInfo => { |
| 76 | // Check llama.cpp (Tauri only) |
| 77 | if (isTauri()) { |
| 78 | const nativeState = NativeLlmManager.getInstance().getState(); |
| 79 | if (nativeState.status === 'loaded' && nativeState.modelId) { |
| 80 | return { |
| 81 | backend: 'llamacpp', |
| 82 | modelName: nativeState.modelId, |
| 83 | isMultimodal: true, // Assume multimodal if mmproj might be loaded |
| 84 | }; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Check Transformers.js |
| 89 | const gemmaState = GemmaModelManager.getInstance().getState(); |
| 90 | if (gemmaState.status === 'loaded' && gemmaState.modelId) { |
| 91 | return { |
| 92 | backend: 'transformers', |
| 93 | modelName: GEMMA_DISPLAY_NAMES[gemmaState.modelId as GemmaModelId] || gemmaState.modelId, |
| 94 | isMultimodal: true, |
| 95 | }; |
| 96 | } |
| 97 | |
| 98 | // TODO: Check Ollama when we have an OllamaManager |
| 99 | |
| 100 | return { backend: null, modelName: '', isMultimodal: false }; |
| 101 | }, []); |
| 102 | |
| 103 | // Subscribe to state changes from both managers |
| 104 | useEffect(() => { |
| 105 | if (!isVisible) return; |
| 106 | |
| 107 | // Initial detection |
| 108 | setBackendInfo(detectActiveBackend()); |
| 109 | |
| 110 | // Get initial states |
nothing calls this directly
no test coverage detected