适用版本:ChengOS v0.1.0+ | 最后核对:2026-08-13 | 来源:
crates/cheng-nodes/src/nodes/builtin/translation
翻译由一个节点承担,具体提供商通过字段选择:既可以用复用现有模型凭据的 LLM 提供商, 也可以直连 DeepL、百度、Google 的厂商 API。取舍很明确 —— 处理普通文本时厂商 API 更便宜、更稳定, 而只有 LLM 提供商会遵循语气与术语表要求。源语言可以保持自动检测;实际判定的语言会作为输出返回, 下游分支可以据此处理。
翻译 — ai/translation
使用 LLM / DeepL / 百度 / 谷歌翻译文本,保留格式和词汇表
输入
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
text |
string | — | "" |
要翻译的源文本(字符串端口). 控件:textarea |
text_artifact |
object | — | null |
存放源文本的 Artifact(推荐用于长文档) |
text_artifact_uri |
string | — | null |
源文本的 artifact:// URI |
context |
object | — | null |
可选的 AgentContext 输入(翻译内容追加到上下文中) |
provider |
enum | — | llm |
翻译服务提供商. 控件:select. 取值:llm (LLM-driven translation (reuses the existing LLM credential model).), deepl (DeepL Translate (free or pro).), baidu (百度翻译 通用文本翻译.), google (Google Cloud Translation v3 with API-key authentication.) |
credential_id |
string | — | null |
所选供应商的凭证 ID(DeepL / 百度 / 谷歌).LLM 模式忽略此参数. 控件:credential-select |
llm_model |
string | — | null |
LLM 模型选择器,用于提供商 = LLM(格式:credential_id::model_name). 控件:llm-model-select |
source_lang |
enum | — | auto |
源语言(Auto = 自动检测). 控件:select. 取值:auto (Auto-detect), en (English), zh-Hans (Chinese (Simplified) — 简体中文), zh-Hant (Chinese (Traditional) — 繁體中文), ja (Japanese — 日本語), ko (Korean — 한국어), fr (French — Français), de (German — Deutsch), es (Spanish — Español), pt (Portuguese — Português), ru (Russian — Русский), it (Italian — Italiano), … (+7) |
target_lang |
enum | — | zh-Hans |
目标语言. 控件:select. 取值:en (English), zh-Hans (Chinese (Simplified) — 简体中文), zh-Hant (Chinese (Traditional) — 繁體中文), ja (Japanese — 日本語), ko (Korean — 한국어), fr (French — Français), de (German — Deutsch), es (Spanish — Español), pt (Portuguese — Português), ru (Russian — Русский), it (Italian — Italiano), ar (Arabic — العربية), … (+6) |
style |
enum | — | default |
语气(仅 LLM 提供商;供应商 API 会忽略此参数). 控件:select. 取值:default, formal, casual, technical, literary |
preserve_formatting |
boolean | — | true |
保留 Markdown 结构(链接 / 图片)— 推荐 |
preserve_code_blocks |
boolean | — | true |
保留 fenced 和 inline 代码块 — 推荐 |
glossary |
string | — | null |
可选的强制翻译词汇表.格式为 {“src”:”dst”} 映射或 [{src,dst}] 数组. 控件:code-editor |
custom_prompt |
string | — | null |
覆盖 LLM 系统提示(仅 LLM 提供商). 控件:textarea |
timeout_ms |
integer | — | 30000 |
每个请求的超时时间(毫秒) |
max_retries |
integer | — | 2 |
瞬时提供商错误的重试预算(限速 / 超时 / 5xx) |
输出
| 字段 | 类型 | 说明 |
|---|---|---|
translated_text |
string | 翻译后的文本(字符串) |
translated_text_artifact |
object | 存放完整翻译文本的 Artifact |
translated_preview |
string | 有界翻译文本预览 |
source_char_count |
integer | 源文本字符数 |
translated_char_count |
integer | 翻译后文本字符数 |
segments_count |
integer | 翻译分段数量 |
context |
object (端口) | AgentContext,包含追加的翻译内容. 连接端口,不是表单字段。 |
detected_source |
enum | 实际使用的源语言(当 source_lang = Auto 时解析). 取值:auto, en, zh-Hans, zh-Hant, ja, ko, fr, de, es, pt, ru, it, … (+7) |
target_lang |
enum | 使用的目标语言. 取值:auto, en, zh-Hans, zh-Hant, ja, ko, fr, de, es, pt, ru, it, … (+7) |
provider |
string | 本次翻译使用的提供商 |
model |
string | LLM 提供商使用的模型(供应商 API 省略此字段) |
stats |
object (端口) | 翻译统计(字符数,字节数,重试次数,词汇表命中数,耗时). 连接端口,不是表单字段。 |
下一步
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

暂无评论内容