Spaces:
No application file
No application file
Download frontend/src/hooks/useAIAdaptation.ts from dimensionalpulsar/adn: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/dimensionalpulsar/adn/resolve/main/frontend/src/hooks/useAIAdaptation.ts
- Command line
-
hf download hf://spaces/dimensionalpulsar/adn/frontend/src/hooks/useAIAdaptation.ts
-
curl -L -o useAIAdaptation.ts https://huggingface.co/spaces/dimensionalpulsar/adn/resolve/main/frontend/src/hooks/useAIAdaptation.ts
1.27 kB
| import { useEffect } from 'react'; | |
| import axios from 'axios'; | |
| import { useStore } from '../store'; | |
| // Debounce helper | |
| let debounceTimer: ReturnType<typeof setTimeout>; | |
| export function useAIAdaptation() { | |
| const { | |
| waveAmplitude, temperature, waveExpansion, finScale, | |
| setAIResult, setLoadingAI, setFluidField, | |
| } = useStore(); | |
| // Call /api/adapt-fins whenever ocean parameters change (debounced 1.5s) | |
| useEffect(() => { | |
| clearTimeout(debounceTimer); | |
| debounceTimer = setTimeout(async () => { | |
| setLoadingAI(true); | |
| try { | |
| const [finRes, fluidRes] = await Promise.all([ | |
| axios.post('/api/adapt-fins', { | |
| waveAmplitude, | |
| temperature, | |
| waveExpansion, | |
| currentFinScale: finScale, | |
| }), | |
| axios.post('/api/fluid-state', { | |
| waveAmplitude, | |
| waveExpansion, | |
| time: Date.now() / 1000, | |
| }), | |
| ]); | |
| setAIResult(finRes.data); | |
| setFluidField(fluidRes.data.field); | |
| } catch (err) { | |
| console.warn('AI adaptation error:', err); | |
| } finally { | |
| setLoadingAI(false); | |
| } | |
| }, 1500); | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [waveAmplitude, temperature, waveExpansion]); | |
| } | |