fix: add frontend/src/lib/ to git (was ignored by /lib/ pattern)
The root .gitignore had `lib/` which matched frontend/src/lib/, causing Docker build to fail with "Module not found: Can't resolve '@/lib/utils'" and '@/lib/i18n'. Changed to `/lib/` so it only ignores the Python lib at repo root. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
46
frontend/src/lib/webllm.ts
Normal file
46
frontend/src/lib/webllm.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { useState, useCallback } from "react";
|
||||
|
||||
interface WebLLMState {
|
||||
isLoaded: boolean;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export function useWebLLM() {
|
||||
const [state, setState] = useState<WebLLMState>({
|
||||
isLoaded: false,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
|
||||
const isWebGPUSupported = useCallback(() => {
|
||||
if (typeof navigator === "undefined") return false;
|
||||
return "gpu" in navigator;
|
||||
}, []);
|
||||
|
||||
const translate = useCallback(
|
||||
async (
|
||||
_text: string,
|
||||
_targetLang: string,
|
||||
_systemPrompt?: string,
|
||||
_glossary?: string,
|
||||
): Promise<string> => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
throw new Error("WebLLM is not available in this environment");
|
||||
} catch (err) {
|
||||
const message =
|
||||
err instanceof Error ? err.message : "WebLLM translation failed";
|
||||
setState((s) => ({ ...s, loading: false, error: message }));
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
isWebGPUSupported,
|
||||
translate,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user