Bitzsoft.Integrations.Translation.AI.Tongyi
1.0.0
dotnet add package Bitzsoft.Integrations.Translation.AI.Tongyi --version 1.0.0
NuGet\Install-Package Bitzsoft.Integrations.Translation.AI.Tongyi -Version 1.0.0
<PackageReference Include="Bitzsoft.Integrations.Translation.AI.Tongyi" Version="1.0.0" />
<PackageVersion Include="Bitzsoft.Integrations.Translation.AI.Tongyi" Version="1.0.0" />
<PackageReference Include="Bitzsoft.Integrations.Translation.AI.Tongyi" />
paket add Bitzsoft.Integrations.Translation.AI.Tongyi --version 1.0.0
#r "nuget: Bitzsoft.Integrations.Translation.AI.Tongyi, 1.0.0"
#:package Bitzsoft.Integrations.Translation.AI.Tongyi@1.0.0
#addin nuget:?package=Bitzsoft.Integrations.Translation.AI.Tongyi&version=1.0.0
#tool nuget:?package=Bitzsoft.Integrations.Translation.AI.Tongyi&version=1.0.0
Bitzsoft.Integrations.Translation.AI.Tongyi
阿里云百炼通义翻译(Qwen-MT)实现包 -- OpenAI 兼容端点 + translation_options 原生术语干预(terms)与领域提示(domains),实现 IAiTranslationProvider 契约。相比通用大模型提示词方案,Qwen-MT 是翻译专用模型:接入更轻(一个 chat/completions 调用)、术语约束由模型原生保证。
功能特性
- 原生术语干预:请求内
Terms直接映射translation_options.terms(source/target),模型严格采用指定译法 - 领域提示:
DomainHint/DefaultDomains映射domains(仅英文),法律 / IT 等领域定向 - 接入轻量:Bearer API Key + 单端点,无需提示词工程即可获得专业翻译质量
- 模型可选:
qwen-mt-plus(质量)/qwen-mt-flash/qwen-mt-lite(速度) - AI 契约:实现
IAiTranslationProvider,温度与输出 token 上限透传 - 限流退避重试:net8+ 标准韧性 handler(429/503/504 指数退避)
- 健康探测:
GET /models模型列表(不计 token) - 请求审计:内置 RequestLogging 管道记录出站请求
安装
dotnet add package Bitzsoft.Integrations.Translation.AI.Tongyi
配置
appsettings.json
{
"Translation": {
"Tongyi": {
"ApiKey": "sk-your-dashscope-api-key",
"Model": "qwen-mt-plus",
"DefaultDomains": "The text is from legal contract domain.",
"DefaultTemperature": 0.2
}
}
}
| 配置项 | 说明 | 必填 | 默认值 |
|---|---|---|---|
ApiKey |
百炼 DashScope API Key(Bearer,继承统一 Options) | 是 | - |
Endpoint |
compatible-mode 端点(不含 chat/completions) | 否 | https://dashscope.aliyuncs.com/compatible-mode/v1 |
BaseAddress |
端点覆盖(工作空间专属端点用此项) | 否 | - |
Model |
翻译模型 | 否 | qwen-mt-plus |
DefaultDomains |
默认领域提示(仅英文) | 否 | 空 |
DefaultTemperature |
默认采样温度 | 否 | 0.2 |
Timeout / MaxRetryAttempts / RetryBaseDelay |
超时与限流退避 | 否 | 30s / 3 / 500ms |
HttpClientName |
命名 HttpClient 标识 | 否 | TongyiTranslationProvider |
工作空间专属端点示例:
"BaseAddress": "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"(北京 / 新加坡地域 API Key 不同)。
注册服务
builder.Services.AddBitzsoftTongyiTranslation(builder.Configuration);
注册后 ITranslationProviderFactory 按编码 tongyi 解析;IIntegrationProviderResolver<IAiTranslationProvider> 亦可按同一编码解析 AI 能力。
使用示例
// AI 契约:术语原生干预 + 温度
var ai = resolver.GetRequired("tongyi");
var result = await ai.TranslateAsync(new AiTranslationRequest
{
Text = "The force majeure clause shall apply.",
SourceLanguage = "en",
TargetLanguage = "zh",
Terms = new[] { new TranslationTerm("force majeure", "不可抗力") },
DomainHint = "The text is from legal contract domain.",
Temperature = 0.1
});
能力矩阵
| 能力 | 支持 | 说明 |
|---|---|---|
| 单文本翻译 | ✅ | chat/completions + translation_options |
| 批量翻译 | ✅ | 逐条调用保持顺序(账号限流 5 RPM) |
| 语言检测 | ❌ | Qwen-MT 响应不回显检测语种 |
| 领域词汇表(Terms) | ✅ 原生强约束 | translation_options.terms |
| 风格 / 指令 / 提示词模板 | ❌ | Qwen-MT 不支持 system message,相关字段忽略 |
| HTML 格式 | ❌ | 纯文本翻译 |
| 健康探测 | ✅ | GET /models(不计 token) |
错误码收敛
| 通义信号 | 统一错误码 |
|---|---|
| 401(InvalidApiKey) | AuthenticationFailed |
| 429(限流,官方应用 5 RPM) | RateLimited |
| 400 + message 含 lang / model | LanguageNotSupported |
| 400(参数无效) | InvalidArgument |
| 网络异常 | NetworkUnreachable |
| 超时 | Timeout |
相关包
| Product | Versions 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. |
-
net10.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Bitzsoft.Integrations.Translation.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Http.Resilience (>= 10.7.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Bitzsoft.Integrations.Translation.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Bitzsoft.Integrations.Translation.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Http.Resilience (>= 10.7.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Translation.AI.Tongyi:
| 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 | 63 | 10/21/2026 |