-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: experimental local ai model #254
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6fb2a0e
feat: working version
janrtvld 821d4a1
feat: warnings
janrtvld 0ad3f72
feat: clean up
janrtvld 02fccbf
chore: refactor
janrtvld 050d209
fix: types
janrtvld 6f306ef
feat: added expo device info
janrtvld 592e784
feat: performance improvements
janrtvld 7c8c971
Merge branch 'main' into feat/local-ai
janrtvld 06b15ec
chore: make error scrollable
janrtvld 87902fc
chore: spacing
janrtvld 54b694f
chore: comment
janrtvld a5d285c
fix: stricter reqs
janrtvld 281faf5
chore: changelog entry
janrtvld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
apps/easypid/src/features/menu/components/LocalAiContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { HeroIcons } from '@package/ui/src/content/Icon' | ||
|
||
import { Switch } from '@package/ui/src/base/Switch' | ||
|
||
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' | ||
import React, { useState } from 'react' | ||
|
||
export function LocalAiContainer() { | ||
const toast = useToastController() | ||
const isConnectedToWifi = useIsConnectedToWifi() | ||
const hasInternetConnection = useHasInternetConnection() | ||
const isDeviceCapable = useIsDeviceCapable() | ||
|
||
const [isAiModelConfirmationOpen, setIsAiModelConfirmationOpen] = useState(false) | ||
const { loadModel, isModelReady, downloadProgress, removeModel, isModelActivated, isModelDownloading } = useLLM() | ||
|
||
const onActivateModel = () => { | ||
if (!isDeviceCapable) { | ||
toast.show('Device not supported', { | ||
message: 'This device is not powerful enough to run local AI models', | ||
customData: { | ||
preset: 'warning', | ||
}, | ||
}) | ||
setIsAiModelConfirmationOpen(false) | ||
return | ||
} | ||
if (!isConnectedToWifi && !hasInternetConnection) { | ||
toast.show('WiFi connection required', { | ||
message: 'Please connect to WiFi to activate and download the model', | ||
customData: { | ||
preset: 'warning', | ||
}, | ||
}) | ||
setIsAiModelConfirmationOpen(false) | ||
return | ||
} | ||
|
||
setIsAiModelConfirmationOpen(false) | ||
loadModel() | ||
} | ||
|
||
const handleAiModelChange = (value: boolean) => { | ||
if (isModelDownloading) { | ||
toast.show('Model download in progress', { | ||
message: 'Force close the app to cancel the download', | ||
customData: { | ||
preset: 'warning', | ||
}, | ||
}) | ||
return | ||
} | ||
|
||
if (value) { | ||
setIsAiModelConfirmationOpen(true) | ||
} else { | ||
removeModel() | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Switch | ||
id="local-ai-model" | ||
label="Use local AI model" | ||
icon={<HeroIcons.CpuChipFilled />} | ||
value={isModelActivated} | ||
description={ | ||
isModelActivated | ||
? isModelReady | ||
? 'Model active and ready to use' | ||
: downloadProgress | ||
? `Downloading model ${(downloadProgress * 100).toFixed(2)}%` | ||
: 'Getting ready...' | ||
: '' | ||
} | ||
onChange={handleAiModelChange} | ||
beta | ||
/> | ||
<ConfirmationSheet | ||
type="floating" | ||
variant="regular" | ||
isOpen={isAiModelConfirmationOpen} | ||
setIsOpen={setIsAiModelConfirmationOpen} | ||
title="Enable local AI model" | ||
confirmText="Enable" | ||
cancelText="Cancel" | ||
description={[ | ||
'This will download a local AI model to your device which will take up to around 1.3GB of space.', | ||
'This is an experimental feature. Only supported on high-end devices.', | ||
]} | ||
onConfirm={onActivateModel} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any thing we also need to configure in appstoreconnect?