Bitzsoft.Integrations.Translation.AI.Anthropic 1.0.0

dotnet add package Bitzsoft.Integrations.Translation.AI.Anthropic --version 1.0.0
                    
NuGet\Install-Package Bitzsoft.Integrations.Translation.AI.Anthropic -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.Anthropic" 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.Anthropic" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Translation.AI.Anthropic" />
                    
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.Anthropic --version 1.0.0
                    
#r "nuget: Bitzsoft.Integrations.Translation.AI.Anthropic, 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.Anthropic@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.Anthropic&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Translation.AI.Anthropic&version=1.0.0
                    
Install as a Cake Tool

Bitzsoft.Integrations.Translation.AI.Anthropic

Anthropic Claude 大模型翻译实现包 -- 复用既有 Bitzsoft.Integrations.AI.Anthropic 原生 Messages 适配器(注册即幂等带上 AddBitzAnthropicAI()),法律术语约束提示词 + 分段回拼 + JSON 输出回退,实现 IAiTranslationProvider 契约。

功能特性

  • 复用既有 Anthropic 包:协议适配、凭据与租户语义由 AI 域原生 Messages 适配器承载
  • 法律术语约束提示词:内置法律与商务文书级系统提示词模板,Terms 逐行注入强约束译法
  • 批量分段策略:长文本按 SegmentCharLimit(段落 → 句子 → 硬截断)切分、按原始分隔符回拼
  • JSON 输出 + 失败回退:Claude 无原生 response_format,以提示词要求 JSON + 容错解析(剥代码围栏 / 首尾杂散文本),失败自动回退纯文本重译
  • 风格 / 温度 / 提示词模板:Style / Instructions / SystemPromptTemplate / Temperature 全量支持
  • 语言检测:Claude JSON 输出识别语种并归一化统一编码
  • 健康探测:单次最小补全(限定 8 token)

安装

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

配置

appsettings.json

{
  "Translation": {
    "Anthropic": {
      "ClientName": "translation-claude",
      "ModelId": "claude-sonnet-4-5",
      "SegmentCharLimit": 6000,
      "MaxBatchItems": 20,
      "EnableJsonMode": true,
      "DefaultTemperature": 0.2
    }
  }
}
配置项 说明 必填 默认值
ClientName AI 命名客户端(与 AddBitzChatClient 注册名一致) 否 translation-claude
ModelId 模型覆盖(claude-sonnet-4-5 / claude-opus-4 ...) 否 命名 AiOptions 默认模型
SegmentCharLimit / MaxBatchItems 分段与批量上限 否 6000 / 20
EnableJsonMode 提示词级 JSON 输出(失败自动纯文本回退) 否 true
DefaultTemperature 默认采样温度 否 0.2
DefaultSystemPromptTemplate / DefaultStyle / DefaultDomainHint / DefaultInstructions 默认提示词参数 否 内置法律文书级模板

注册服务

using Bitzsoft.Integrations.AI;
using Microsoft.Extensions.DependencyInjection;

// 1. AI 命名客户端(ProfileId=anthropic,密钥进凭据存储)
builder.Services.AddInMemoryIntegrationCredentials();
builder.Services.AddBitzChatClient("translation-claude", options =>
{
    options.ProviderId = "anthropic";
    options.ProfileId = "anthropic";
    options.ModelId = "claude-sonnet-4-5";
});

// 2. 注册 Claude 翻译(内部幂等带上 AddBitzAnthropicAI 原生适配器)
builder.Services.AddBitzsoftAnthropicTranslation(builder.Configuration);

使用示例

var provider = factory.GetProvider(TranslationProviderCode.Anthropic);
var result = await ((IAiTranslationProvider)provider).TranslateAsync(new AiTranslationRequest
{
    Text = longContractText,
    SourceLanguage = "en",
    TargetLanguage = "zh",
    Terms = new[] { new TranslationTerm("indemnity", "赔偿") },
    Style = "正式法律文书",
    Temperature = 0.1
});

能力矩阵

能力 支持 说明
单文本翻译 ✅ 超长文本分段回拼
批量翻译 ✅ JSON 数组单请求,失败逐条回退
语言检测 ✅ Claude JSON 输出识别并归一化
领域词汇表(Terms) ✅ 提示词强约束 法律文书级系统提示词注入
风格 / 指令 / 提示词模板 / 温度 ✅ 全量支持
原生 JSON 模式 ❌ 协议限制;提示词约束 + 解析容错 + 纯文本回退
健康探测 ✅ 最小补全(8 token)

相关包

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 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.Anthropic:

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 69 10/21/2026