Bitzsoft.Integrations.Translation.AI.Baidu 1.0.0

dotnet add package Bitzsoft.Integrations.Translation.AI.Baidu --version 1.0.0
                    
NuGet\Install-Package Bitzsoft.Integrations.Translation.AI.Baidu -Version 1.0.0
                    
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="Bitzsoft.Integrations.Translation.AI.Baidu" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Translation.AI.Baidu" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Translation.AI.Baidu" />
                    
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 Bitzsoft.Integrations.Translation.AI.Baidu --version 1.0.0
                    
#r "nuget: Bitzsoft.Integrations.Translation.AI.Baidu, 1.0.0"
                    
#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 Bitzsoft.Integrations.Translation.AI.Baidu@1.0.0
                    
#: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=Bitzsoft.Integrations.Translation.AI.Baidu&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Translation.AI.Baidu&version=1.0.0
                    
Install as a Cake Tool

Bitzsoft.Integrations.Translation.AI.Baidu

百度大模型文本翻译实现包 -- 官方 ait/aiTextTranslate 端点,翻译指令(reference)承载风格 / 领域 / 术语约束,支持控制台术语库干预(needIntervene)与 llm / nmt 双引擎,实现 IAiTranslationProvider 契约。与 Translation.Baidu(通用翻译 API)共用开放平台账号,互为补充:通用 API 走免费字符额度,本包为大模型质量档位。

功能特性

  • 翻译指令注入:Style / Instructions / DomainHint / Terms 拼装为 reference 指令(上限 500 字符,超限按 InvalidArgument 快速失败)
  • 术语约束:请求级 Terms 拼入指令强约束译法;控制台术语库经 NeedIntervene 独立开启
  • 双鉴权:新版 API Key(Bearer + JSON 报文,推荐)或 AppId + 密钥(MD5 签名表单报文,与通用 API 同构)
  • 双引擎:ModelType 支持 llm(默认)与 nmt
  • 检测语种回显:from=auto 时响应 from 归一化为统一编码填入 DetectedSourceLanguage
  • 限流退避重试:net8+ 标准韧性 handler(429/503/504 指数退避)
  • 健康探测:最小代价单字符翻译探测(配额 / 限流降级为 Degraded)
  • 请求审计:内置 RequestLogging 管道记录出站请求

安装

dotnet add package Bitzsoft.Integrations.Translation.AI.Baidu

配置

appsettings.json

{
  "Translation": {
    "BaiduAi": {
      "AppId": "20251021000123456",
      "ApiKey": "your-api-key",
      "ModelType": "llm",
      "DefaultReference": "使用正式法律文书风格翻译",
      "NeedIntervene": false
    }
  }
}
配置项 说明 必填 默认值
AppId 开放平台 APPID(官方参数表必填) 是 -
ApiKey 新版 API Key(Bearer 鉴权,推荐) 与 AppSecret 二选一 -
AppSecret 平台密钥(MD5 签名鉴权) 与 ApiKey 二选一 -
Endpoint 大模型翻译端点(完整 URL) 否 https://fanyi-api.baidu.com/ait/api/aiTextTranslate
BaseAddress 端点覆盖(代理网关场景替换完整 URL) 否 -
ModelType 翻译引擎(llm / nmt) 否 llm
DefaultReference 默认翻译指令(与请求级片段拼接) 否 空
NeedIntervene 启用控制台术语库干预 否 false
Timeout / MaxRetryAttempts / RetryBaseDelay 超时与限流退避 否 30s / 3 / 500ms
HttpClientName 命名 HttpClient 标识 否 BaiduAiTranslationProvider

注册服务

builder.Services.AddBitzsoftBaiduAiTranslation(builder.Configuration);

注册后 ITranslationProviderFactory 按编码 baidu-ai 解析;IIntegrationProviderResolver<IAiTranslationProvider> 亦可按同一编码解析 AI 能力。

使用示例

// AI 契约:风格 + 术语约束经翻译指令注入
var ai = resolver.GetRequired("baidu-ai");
var result = await ai.TranslateAsync(new AiTranslationRequest
{
    Text = "The force majeure clause shall apply.",
    SourceLanguage = "en",
    TargetLanguage = "zh",
    Style = "正式法律文书",
    Terms = new[] { new TranslationTerm("force majeure", "不可抗力") },
});

能力矩阵

能力 支持 说明
单文本翻译 ✅ ait/aiTextTranslate(单次 ≤6000 字符)
批量翻译 ✅ 逐条调用保持顺序
语言检测 ❌ 无独立接口(auto 源语种经翻译回显)
领域词汇表(Terms) ✅ 指令注入 拼入 reference,非原生术语参数
风格 / 指令 ✅ 指令注入 reference(合计 ≤500 字符)
提示词模板 / 温度 / 输出上限 ❌ 服务端不暴露生成参数,相关字段忽略
HTML 格式 ❌ 纯文本翻译(nmt 引擎的 tag 参数未开放)
健康探测 ✅ 单字符翻译探测

错误码收敛

百度信号 统一错误码
52003 / 54001 / 90107(鉴权类) AuthenticationFailed
54003 / 54005 / 59004(限流类) RateLimited
54004(余额不足) QuotaExceeded
58001(语言方向不支持) LanguageNotSupported
58000 / 58002 / 58003(IP / 服务关闭) AccessDenied
58004 / 59002 / 59003 / 59005-07(参数类) InvalidArgument
20003(内容安全风险) InvalidArgument
52001(超时) Timeout
网络异常 NetworkUnreachable

相关包

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Translation.AI.Baidu:

Package Downloads
Bitzsoft.Integrations.Translation.All

翻译服务聚合包 — 传统机翻(阿里云 / 百度 / 腾讯云 / 有道 / DeepL / Google 官方)+ AI 翻译(通义 Qwen-MT / 百度大模型 / 火山引擎大模型,OpenAI 兼容 / Anthropic net8+),配置存在性驱动注册

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 68 10/21/2026