diff --git a/apps/easypid/src/app/_layout.tsx b/apps/easypid/src/app/_layout.tsx index 9480c6d2..da05c8dc 100644 --- a/apps/easypid/src/app/_layout.tsx +++ b/apps/easypid/src/app/_layout.tsx @@ -6,7 +6,7 @@ import { DefaultTheme, ThemeProvider } from '@react-navigation/native' import { Slot } from 'expo-router' import * as SplashScreen from 'expo-splash-screen' -import { useCheckIncompleteDownload } from '@easypid/llm/useLLM' +import { useCheckIncompleteDownload } from '@easypid/llm' import tamaguiConfig from '../../tamagui.config' void SplashScreen.preventAutoHideAsync() diff --git a/apps/easypid/src/features/menu/components/LocalAiContainer.tsx b/apps/easypid/src/features/menu/components/LocalAiContainer.tsx index a23f01e5..0eac525b 100644 --- a/apps/easypid/src/features/menu/components/LocalAiContainer.tsx +++ b/apps/easypid/src/features/menu/components/LocalAiContainer.tsx @@ -2,7 +2,7 @@ import { HeroIcons } from '@package/ui/src/content/Icon' import { Switch } from '@package/ui/src/base/Switch' -import { useIsDeviceCapable, useLLM } from '@easypid/llm/useLLM' +import { useIsDeviceCapable, useLLM } from '@easypid/llm' import { ConfirmationSheet } from '@package/app/src/components/ConfirmationSheet' import { useHasInternetConnection, useIsConnectedToWifi } from 'packages/app/src/hooks' import { useToastController } from 'packages/ui/src' diff --git a/apps/easypid/src/hooks/useOverAskingAi.tsx b/apps/easypid/src/hooks/useOverAskingAi.tsx index e8feb25b..825a3708 100644 --- a/apps/easypid/src/hooks/useOverAskingAi.tsx +++ b/apps/easypid/src/hooks/useOverAskingAi.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react' -import { useLLM } from '@easypid/llm/useLLM' +import { useLLM } from '@easypid/llm' import type { OverAskingInput, OverAskingResponse } from '@easypid/use-cases/OverAskingApi' import { checkForOverAskingApi as analyzeVerificationApi } from '@easypid/use-cases/OverAskingApi' diff --git a/apps/easypid/src/llm/index.ts b/apps/easypid/src/llm/index.ts new file mode 100644 index 00000000..6684c967 --- /dev/null +++ b/apps/easypid/src/llm/index.ts @@ -0,0 +1,3 @@ +export * from './useLLM' +export * from './state' +export * from './types' diff --git a/apps/easypid/src/llm/state.ts b/apps/easypid/src/llm/state.ts new file mode 100644 index 00000000..39ef5cf2 --- /dev/null +++ b/apps/easypid/src/llm/state.ts @@ -0,0 +1,27 @@ +import { useMMKVBoolean } from 'react-native-mmkv' + +import { mmkv } from '@easypid/storage/mmkv' + +export function useIsModelReady() { + return useMMKVBoolean('isModelReady', mmkv) +} + +export function removeIsModelReady() { + mmkv.delete('isModelReady') +} + +export function useIsModelActivated() { + return useMMKVBoolean('isModelActivated', mmkv) +} + +export function removeIsModelActivated() { + mmkv.delete('isModelActivated') +} + +export function useIsModelDownloading() { + return useMMKVBoolean('isModelDownloading', mmkv) +} + +export function removeIsModelDownloading() { + mmkv.delete('isModelDownloading') +} diff --git a/apps/easypid/src/llm/useLLM.tsx b/apps/easypid/src/llm/useLLM.tsx index 65e2fbe3..3e1312da 100644 --- a/apps/easypid/src/llm/useLLM.tsx +++ b/apps/easypid/src/llm/useLLM.tsx @@ -1,40 +1,22 @@ -import { mmkv } from '@easypid/storage/mmkv' import { useCallback, useEffect, useRef, useState } from 'react' import { Platform } from 'react-native' import { LLAMA3_2_1B_QLORA_URL, LLAMA3_2_1B_TOKENIZER } from 'react-native-executorch' -import { useMMKVBoolean } from 'react-native-mmkv' import RnExecutorch, { subscribeToDownloadProgress, subscribeToTokenGenerated } from './RnExecutorchModule' import { DEFAULT_CONTEXT_WINDOW_LENGTH, EOT_TOKEN } from './constants' +import { + removeIsModelActivated, + removeIsModelDownloading, + removeIsModelReady, + useIsModelActivated, + useIsModelDownloading, + useIsModelReady, +} from './state' import type { Model, ResourceSource } from './types' const interrupt = () => { RnExecutorch.interrupt() } -export function useIsModelReady() { - return useMMKVBoolean('isModelReady', mmkv) -} - -export function removeIsModelReady() { - mmkv.delete('isModelReady') -} - -export function useIsModelActivated() { - return useMMKVBoolean('isModelActivated', mmkv) -} - -export function removeIsModelActivated() { - mmkv.delete('isModelActivated') -} - -export function useIsModelDownloading() { - return useMMKVBoolean('isModelDownloading', mmkv) -} - -export function removeIsModelDownloading() { - mmkv.delete('isModelDownloading') -} - export const useLLM = ({ modelSource = LLAMA3_2_1B_QLORA_URL, tokenizerSource = LLAMA3_2_1B_TOKENIZER,