@dvai-bridge/capacitor-llama 4.0.0

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.
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
3
+
4
+ Pod::Spec.new do |s|
5
+ s.name = 'DVAICapacitorLlama'
6
+ s.version = package['version']
7
+ s.summary = package['description']
8
+ s.license = 'Custom (See LICENSE)'
9
+ s.homepage = package['repository']['url']
10
+ s.author = package['author']
11
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
12
+ s.source_files = [
13
+ 'ios/Sources/**/*.{swift,h,m,mm}',
14
+ '../dvai-bridge-ios-llama-core/ios/Sources/**/*.{swift,h,m,mm}',
15
+ ]
16
+ s.public_header_files = '../dvai-bridge-ios-llama-core/ios/Sources/DVAILlamaCoreObjC/include/*.h'
17
+ s.ios.deployment_target = '14.0'
18
+ s.swift_version = '5.9'
19
+ s.dependency 'Capacitor'
20
+ s.dependency 'Telegraph', '~> 0.40'
21
+ end
package/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ # Deep Voice Ai Limited - Software License Agreement
2
+
3
+ **Version 1.0.0**
4
+
5
+ This License Agreement governs the use of the DVAI-Bridge software (the "Software"). By downloading, installing, or using the Software, you agree to be bound by the terms of this License.
6
+
7
+ ---
8
+
9
+ ## 1. LICENSE GRANTS
10
+
11
+ ### 1.1 Development and Personal Use (Free Tier)
12
+ Deep Voice Ai Limited ("Licensor") grants you a non-exclusive, non-transferable, royalty-free license to use the Software solely for:
13
+ - Internal development and testing purposes.
14
+ - Non-commercial personal projects.
15
+ - Academic and non-profit research.
16
+
17
+ ### 1.2 Commercial Use (Paid Tier)
18
+ Any use of the Software for **Commercial Purposes** requires a separate, paid Commercial License from Licensor. "Commercial Purposes" include:
19
+ - Use in production environments.
20
+ - Integration into revenue-generating products or services.
21
+ - Distribution to third-party customers for a fee.
22
+ - Use by an entity with more than $100,000 USD in annual revenue.
23
+
24
+ To obtain a Commercial License, contact `info@deepvoiceai.co` or visit `https://deepvoiceai.co/licensing`.
25
+
26
+ ---
27
+
28
+ ## 2. RESTRICTIONS
29
+ Except as expressly permitted, you may not:
30
+ - Sublicense, rent, lease, or resell the Software without express permission.
31
+ - Remove any proprietary notices or branding from the Software.
32
+ - Use the Software for any illegal or malicious purposes.
33
+
34
+ ---
35
+
36
+ ## 3. INTELLECTUAL PROPERTY
37
+ The Software is owned by **Deep Voice Ai Limited** and is protected by copyright and intellectual property laws. This agreement does not transfer ownership of the Software.
38
+
39
+ ---
40
+
41
+ ## 4. NO WARRANTY
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
43
+
44
+ ---
45
+
46
+ ## 5. GOVERNING LAW
47
+ This License shall be governed by and construed in accordance with the laws of the jurisdiction where Deep Voice Ai Limited is registered.
48
+
49
+ ---
50
+
51
+ © 2026 Deep Voice Ai Limited. All rights reserved.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ ![DVAI-Bridge](/assets/banner.png)
2
+
3
+ # DVAI-Bridge
4
+
5
+ <!-- [![Smoke — real models](https://github.com/Westenets/dvai-bridge/actions/workflows/smoke-real-models.yml/badge.svg?branch=main)](https://github.com/Westenets/dvai-bridge/actions/workflows/smoke-real-models.yml) -->
6
+
7
+ [![License](https://img.shields.io/badge/License-Commercial-blue.svg)](LICENSE) ![Node.js](https://img.shields.io/badge/Node.js-22+-green?logo=node.js) ![TypeScript](https://img.shields.io/badge/TypeScript-5.6+-blue?logo=typescript) ![Swift](https://img.shields.io/badge/Swift-5.9+-F05138?logo=swift) ![Kotlin](https://img.shields.io/badge/Kotlin-2.0+-7F52FF?logo=kotlin) ![Flutter](https://img.shields.io/badge/Flutter-3.39+-02569B?logo=flutter) ![.NET](https://img.shields.io/badge/.NET-10.0_LTS-512BD4?logo=dotnet)
8
+
9
+ > **The local OpenAI server you embed inside your app.**
10
+ > One library. One HTTP wire. Every platform. Zero install for your users.
11
+
12
+ **Docs:** [dvai-bridge.deepvoiceai.co](https://dvai-bridge.deepvoiceai.co)
13
+
14
+ ```ts
15
+ import { DVAI } from "@dvai-bridge/core";
16
+ import OpenAI from "openai";
17
+
18
+ const dvai = new DVAI({ backend: "transformers" });
19
+ await dvai.initialize();
20
+
21
+ const openai = new OpenAI({ baseURL: dvai.baseUrl, apiKey: "ignored" });
22
+ await openai.chat.completions.create({
23
+ model: dvai.transformersModelId,
24
+ messages: [{ role: "user", content: "Hello!" }],
25
+ });
26
+ ```
27
+
28
+ That's it. A real OpenAI-compatible server is now running inside your app's
29
+ own process. Point any OpenAI client — LangChain, the OpenAI SDK, the Vercel
30
+ AI SDK, anything — at `dvai.baseUrl` and your agent code keeps working.
31
+
32
+ Built by **[Deep Voice AI](https://deepvoiceai.co)**.
33
+
34
+ ---
35
+
36
+ ## Why it exists
37
+
38
+ Local AI works beautifully on a laptop with **Ollama + LangChain**. Then you
39
+ try to ship the app and your users don't have Ollama. Mobile can't run it.
40
+ Corporate IT won't add another daemon. So you reinvent the same plumbing —
41
+ spawn an inference engine, bind a port, translate to OpenAI HTTP, handle
42
+ CORS, manage lifecycle, wrap the accelerator of the day per platform — and
43
+ do it all over again for every target OS.
44
+
45
+ DVAI-Bridge is that plumbing, packaged as a library, for every client
46
+ platform.
47
+
48
+ ---
49
+
50
+ ## What you get
51
+
52
+ - **One OpenAI HTTP surface.** Bound on `127.0.0.1` (or `0.0.0.0` for
53
+ device-to-device). Streaming, embeddings, models, recovery — all built in.
54
+ - **Six SDKs.** `@dvai-bridge/core` + `react` + `vanilla` + `capacitor`,
55
+ `DVAIBridge` (Swift / iOS), `co.deepvoiceai:dvai-bridge` (Kotlin / Android),
56
+ `@dvai-bridge/react-native`, `dvai_bridge` (Flutter), `co.deepvoiceai.dvai-bridge` (.NET).
57
+ - **Nine backends.** WebLLM, Transformers.js, llama.cpp, Apple Foundation
58
+ Models, MLX, CoreML / ANE, MediaPipe LLM, LiteRT, ONNX Runtime GenAI —
59
+ selected per-platform, invisible to your agent code.
60
+ - **Native acceleration** wherever it runs: WebGPU in browsers, CUDA / Metal
61
+ / Vulkan / DirectML on desktop, ANE / Metal / MLX on iOS, NNAPI / QNN
62
+ Hexagon / GPU delegate on Android.
63
+ - **Multimodal.** Text, image, audio, video — declarative loader for
64
+ cutting-edge models (Gemma 4, LLaVA, Idefics) without waiting for library
65
+ updates.
66
+ - **Distributed inference (v3.0+).** Phone too slow? Offload to your laptop
67
+ on the same Wi-Fi via mDNS pairing — same OpenAI wire, transparent to
68
+ your code. Internet path via a self-hostable rendezvous server.
69
+ - **DVAI Hub (v3.1+).** A first-party desktop utility that turns any device
70
+ into a strong-peer for the rest of your fleet. Brand-neutral install via
71
+ Homebrew / winget / GitHub Releases, OR fork it for your own branded
72
+ companion. Routes through Ollama / LM Studio / vLLM / llama-server /
73
+ llamafile if you've already got those running.
74
+ - **Zero user install.** It's a library, not a daemon. `npm install`,
75
+ `cocoapods`, gradle — your CI already has the muscle for it.
76
+
77
+ ---
78
+
79
+ ## Supported platforms
80
+
81
+ | Stack | Package | Backends |
82
+ | --- | --- | --- |
83
+ | Browser (React, Vue, Svelte, vanilla JS) | `@dvai-bridge/core` + `react` / `vanilla` | WebLLM (WebGPU), Transformers.js (WebGPU / WASM SIMD) |
84
+ | Node / Bun / Electron | `@dvai-bridge/core` | Transformers.js, native llama.cpp |
85
+ | Capacitor hybrid mobile | `@dvai-bridge/capacitor` + backend slice | Native llama.cpp (Metal iOS, Vulkan / CPU Android) |
86
+ | iOS native (Swift) | `DVAIBridge` (SPM / CocoaPods) | llama.cpp (Metal), CoreML / ANE, Apple Foundation Models, MLX |
87
+ | Android native (Kotlin / Java) | `co.deepvoiceai:dvai-bridge` (AAR) | llama.cpp, MediaPipe LLM, LiteRT, NNAPI / QNN |
88
+ | React Native (≥0.77, TurboModule) | `@dvai-bridge/react-native` | All iOS + Android backends (delegates) |
89
+ | Flutter (≥3.39) | `dvai_bridge` (pub.dev) | All iOS + Android backends (Pigeon channels) |
90
+ | .NET 10 LTS (MAUI / Avalonia / WinUI / Catalyst / desktop) | `co.deepvoiceai.dvai-bridge*` (NuGet) | iOS / Android delegate to native; desktop = llama.cpp + ONNX Runtime GenAI + ML.NET |
91
+
92
+ Full quickstart per platform: [dvai-bridge.deepvoiceai.co/guide/getting-started](https://dvai-bridge.deepvoiceai.co/guide/getting-started)
93
+
94
+ ---
95
+
96
+ ## Examples
97
+
98
+ ```ts
99
+ // React
100
+ import { DVAIProvider, useDVAI } from "@dvai-bridge/react";
101
+ <DVAIProvider config={{ backend: "transformers" }}>
102
+ <Chat />
103
+ </DVAIProvider>;
104
+ function Chat() {
105
+ const { isReady, baseUrl } = useDVAI();
106
+ return isReady ? <div>Local AI live at {baseUrl}</div> : <Loading />;
107
+ }
108
+ ```
109
+
110
+ ```swift
111
+ // iOS
112
+ let server = try await DVAIBridge.shared.start()
113
+ // server.baseUrl = "http://127.0.0.1:38883/v1"
114
+ ```
115
+
116
+ ```kotlin
117
+ // Android
118
+ val server = DVAIBridge.start(context)
119
+ // server.baseUrl = "http://127.0.0.1:38883/v1"
120
+ ```
121
+
122
+ ```dart
123
+ // Flutter
124
+ final state = await DVAIBridge.instance.start(
125
+ backend: BackendKind.auto,
126
+ modelPath: '/path/to/model.gguf',
127
+ );
128
+ // state.baseUrl = "http://127.0.0.1:38883/v1"
129
+ ```
130
+
131
+ ```csharp
132
+ // .NET
133
+ var server = await DVAIBridge.Shared.StartAsync(new StartOptions {
134
+ Backend = BackendKind.Auto,
135
+ ModelPath = "/path/to/model.gguf",
136
+ });
137
+ // server.BaseUrl = "http://127.0.0.1:38883/v1"
138
+ ```
139
+
140
+ Multimodal, streaming, embeddings, distributed offload, the Hub —
141
+ everything's at the [docs site](https://dvai-bridge.deepvoiceai.co).
142
+
143
+ ---
144
+
145
+ ## What's new in v3.1
146
+
147
+ - **DVAI Hub** — Tauri desktop utility that's the strong-peer side of v3
148
+ distributed inference. `brew install deepvoiceai/dvai-hub/dvai-hub` (or
149
+ `winget install DeepVoiceAI.DVAIHub`) → mobile apps on the same Wi-Fi
150
+ pair with it and offload heavy inference. [Guide →](https://dvai-bridge.deepvoiceai.co/guide/dvai-hub)
151
+ - **External-engine bridge.** Hub surfaces Ollama / LM Studio / vLLM /
152
+ llama-server / llamafile as additional backend pools so paired apps
153
+ serve from whatever's already cached. Opt-in per engine.
154
+ - **Strict substitution policy.** Models with mismatched family / version /
155
+ size / type are refused by default; quant-only mismatches gated behind a
156
+ per-pairing `preferBetterQuant` flag. No silent mis-routing.
157
+ - **HMAC-signed identity** on `/v1/chat/completions`. Per-app audit logs
158
+ surface who served what, with structured `(appId, peerDeviceId,
159
+ engine, requestedModel, servedModel, outcome)` rows.
160
+ - **Library finalization.** `httpBindHost` (LAN bind), `chatCompletionInterceptor`
161
+ (extension point), HMAC primitives re-exported, `/v1/dvai/*` routes
162
+ actually dispatched, TransformersBackend Node-mode device fix.
163
+ [Migration v3.0 → v3.1 →](https://dvai-bridge.deepvoiceai.co/migration/v3.0-to-v3.1)
164
+
165
+ ---
166
+
167
+ ## Robustness
168
+
169
+ Streaming-correct (SSE passthrough + blank-chunk detection), generation
170
+ timeout, automatic engine-state recovery on fatal errors, port fallback,
171
+ worker offloading, Private Network Access ready, CORS configured. The
172
+ boring substrate so your agent code never has to think about it.
173
+
174
+ ---
175
+
176
+ ## Licensing
177
+
178
+ Dual: **free for development & personal use** on `localhost` (verified at
179
+ runtime). **Commercial use** requires a license key — `info@deepvoiceai.co`.
180
+
181
+ ---
182
+
183
+ ## Contributing
184
+
185
+ PRs welcome.
186
+
187
+ ```bash
188
+ pnpm install
189
+ pnpm build
190
+ bash scripts/build-all.sh # full matrix (auto-skips per-host)
191
+ ```
192
+
193
+ [`CONTRIBUTING.md`](./CONTRIBUTING.md) for the PR flow. Per-platform
194
+ contributor docs (iOS / Android / RN / Flutter / .NET) under
195
+ [`docs/development/`](./docs/development/).
196
+
197
+ ---
198
+
199
+ © Deep Voice AI Limited. All rights reserved.
@@ -0,0 +1,91 @@
1
+ buildscript {
2
+ ext {
3
+ kotlinVersion = '2.3.21'
4
+ }
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+ dependencies {
10
+ classpath 'com.android.tools.build:gradle:9.2.0'
11
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
12
+ }
13
+ }
14
+
15
+ ext {
16
+ junitVersion = '4.13.2'
17
+ androidxAppCompatVersion = '1.7.1'
18
+ capacitorVersion = '8.3.1'
19
+ coroutinesVersion = '1.10.2'
20
+ // Pinned within Ktor 2.x — Ktor 3 has breaking API changes around server
21
+ // configuration that would require non-trivial refactors. Stay on the
22
+ // latest 2.x patch (2.3.13) until a deliberate Ktor 3 migration.
23
+ ktorVersion = '2.3.13'
24
+ }
25
+
26
+ allprojects {
27
+ repositories {
28
+ google()
29
+ mavenCentral()
30
+ // Phase 3D: android-llama-core's transitive dep on shared-core resolves
31
+ // here in dev (after `bash scripts/android-publish-local.sh`).
32
+ // Production consumers add the GitHub Packages Maven repo per the
33
+ // consumer-integration docs.
34
+ mavenLocal()
35
+ }
36
+ }
37
+
38
+ // AGP 9+ ships built-in Kotlin support; the standalone 'kotlin-android'
39
+ // plugin is no longer needed (and is rejected by the build).
40
+ // See https://kotl.in/gradle/agp-built-in-kotlin
41
+ apply plugin: 'com.android.library'
42
+
43
+ android {
44
+ namespace 'co.deepvoiceai.bridge.llama'
45
+ compileSdk 36
46
+
47
+ defaultConfig {
48
+ minSdk 24
49
+ targetSdk 36
50
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
51
+ // NDK / externalNativeBuild live in dvai-bridge-android-llama-core; not here.
52
+ }
53
+
54
+ compileOptions {
55
+ sourceCompatibility JavaVersion.VERSION_17
56
+ targetCompatibility JavaVersion.VERSION_17
57
+ }
58
+ testOptions {
59
+ unitTests {
60
+ includeAndroidResources = true
61
+ returnDefaultValues = true
62
+ }
63
+ }
64
+ }
65
+
66
+ // AGP 9 / Kotlin 2.x: the legacy android.kotlinOptions block is gone. The
67
+ // replacement is the standalone `kotlin { compilerOptions { ... } }` extension
68
+ // (provided by AGP's built-in Kotlin integration).
69
+ kotlin {
70
+ compilerOptions {
71
+ jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
72
+ }
73
+ }
74
+
75
+ dependencies {
76
+ // The core re-exports its Kotlin API to wrapper consumers via `api`.
77
+ api project(':dvai-bridge-android-llama-core')
78
+
79
+ implementation "com.capacitorjs:core:$capacitorVersion"
80
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
81
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
82
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
83
+
84
+ testImplementation "junit:junit:$junitVersion"
85
+ testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
86
+ testImplementation 'org.robolectric:robolectric:4.13'
87
+
88
+ androidTestImplementation 'androidx.test:runner:1.6.2'
89
+ androidTestImplementation 'androidx.test:core:1.6.1'
90
+ androidTestImplementation 'androidx.test.ext:junit:1.2.1'
91
+ }
@@ -0,0 +1,4 @@
1
+ android.useAndroidX=true
2
+ kotlin.code.style=official
3
+ android.nonTransitiveRClass=true
4
+ org.gradle.jvmargs=-Xmx4096m
@@ -0,0 +1,4 @@
1
+ include ':dvai-bridge-android-llama-core'
2
+ project(':dvai-bridge-android-llama-core').projectDir = file('../../dvai-bridge-android-llama-core/android')
3
+
4
+ rootProject.name = 'dvai-bridge-capacitor-llama'
@@ -0,0 +1,238 @@
1
+ package co.deepvoiceai.bridge.llama
2
+
3
+ import androidx.test.ext.junit.runners.AndroidJUnit4
4
+ import androidx.test.platform.app.InstrumentationRegistry
5
+ import co.deepvoiceai.bridge.llama.core.LlamaCppBridge
6
+ import co.deepvoiceai.bridge.llama.core.ModelDownloader
7
+ import co.deepvoiceai.bridge.llama.core.MTMD_MEDIA_MARKER
8
+ import org.junit.After
9
+ import org.junit.Assert.assertFalse
10
+ import org.junit.Assert.assertNotNull
11
+ import org.junit.Assert.assertTrue
12
+ import org.junit.Assume.assumeTrue
13
+ import org.junit.Test
14
+ import org.junit.runner.RunWith
15
+ import java.io.File
16
+
17
+ /**
18
+ * End-to-end smoke test against a small public GGUF model. Verifies
19
+ * mechanics (download → load → respond → free) only, not output quality.
20
+ *
21
+ * Reads `smoke_model_url` / `smoke_model_sha256` from the instrumentation
22
+ * arguments — the workflow forwards them via:
23
+ *
24
+ * ./gradlew connectedAndroidTest \
25
+ * -Pandroid.testInstrumentationRunnerArguments.smoke_model_url=$URL \
26
+ * -Pandroid.testInstrumentationRunnerArguments.smoke_model_sha256=$SHA
27
+ *
28
+ * When either is missing the test is skipped via `Assume.assumeTrue`,
29
+ * so it stays safe to run locally without those args.
30
+ */
31
+ @RunWith(AndroidJUnit4::class)
32
+ class RealModelSmokeTest {
33
+ private val ctx = InstrumentationRegistry.getInstrumentation().targetContext
34
+ private val args = InstrumentationRegistry.getArguments()
35
+ private var bridge: LlamaCppBridge? = null
36
+ private var tempDir: File? = null
37
+
38
+ @After
39
+ fun tearDown() {
40
+ bridge?.unload()
41
+ bridge = null
42
+ tempDir?.deleteRecursively()
43
+ tempDir = null
44
+ }
45
+
46
+ /**
47
+ * Vision smoke: download model + mmproj, load both, run a multimodal
48
+ * completion against the tiny test image asset. Skips cleanly if any of
49
+ * smoke_vision_model_url / smoke_vision_model_sha256 /
50
+ * smoke_vision_mmproj_url / smoke_vision_mmproj_sha256 are missing.
51
+ */
52
+ @Test
53
+ fun smokeVisionEndToEnd() {
54
+ val modelUrl = args.getString("smoke_vision_model_url")
55
+ val modelSha = args.getString("smoke_vision_model_sha256")
56
+ val mmprojUrl = args.getString("smoke_vision_mmproj_url")
57
+ val mmprojSha = args.getString("smoke_vision_mmproj_sha256")
58
+ assumeTrue(
59
+ "smoke_vision_* not all provided as instrumentation args; skipping",
60
+ !modelUrl.isNullOrEmpty() && !modelSha.isNullOrEmpty() &&
61
+ !mmprojUrl.isNullOrEmpty() && !mmprojSha.isNullOrEmpty()
62
+ )
63
+
64
+ val cacheRoot = File(ctx.cacheDir, "dvai-vision-${System.nanoTime()}")
65
+ cacheRoot.mkdirs()
66
+ tempDir = cacheRoot
67
+
68
+ val downloader = ModelDownloader(ctx, cacheDirOverride = cacheRoot)
69
+ val (modelPath, _) = downloader.downloadModel(
70
+ url = modelUrl!!,
71
+ expectedSha256 = modelSha!!.lowercase(),
72
+ destFilename = "smoke-vision-model.gguf",
73
+ headers = emptyMap(),
74
+ onProgress = { _, _ -> },
75
+ )
76
+ val (mmprojPath, _) = downloader.downloadModel(
77
+ url = mmprojUrl!!,
78
+ expectedSha256 = mmprojSha!!.lowercase(),
79
+ destFilename = "smoke-vision-mmproj.gguf",
80
+ headers = emptyMap(),
81
+ onProgress = { _, _ -> },
82
+ )
83
+
84
+ val bridge = LlamaCppBridge()
85
+ this.bridge = bridge
86
+ val loaded = bridge.loadModel(
87
+ path = modelPath,
88
+ mmprojPath = null,
89
+ gpuLayers = 99,
90
+ contextSize = 4096,
91
+ threads = 4,
92
+ embeddingMode = false,
93
+ )
94
+ assertTrue("model load should succeed", loaded)
95
+ val mmOk = bridge.loadMmproj(mmprojPath)
96
+ assertTrue("mmproj load should succeed", mmOk)
97
+ assertTrue("bridge should report mmproj loaded", bridge.isMmprojLoaded())
98
+
99
+ // Read the tiny PNG from assets (1x1 transparent pixel).
100
+ val imageBytes = ctx.assets.open("images/tiny-test.png").use { it.readBytes() }
101
+
102
+ val messages = listOf(mapOf("role" to "user", "content" to "Describe this image: $MTMD_MEDIA_MARKER"))
103
+ val chatPrompt = bridge.applyChatTemplate(
104
+ templateOverride = null,
105
+ messages = messages,
106
+ addAssistant = true,
107
+ )
108
+ assertNotNull("chat template should render", chatPrompt)
109
+
110
+ val completion = bridge.completeMultimodalPrompt(
111
+ prompt = chatPrompt!!,
112
+ media = listOf(imageBytes),
113
+ maxTokens = 32,
114
+ temperature = 0.0f,
115
+ topP = 1.0f,
116
+ )
117
+ assertNotNull("vision completion should not be null", completion)
118
+ assertFalse("vision completion should not be empty", completion!!.isEmpty())
119
+ }
120
+
121
+ /**
122
+ * Audio smoke: same as vision, but with the WAV fixture. Skipped if the
123
+ * loaded mmproj has no audio encoder.
124
+ */
125
+ @Test
126
+ fun smokeAudioEndToEnd() {
127
+ val modelUrl = args.getString("smoke_vision_model_url")
128
+ val modelSha = args.getString("smoke_vision_model_sha256")
129
+ val mmprojUrl = args.getString("smoke_vision_mmproj_url")
130
+ val mmprojSha = args.getString("smoke_vision_mmproj_sha256")
131
+ assumeTrue(
132
+ "smoke_vision_* not all provided as instrumentation args; skipping",
133
+ !modelUrl.isNullOrEmpty() && !modelSha.isNullOrEmpty() &&
134
+ !mmprojUrl.isNullOrEmpty() && !mmprojSha.isNullOrEmpty()
135
+ )
136
+
137
+ val cacheRoot = File(ctx.cacheDir, "dvai-audio-${System.nanoTime()}")
138
+ cacheRoot.mkdirs()
139
+ tempDir = cacheRoot
140
+
141
+ val downloader = ModelDownloader(ctx, cacheDirOverride = cacheRoot)
142
+ val (modelPath, _) = downloader.downloadModel(
143
+ url = modelUrl!!,
144
+ expectedSha256 = modelSha!!.lowercase(),
145
+ destFilename = "smoke-audio-model.gguf",
146
+ headers = emptyMap(),
147
+ onProgress = { _, _ -> },
148
+ )
149
+ val (mmprojPath, _) = downloader.downloadModel(
150
+ url = mmprojUrl!!,
151
+ expectedSha256 = mmprojSha!!.lowercase(),
152
+ destFilename = "smoke-audio-mmproj.gguf",
153
+ headers = emptyMap(),
154
+ onProgress = { _, _ -> },
155
+ )
156
+
157
+ val bridge = LlamaCppBridge()
158
+ this.bridge = bridge
159
+ bridge.loadModel(
160
+ path = modelPath,
161
+ mmprojPath = null,
162
+ gpuLayers = 99,
163
+ contextSize = 4096,
164
+ threads = 4,
165
+ embeddingMode = false,
166
+ )
167
+ bridge.loadMmproj(mmprojPath)
168
+ assumeTrue("Loaded mmproj reports no audio encoder; skipping audio smoke", bridge.hasAudioEncoder())
169
+
170
+ // mtmd accepts wav/mp3/flac for audio. Use the WAV fixture from assets.
171
+ val audioBytes = ctx.assets.open("audio/wav-1s-16khz-mono.wav").use { it.readBytes() }
172
+
173
+ val messages = listOf(mapOf("role" to "user", "content" to "Transcribe this: $MTMD_MEDIA_MARKER"))
174
+ val chatPrompt = bridge.applyChatTemplate(
175
+ templateOverride = null,
176
+ messages = messages,
177
+ addAssistant = true,
178
+ )!!
179
+
180
+ val completion = bridge.completeMultimodalPrompt(
181
+ prompt = chatPrompt,
182
+ media = listOf(audioBytes),
183
+ maxTokens = 32,
184
+ temperature = 0.0f,
185
+ topP = 1.0f,
186
+ )
187
+ assertNotNull("audio completion should not be null", completion)
188
+ assertFalse("audio completion should not be empty", completion!!.isEmpty())
189
+ }
190
+
191
+ @Test
192
+ fun smokeRealModelEndToEnd() {
193
+ val url = args.getString("smoke_model_url")
194
+ val sha = args.getString("smoke_model_sha256")
195
+ assumeTrue(
196
+ "smoke_model_url/smoke_model_sha256 not provided as instrumentation args; skipping",
197
+ !url.isNullOrEmpty() && !sha.isNullOrEmpty()
198
+ )
199
+
200
+ val cacheRoot = File(ctx.cacheDir, "dvai-smoke-${System.nanoTime()}")
201
+ cacheRoot.mkdirs()
202
+ tempDir = cacheRoot
203
+
204
+ val downloader = ModelDownloader(ctx, cacheDirOverride = cacheRoot)
205
+ val (path, cached) = downloader.downloadModel(
206
+ url = url!!,
207
+ expectedSha256 = sha!!.lowercase(),
208
+ destFilename = "smoke-model.gguf",
209
+ headers = emptyMap(),
210
+ onProgress = { _, _ -> /* no-op for smoke */ },
211
+ )
212
+ assertFalse("first download into a fresh temp dir should not be cached", cached)
213
+ assertTrue("downloaded file should exist at $path", File(path).exists())
214
+
215
+ val bridge = LlamaCppBridge()
216
+ this.bridge = bridge
217
+ val loaded = bridge.loadModel(
218
+ path = path,
219
+ mmprojPath = null,
220
+ gpuLayers = 99,
221
+ contextSize = 2048,
222
+ threads = 4,
223
+ embeddingMode = false,
224
+ )
225
+ assertTrue("model load should succeed", loaded)
226
+ assertTrue("bridge should report loaded", bridge.isLoaded())
227
+
228
+ val completion = bridge.completePrompt(
229
+ prompt = "<|begin_of_text|>What is 2+2?",
230
+ maxTokens = 32,
231
+ temperature = 0.0f,
232
+ topP = 1.0f,
233
+ )
234
+ // Don't assert specific content — that's quality testing, not smoke.
235
+ assertNotNull("completion should not be null", completion)
236
+ assertFalse("completion should not be empty", completion!!.isEmpty())
237
+ }
238
+ }
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:tools="http://schemas.android.com/tools">
4
+ <application
5
+ android:networkSecurityConfig="@xml/dvai_network_security_config"
6
+ tools:replace="android:networkSecurityConfig" />
7
+ </manifest>