跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://docs.nexa.ai/llms.txt

Use this file to discover all available pages before exploring further.

安装

Nexa AI Android SDK 可从 Maven Central 获取,最新版本为 0.0.24。你也可以在 Maven Repository 查看(更新速度较 Maven Central 略慢)。

添加依赖

在你的 app/build.gradle.kts 中添加以下依赖以导入 NexaSDK:
dependencies {
  implementation("ai.nexa:core:0.0.24")
}
默认仓库为 mavenCentral()。你也可以在 settings.gradle.kts 中添加 GitHub 的 raw 仓库:
dependencyResolutionManagement{
    repositories {
        maven {
            url = uri("https://raw.githubusercontent.com/NexaAI/core/main")
        }
    }
}

运行你的第一个模型

1

初始化 SDK

在你的 Android 应用中初始化 NexaSDK:
NexaSdk.getInstance().init(this)
2

下载并加载模型

创建 VLM 封装并加载用于 NPU 推理的模型。你可以从 HuggingFace 下载 OmniNeural-4B 模型,将其放置在你的应用有权限访问的目录,例如:/data/data/${your-app-packagename}/files/models/OmniNeural-4B
VlmWrapper.builder()
    .vlmCreateInput(
        VlmCreateInput(
            model_name = "omni-neural",
            model_path = <your-model-file-absolute-path>,
            config = ModelConfig(
                max_tokens = 2048,
                enable_thinking = false
            ),
            plugin_id = "npu"
        )
    )
    .build()
    .onSuccess { vlmWrapper = it }
应用必须有权限访问模型目录。例如,在示例应用中,model_path 设置为 /data/data/com.nexa.demo/files/models/OmniNeural-4B/files-1-1.nexa
3

生成内容

使用已加载的模型生成响应:
vlmWrapper.generateStreamFlow("Who are you?", GenerationConfig()).collect { result ->
    println(result)
}

支持的模型

我们为你整理了可用模型合集:

NPU 模型

针对 Qualcomm NPU 优化的模型

GGUF 模型

任意 GGUF 格式的 LLM 与 VLM 模型

设备兼容性

  • Qualcomm Snapdragon 8 Elite
  • Qualcomm Snapdragon 8 Elite Gen 5
  • Qualcomm Adreno GPU
  • ARM64-v8a

后续步骤

API 参考

查看各模型类型的详细文档与使用方式。