LocalAI.Translation 1.2.1

dotnet add package LocalAI.Translation --version 1.2.1
                    
NuGet\Install-Package LocalAI.Translation -Version 1.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LocalAI.Translation" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LocalAI.Translation" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="LocalAI.Translation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LocalAI.Translation --version 1.2.1
                    
#r "nuget: LocalAI.Translation, 1.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LocalAI.Translation@1.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LocalAI.Translation&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=LocalAI.Translation&version=1.2.1
                    
Install as a Cake Tool

LocalAI Translate — .NET 本地 AI 离线翻译 SDK

一个安装入口,包含 DirectML 推理库及自动还原的中英越 INT8 模型。模型在本机运行, 无需网络服务。

模型源自 facebook/nllb-200-distilled-600M,模型资产受 CC BY-NC 4.0 约束,仅限非商业用途。SDK 源代码采用 MIT 许可证。

安装

dotnet add package LocalAI.Translation

虽然 NuGet 因单包大小限制在内部还原四个模型组件,但应用只需要引用上面的主包。 模型会自动进入输出和发布目录的 models 文件夹,不需要配置模型路径。

最小示例

using Nllb.Onnx;

await using var engine = new TranslationEngine();
var initialization = await engine.InitializeAsync();
var result = await engine.TranslateAsync(new TranslationRequest(
    "今天天气很好。",
    "zho_Hans",
    "vie_Latn"));

if (!result.IsSuccess)
{
    throw new InvalidOperationException($"{result.Status}: {result.ErrorMessage}");
}

Console.WriteLine(result.Text);

默认配置会自动选择 DirectML/CPU 并让模型常驻。InitializeAsync() 可在应用启动时完成 预热;engine.Metrics 提供请求、耗时、缓存命中率、实际后端和模型加载状态。

语言代码为:简体中文 zho_Hans、英文 eng_Latn、越南文 vie_Latn。

高级部署才需要通过 new TranslationEngineOptions(path) 或环境变量 NLLB_ONNX_MODEL_DIR 覆盖默认目录。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 116 8/21/2026
1.2.0 102 8/21/2026

SDK 1.2.1 fixes transitive model asset propagation so installing only the main package automatically restores and copies the 1.0.0 model bundle.