expo-ai-kit 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build/.transforms/05637efea134638df3d3fc7b19d5dfdb/results.bin +1 -0
- package/android/build/.transforms/05637efea134638df3d3fc7b19d5dfdb/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/cd4ecc077e8795b855097bce5bf059b1/results.bin +1 -0
- package/android/build/.transforms/cd4ecc077e8795b855097bce5bf059b1/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/generated/source/buildConfig/debug/expo/modules/aikit/BuildConfig.java +10 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +7 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
- package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
- package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/build/intermediates/java_res/debug/processDebugJavaRes/out/META-INF/expo-ai-kit_debug.kotlin_module +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/expo/modules/aikit/BuildConfig.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +2 -0
- package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +7 -0
- package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +7 -0
- package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
- package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +1 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +2 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +14 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build/tmp/kotlin-classes/debug/META-INF/expo-ai-kit_debug.kotlin_module +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$11$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$streamCallback$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$3.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$4.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$5.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$6.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$AsyncFunction$7.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$10.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$11.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$12.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$3.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$4.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$5.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$6.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$7.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$8.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Coroutine$9.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Function$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$Function$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$FunctionWithoutArgs$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$FunctionWithoutArgs$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$FunctionWithoutArgs$3.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$20$$inlined$FunctionWithoutArgs$4.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$deleteModelFile$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$downloadModelFile$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$downloadModelFile$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateText$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateText$2$1$1$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateText$2$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateTextStream$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateTextStream$2$1$1$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$generateTextStream$2$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$loadModel$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$loadModel$2$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient$unloadModel$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/GemmaInferenceClient.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient.class +0 -0
- package/android/build.gradle +11 -2
- package/android/src/main/java/expo/modules/aikit/ExpoAiKitModule.kt +2 -2
- package/android/src/main/java/expo/modules/aikit/GemmaInferenceClient.kt +146 -32
- package/build/ExpoAiKitModule.d.ts +1 -1
- package/build/ExpoAiKitModule.d.ts.map +1 -1
- package/build/ExpoAiKitModule.js.map +1 -1
- package/build/index.d.ts +4 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -2
- package/build/index.js.map +1 -1
- package/build/models.d.ts.map +1 -1
- package/build/models.js +2 -4
- package/build/models.js.map +1 -1
- package/build/types.d.ts +15 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/package.json +1 -1
- package/src/ExpoAiKitModule.ts +1 -1
- package/src/index.ts +8 -2
- package/src/models.ts +2 -4
- package/src/types.ts +17 -0
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
package expo.modules.aikit
|
|
2
2
|
|
|
3
|
+
import android.app.ActivityManager
|
|
3
4
|
import android.content.Context
|
|
4
5
|
import com.google.ai.edge.litertlm.Engine
|
|
5
6
|
import com.google.ai.edge.litertlm.EngineConfig
|
|
6
7
|
import com.google.ai.edge.litertlm.Conversation
|
|
8
|
+
import com.google.ai.edge.litertlm.ConversationConfig
|
|
7
9
|
import com.google.ai.edge.litertlm.Backend
|
|
10
|
+
import com.google.ai.edge.litertlm.Message
|
|
11
|
+
import com.google.ai.edge.litertlm.MessageCallback
|
|
12
|
+
import com.google.ai.edge.litertlm.Contents
|
|
8
13
|
import kotlinx.coroutines.Dispatchers
|
|
9
14
|
import kotlinx.coroutines.sync.Mutex
|
|
10
15
|
import kotlinx.coroutines.sync.withLock
|
|
11
16
|
import kotlinx.coroutines.withContext
|
|
17
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
12
18
|
import java.io.File
|
|
13
19
|
import java.io.FileInputStream
|
|
14
20
|
import java.io.FileOutputStream
|
|
@@ -16,6 +22,8 @@ import java.io.IOException
|
|
|
16
22
|
import java.net.HttpURLConnection
|
|
17
23
|
import java.net.URL
|
|
18
24
|
import java.security.MessageDigest
|
|
25
|
+
import kotlin.coroutines.resume
|
|
26
|
+
import kotlin.coroutines.resumeWithException
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* Wrapper around LiteRT-LM Engine for Gemma 4 models.
|
|
@@ -46,7 +54,7 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
46
54
|
* Unloads any previously loaded model first.
|
|
47
55
|
* Caller is responsible for emitting onModelStateChange events.
|
|
48
56
|
*/
|
|
49
|
-
suspend fun loadModel(modelId: String, modelPath: String) = mutex.withLock {
|
|
57
|
+
suspend fun loadModel(modelId: String, modelPath: String, minRamBytes: Long = 0, backend: String = "auto") = mutex.withLock {
|
|
50
58
|
// Unload previous model if different
|
|
51
59
|
if (loadedModelId != null && loadedModelId != modelId) {
|
|
52
60
|
conversation?.close()
|
|
@@ -60,15 +68,56 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
60
68
|
return@withLock // Already loaded
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
// Soft memory check. LiteRT-LM memory-maps model weights so actual RSS
|
|
72
|
+
// is much lower than file size. We log a warning but always attempt the
|
|
73
|
+
// load — Engine.initialize() may still succeed. If it truly OOMs, Android's
|
|
74
|
+
// lmkd kills the process (uncatchable signal 9), but that's better than
|
|
75
|
+
// blocking devices that could have worked.
|
|
76
|
+
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager
|
|
77
|
+
if (activityManager != null && minRamBytes > 0) {
|
|
78
|
+
val memInfo = ActivityManager.MemoryInfo()
|
|
79
|
+
activityManager.getMemoryInfo(memInfo)
|
|
80
|
+
if (memInfo.availMem < minRamBytes) {
|
|
81
|
+
android.util.Log.w("ExpoAiKit",
|
|
82
|
+
"Low memory warning for $modelId: " +
|
|
83
|
+
"available ${memInfo.availMem / 1_000_000}MB, recommended ${minRamBytes / 1_000_000}MB. " +
|
|
84
|
+
"Attempting load anyway (LiteRT-LM uses memory-mapped I/O)."
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
63
89
|
try {
|
|
64
90
|
withContext(Dispatchers.IO) {
|
|
65
|
-
val
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
91
|
+
val newEngine = when (backend) {
|
|
92
|
+
"gpu" -> {
|
|
93
|
+
val config = EngineConfig(modelPath = modelPath, backend = Backend.GPU())
|
|
94
|
+
val eng = Engine(config)
|
|
95
|
+
eng.initialize()
|
|
96
|
+
eng
|
|
97
|
+
}
|
|
98
|
+
"cpu" -> {
|
|
99
|
+
val config = EngineConfig(modelPath = modelPath, backend = Backend.CPU())
|
|
100
|
+
val eng = Engine(config)
|
|
101
|
+
eng.initialize()
|
|
102
|
+
eng
|
|
103
|
+
}
|
|
104
|
+
else -> {
|
|
105
|
+
// "auto": try GPU first, fall back to CPU
|
|
106
|
+
try {
|
|
107
|
+
val gpuConfig = EngineConfig(modelPath = modelPath, backend = Backend.GPU())
|
|
108
|
+
val eng = Engine(gpuConfig)
|
|
109
|
+
eng.initialize()
|
|
110
|
+
eng
|
|
111
|
+
} catch (e: Exception) {
|
|
112
|
+
val cpuConfig = EngineConfig(modelPath = modelPath, backend = Backend.CPU())
|
|
113
|
+
val eng = Engine(cpuConfig)
|
|
114
|
+
eng.initialize()
|
|
115
|
+
eng
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
val newConversation = newEngine.createConversation(ConversationConfig())
|
|
72
121
|
|
|
73
122
|
engine = newEngine
|
|
74
123
|
conversation = newConversation
|
|
@@ -122,7 +171,25 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
122
171
|
|
|
123
172
|
try {
|
|
124
173
|
withContext(Dispatchers.IO) {
|
|
125
|
-
|
|
174
|
+
suspendCancellableCoroutine<String> { continuation ->
|
|
175
|
+
val result = StringBuilder()
|
|
176
|
+
conv.sendMessageAsync(
|
|
177
|
+
Contents.of(fullPrompt),
|
|
178
|
+
object : MessageCallback {
|
|
179
|
+
override fun onMessage(message: Message) {
|
|
180
|
+
result.clear()
|
|
181
|
+
result.append(message.toString())
|
|
182
|
+
}
|
|
183
|
+
override fun onDone() {
|
|
184
|
+
continuation.resume(result.toString())
|
|
185
|
+
}
|
|
186
|
+
override fun onError(throwable: Throwable) {
|
|
187
|
+
continuation.resumeWithException(throwable)
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
emptyMap()
|
|
191
|
+
)
|
|
192
|
+
}
|
|
126
193
|
}
|
|
127
194
|
} catch (e: OutOfMemoryError) {
|
|
128
195
|
throw RuntimeException("INFERENCE_OOM:${loadedModelId ?: "unknown"}:Out of memory during inference")
|
|
@@ -135,7 +202,7 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
135
202
|
* Generate a streaming response. The onChunk callback receives
|
|
136
203
|
* (token=delta, accumulatedText=full, isDone) matching the PromptApiClient contract.
|
|
137
204
|
*
|
|
138
|
-
* LiteRT-LM
|
|
205
|
+
* LiteRT-LM 0.10.0 uses a MessageCallback interface. Each onMessage emission
|
|
139
206
|
* contains accumulated text, so we diff against previousText to extract
|
|
140
207
|
* the delta token.
|
|
141
208
|
*/
|
|
@@ -151,21 +218,32 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
151
218
|
|
|
152
219
|
try {
|
|
153
220
|
withContext(Dispatchers.IO) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
221
|
+
suspendCancellableCoroutine<Unit> { continuation ->
|
|
222
|
+
var previousText = ""
|
|
223
|
+
conv.sendMessageAsync(
|
|
224
|
+
Contents.of(fullPrompt),
|
|
225
|
+
object : MessageCallback {
|
|
226
|
+
override fun onMessage(message: Message) {
|
|
227
|
+
val accumulated = message.toString()
|
|
228
|
+
val token = if (accumulated.length > previousText.length) {
|
|
229
|
+
accumulated.substring(previousText.length)
|
|
230
|
+
} else {
|
|
231
|
+
""
|
|
232
|
+
}
|
|
233
|
+
previousText = accumulated
|
|
234
|
+
onChunk(token, accumulated, false)
|
|
235
|
+
}
|
|
236
|
+
override fun onDone() {
|
|
237
|
+
onChunk("", previousText, true)
|
|
238
|
+
continuation.resume(Unit)
|
|
239
|
+
}
|
|
240
|
+
override fun onError(throwable: Throwable) {
|
|
241
|
+
continuation.resumeWithException(throwable)
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
emptyMap()
|
|
245
|
+
)
|
|
165
246
|
}
|
|
166
|
-
|
|
167
|
-
// Final done event for consistency with PromptApiClient
|
|
168
|
-
onChunk("", previousText, true)
|
|
169
247
|
}
|
|
170
248
|
} catch (e: OutOfMemoryError) {
|
|
171
249
|
throw RuntimeException("INFERENCE_OOM:${loadedModelId ?: "unknown"}:Out of memory during inference")
|
|
@@ -205,14 +283,7 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
205
283
|
val tempFile = File(modelsDir, "$modelId.litertlm.tmp")
|
|
206
284
|
|
|
207
285
|
try {
|
|
208
|
-
val connection =
|
|
209
|
-
connection.connectTimeout = 30_000
|
|
210
|
-
connection.readTimeout = 30_000
|
|
211
|
-
connection.connect()
|
|
212
|
-
|
|
213
|
-
if (connection.responseCode != HttpURLConnection.HTTP_OK) {
|
|
214
|
-
throw IOException("HTTP ${connection.responseCode}: ${connection.responseMessage}")
|
|
215
|
-
}
|
|
286
|
+
val connection = openConnectionFollowingRedirects(url)
|
|
216
287
|
|
|
217
288
|
val totalBytes = connection.contentLengthLong
|
|
218
289
|
var bytesRead = 0L
|
|
@@ -312,6 +383,49 @@ class GemmaInferenceClient(private val context: Context) {
|
|
|
312
383
|
}
|
|
313
384
|
}
|
|
314
385
|
|
|
386
|
+
/**
|
|
387
|
+
* Open an HTTP connection, manually following up to 5 redirects across hosts.
|
|
388
|
+
*
|
|
389
|
+
* HttpURLConnection follows redirects by default but only within the same host.
|
|
390
|
+
* HuggingFace LFS redirects from huggingface.co to cdn-lfs-us-1.huggingface.co,
|
|
391
|
+
* which is a cross-host redirect that HttpURLConnection silently does NOT follow —
|
|
392
|
+
* it returns the 302 response as-is (or on some Android versions, returns a small
|
|
393
|
+
* HTML/error body instead of the actual file). This caused downloaded model files
|
|
394
|
+
* to contain garbage instead of the real model weights.
|
|
395
|
+
*/
|
|
396
|
+
private fun openConnectionFollowingRedirects(url: String): HttpURLConnection {
|
|
397
|
+
var currentUrl = url
|
|
398
|
+
var redirects = 0
|
|
399
|
+
while (true) {
|
|
400
|
+
val connection = URL(currentUrl).openConnection() as HttpURLConnection
|
|
401
|
+
connection.connectTimeout = 30_000
|
|
402
|
+
connection.readTimeout = 30_000
|
|
403
|
+
connection.instanceFollowRedirects = false
|
|
404
|
+
connection.connect()
|
|
405
|
+
|
|
406
|
+
val code = connection.responseCode
|
|
407
|
+
if (code in listOf(
|
|
408
|
+
HttpURLConnection.HTTP_MOVED_PERM,
|
|
409
|
+
HttpURLConnection.HTTP_MOVED_TEMP,
|
|
410
|
+
HttpURLConnection.HTTP_SEE_OTHER,
|
|
411
|
+
307, 308
|
|
412
|
+
)) {
|
|
413
|
+
val location = connection.getHeaderField("Location")
|
|
414
|
+
?: throw IOException("Redirect with no Location header")
|
|
415
|
+
connection.disconnect()
|
|
416
|
+
redirects++
|
|
417
|
+
if (redirects > 5) throw IOException("Too many redirects")
|
|
418
|
+
currentUrl = location
|
|
419
|
+
continue
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (code != HttpURLConnection.HTTP_OK) {
|
|
423
|
+
throw IOException("HTTP $code: ${connection.responseMessage}")
|
|
424
|
+
}
|
|
425
|
+
return connection
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
315
429
|
private fun computeSha256(file: File): String {
|
|
316
430
|
val digest = MessageDigest.getInstance("SHA-256")
|
|
317
431
|
FileInputStream(file).use { fis ->
|
|
@@ -13,7 +13,7 @@ export interface ExpoAiKitNativeModule {
|
|
|
13
13
|
getBuiltInModels(): BuiltInModel[];
|
|
14
14
|
getDownloadableModelStatus(modelId: string): DownloadableModelStatus;
|
|
15
15
|
getDeviceRamBytes(): number;
|
|
16
|
-
setModel(modelId: string): Promise<void>;
|
|
16
|
+
setModel(modelId: string, minRamBytes: number, backend: string): Promise<void>;
|
|
17
17
|
getActiveModel(): string;
|
|
18
18
|
unloadModel(): Promise<void>;
|
|
19
19
|
downloadModel(modelId: string, url: string, sha256: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAiKitModule.d.ts","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,UAAU,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,kBAAkB,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAChE,kBAAkB,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF,MAAM,WAAW,qBAAqB;I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QAAQ,EAAE,UAAU,EAAE,EACtB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGhD,gBAAgB,IAAI,YAAY,EAAE,CAAC;IACnC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAAC;IACrE,iBAAiB,IAAI,MAAM,CAAC;IAK5B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,cAAc,IAAI,MAAM,CAAC;IAGzB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAG7B,aAAa,CACX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG5C,WAAW,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC/C,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,GACjC,iBAAiB,CAAC;CACtB;AAED,QAAA,MAAM,eAAe,uBACoC,CAAC;AAE1D,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAiKitModule.js","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA6DxD,MAAM,eAAe,GACnB,mBAAmB,CAAwB,WAAW,CAAC,CAAC;AAE1D,eAAe,eAAe,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nimport type { EventSubscription } from 'expo-modules-core';\nimport {\n LLMMessage,\n LLMResponse,\n LLMStreamEvent,\n BuiltInModel,\n DownloadableModelStatus,\n ModelDownloadProgressEvent,\n ModelStateChangeEvent,\n} from './types';\n\nexport type ExpoAiKitModuleEvents = {\n onStreamToken: (event: LLMStreamEvent) => void;\n onDownloadProgress: (event: ModelDownloadProgressEvent) => void;\n onModelStateChange: (event: ModelStateChangeEvent) => void;\n};\n\nexport interface ExpoAiKitNativeModule {\n // Existing inference API\n isAvailable(): boolean;\n sendMessage(\n messages: LLMMessage[],\n systemPrompt: string\n ): Promise<LLMResponse>;\n startStreaming(\n messages: LLMMessage[],\n systemPrompt: string,\n sessionId: string\n ): Promise<void>;\n stopStreaming(sessionId: string): Promise<void>;\n\n // Model discovery\n getBuiltInModels(): BuiltInModel[];\n getDownloadableModelStatus(modelId: string): DownloadableModelStatus;\n getDeviceRamBytes(): number;\n\n // Model selection & memory management\n // setModel is async: switching to a downloadable model loads it into memory.\n // Auto-unloads the previous downloadable model (only one loaded at a time).\n setModel(modelId: string): Promise<void>;\n getActiveModel(): string;\n // Explicitly free memory from the loaded downloadable model.\n // Reverts to the platform built-in model.\n unloadModel(): Promise<void>;\n\n // Model lifecycle (downloadable models only)\n downloadModel(\n modelId: string,\n url: string,\n sha256: string\n ): Promise<void>;\n deleteModel(modelId: string): Promise<void>;\n\n // Event subscription\n addListener<K extends keyof ExpoAiKitModuleEvents>(\n eventName: K,\n listener: ExpoAiKitModuleEvents[K]\n ): EventSubscription;\n}\n\nconst ExpoAiKitModule =\n requireNativeModule<ExpoAiKitNativeModule>('ExpoAiKit');\n\nexport default ExpoAiKitModule;\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoAiKitModule.js","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA6DxD,MAAM,eAAe,GACnB,mBAAmB,CAAwB,WAAW,CAAC,CAAC;AAE1D,eAAe,eAAe,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nimport type { EventSubscription } from 'expo-modules-core';\nimport {\n LLMMessage,\n LLMResponse,\n LLMStreamEvent,\n BuiltInModel,\n DownloadableModelStatus,\n ModelDownloadProgressEvent,\n ModelStateChangeEvent,\n} from './types';\n\nexport type ExpoAiKitModuleEvents = {\n onStreamToken: (event: LLMStreamEvent) => void;\n onDownloadProgress: (event: ModelDownloadProgressEvent) => void;\n onModelStateChange: (event: ModelStateChangeEvent) => void;\n};\n\nexport interface ExpoAiKitNativeModule {\n // Existing inference API\n isAvailable(): boolean;\n sendMessage(\n messages: LLMMessage[],\n systemPrompt: string\n ): Promise<LLMResponse>;\n startStreaming(\n messages: LLMMessage[],\n systemPrompt: string,\n sessionId: string\n ): Promise<void>;\n stopStreaming(sessionId: string): Promise<void>;\n\n // Model discovery\n getBuiltInModels(): BuiltInModel[];\n getDownloadableModelStatus(modelId: string): DownloadableModelStatus;\n getDeviceRamBytes(): number;\n\n // Model selection & memory management\n // setModel is async: switching to a downloadable model loads it into memory.\n // Auto-unloads the previous downloadable model (only one loaded at a time).\n setModel(modelId: string, minRamBytes: number, backend: string): Promise<void>;\n getActiveModel(): string;\n // Explicitly free memory from the loaded downloadable model.\n // Reverts to the platform built-in model.\n unloadModel(): Promise<void>;\n\n // Model lifecycle (downloadable models only)\n downloadModel(\n modelId: string,\n url: string,\n sha256: string\n ): Promise<void>;\n deleteModel(modelId: string): Promise<void>;\n\n // Event subscription\n addListener<K extends keyof ExpoAiKitModuleEvents>(\n eventName: K,\n listener: ExpoAiKitModuleEvents[K]\n ): EventSubscription;\n}\n\nconst ExpoAiKitModule =\n requireNativeModule<ExpoAiKitNativeModule>('ExpoAiKit');\n\nexport default ExpoAiKitModule;\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LLMMessage, LLMSendOptions, LLMResponse, LLMStreamOptions, LLMStreamCallback, LLMSummarizeOptions, LLMTranslateOptions, LLMRewriteOptions, LLMExtractKeyPointsOptions, LLMAnswerQuestionOptions, LLMSuggestOptions, LLMSuggestResponse, LLMSmartReplyOptions, LLMAutocompleteOptions, BuiltInModel, DownloadableModel } from './types';
|
|
1
|
+
import { LLMMessage, LLMSendOptions, LLMResponse, LLMStreamOptions, LLMStreamCallback, LLMSummarizeOptions, LLMTranslateOptions, LLMRewriteOptions, LLMExtractKeyPointsOptions, LLMAnswerQuestionOptions, LLMSuggestOptions, LLMSuggestResponse, LLMSmartReplyOptions, LLMAutocompleteOptions, BuiltInModel, DownloadableModel, SetModelOptions } from './types';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export * from './memory';
|
|
4
4
|
export * from './hooks';
|
|
@@ -575,12 +575,14 @@ export declare function deleteModel(modelId: string): Promise<void>;
|
|
|
575
575
|
* model (today's behavior, no error).
|
|
576
576
|
*
|
|
577
577
|
* @param modelId - ID of the model to activate (e.g. 'gemma-e2b', 'apple-fm', 'mlkit')
|
|
578
|
+
* @param options - Optional configuration for model loading
|
|
579
|
+
* @param options.backend - Hardware backend: 'auto' (default, GPU with CPU fallback), 'gpu', or 'cpu'
|
|
578
580
|
* @throws {ModelError} MODEL_NOT_FOUND if modelId is invalid
|
|
579
581
|
* @throws {ModelError} MODEL_NOT_DOWNLOADED if the downloadable model file is not on disk
|
|
580
582
|
* @throws {ModelError} MODEL_LOAD_FAILED if loading into memory fails
|
|
581
583
|
* @throws {ModelError} INFERENCE_OOM if device can't fit model in memory
|
|
582
584
|
*/
|
|
583
|
-
export declare function setModel(modelId: string): Promise<void>;
|
|
585
|
+
export declare function setModel(modelId: string, options?: SetModelOptions): Promise<void>;
|
|
584
586
|
/**
|
|
585
587
|
* Get the ID of the currently active model.
|
|
586
588
|
*
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAA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,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAEjD"}
|
package/build/index.js
CHANGED
|
@@ -1024,13 +1024,18 @@ export async function deleteModel(modelId) {
|
|
|
1024
1024
|
* model (today's behavior, no error).
|
|
1025
1025
|
*
|
|
1026
1026
|
* @param modelId - ID of the model to activate (e.g. 'gemma-e2b', 'apple-fm', 'mlkit')
|
|
1027
|
+
* @param options - Optional configuration for model loading
|
|
1028
|
+
* @param options.backend - Hardware backend: 'auto' (default, GPU with CPU fallback), 'gpu', or 'cpu'
|
|
1027
1029
|
* @throws {ModelError} MODEL_NOT_FOUND if modelId is invalid
|
|
1028
1030
|
* @throws {ModelError} MODEL_NOT_DOWNLOADED if the downloadable model file is not on disk
|
|
1029
1031
|
* @throws {ModelError} MODEL_LOAD_FAILED if loading into memory fails
|
|
1030
1032
|
* @throws {ModelError} INFERENCE_OOM if device can't fit model in memory
|
|
1031
1033
|
*/
|
|
1032
|
-
export async function setModel(modelId) {
|
|
1033
|
-
|
|
1034
|
+
export async function setModel(modelId, options) {
|
|
1035
|
+
const entry = getRegistryEntry(modelId);
|
|
1036
|
+
const minRamBytes = entry?.minRamBytes ?? 0;
|
|
1037
|
+
const backend = options?.backend ?? 'auto';
|
|
1038
|
+
await ExpoAiKitModule.setModel(modelId, minRamBytes, backend);
|
|
1034
1039
|
}
|
|
1035
1040
|
/**
|
|
1036
1041
|
* Get the ID of the currently active model.
|