跳转到内容

AI 引擎:不只是翻译

为什么 DevLingo 不直接用词典 API?简单的 API 查询返回的是静态、无上下文的信息。DevLingo 的 AI 引擎做的是三件字典做不了的事。

字典说 “deploy” 就是”部署”。但开发者需要知道:

场景含义例句
部署应用发布到生产环境”We deployed the new version to production.”
配置资源分配/启用资源”Deploy additional servers to handle traffic.”
战术(军事用语)展开、部署”The team is deployed across different time zones.”

DevLingo AI 知道你在 Xcode 中阅读代码,所以强调第一种含义。你在 HR 软件中看到 “deploy”,也许更相关的是第三个意思。

{ "sourceApp": "com.apple.dt.Xcode" }
→ AI 调整回应风格:技术导向、代码相关例句优先
{ "sourceApp": "com.tinyspeck.slackmacgap" }
→ AI 调整回应风格:团队沟通、更口语化

:::tip 应用感知 DevLingo 通过 NSWorkspace 获取当前活跃应用的 Bundle Identifier,传给 Claude。AI 据此调整回应。 :::

字典返回一个文本块。DevLingo AI 返回结构化的 JSON:

{
"word": "idempotent",
"ipa": "/ɪˈdɛmpətənt/",
"pos": "adjective",
"definition_en": "Describing an operation that, when applied multiple times, produces the same result as when applied once.",
"meaning_zh": "幂等的;多次应用与应用一次结果相同",
"examples": [
{
"en": "Ensure your API endpoints are idempotent to handle retry requests safely.",
"zh": "确保 API 端点是幂等的,以安全地处理重试请求。",
"context": "API design"
},
{
"en": "This function's idempotent nature makes it safe to call multiple times.",
"zh": "这个函数的幂等特性使其可以安全地多次调用。",
"context": "Function design"
}
],
"synonyms": [
{
"word": "repeatable",
"difference": "更通用;指任何可重复的操作。'idempotent' 更专业、更精确。"
}
],
"collocations": [
"idempotent operation",
"idempotent function",
"idempotent API"
],
"grammar_notes": "形容词,不可数。在技术文档中常作定语或补语使用。",
"l1_tips": {
"zh": "中文中没有对应的日常词汇。记住 'idempotent' 是数学/编程术语,与中文的 '幂等' 对应,但在技术讨论中直接使用英文更常见。"
},
"tech_pronunciation": {
"ipa": "/ɪˈdɛmpətənt/",
"common_mispronounce": "i-DEM-po-tent(错误;重音应在 DEM)",
"correct_stress": "i-**DEM**-pu-tunt",
"etymology": "源自数学术语,来自拉丁文 'idem'(相同)和 'potent'(强大)"
}
}

每个字段在 UI 中对应不同的卡片区域。不是一堆文字,而是精心组织的学习材料。

{
"phrase": "rubber ducking",
"type": "compound (noun phrase)",
"register": "informal / tech culture",
"definition_en": "A debugging method where you explain your code to a rubber duck (or any object), often revealing bugs through the act of articulation.",
"meaning_zh": "通过向橡皮鸭(或任何物体)解释代码来调试,通常通过表述过程就能发现问题的方法。",
"stress_pattern": "RUB-ber DUCK-ing",
"usage_patterns": [
{
"pattern": "[Subject] [is/uses] rubber ducking",
"example": "I've been rubber ducking this problem for 10 minutes and just found the issue.",
"zh": "我一直在进行 rubber ducking,10 分钟后发现了问题。"
},
{
"pattern": "[Let's] do some rubber ducking [on X]",
"example": "Let's do some rubber ducking on this algorithm.",
"zh": "让我们对这个算法进行 rubber ducking。"
}
],
"alternatives": [
{
"phrase": "debugging by explanation",
"note": "更正式的说法;不如 'rubber ducking' 有文化特色"
},
{
"phrase": "talk it out",
"note": "更口语;没有特指调试方法"
}
]
}

如果输入是开发术语,AI 给出额外信息:

单词:latency
标准输出:definition, examples, pronunciation...
额外输出(仅技术术语):
• 相关度量:毫秒(ms)/ 微秒(μs)
• 与之对应的概念:throughput, bandwidth
• 实战场景:"P99 latency < 100ms" 是什么意思
• 行业基准:一般网络延迟 50ms,不好的是 500ms+

不是”猫坐在垫子上”,而是:

单词:concurrent
例句(来自真实开发):
1. "This function is not concurrent-safe; you need to add locking."
→ 代码审查场景
2. "We redesigned the system to handle concurrent requests efficiently."
→ 架构设计场景
3. "Make sure your HTTP client supports concurrent connections."
→ 性能优化场景

根据用户的母语,AI 主动指出常见陷阱:

用户:中文母语
单词:article / the / a
AI 提示:
"中文母语使用者常见问题:中文没有冠词,但英文区分 definite article (the) 和 indefinite article (a/an)。
错误例:'I saw cat' → 'I saw a cat' 或 'I saw the cat'(取决于上下文)
记忆法:每个可数名词在英文中通常需要冠词。中文里'猫'就是猫,英文里必须说'一只猫'或'那只猫'。"

:::note L1 干扰 这是 DevLingo 的独特之处。标准字典不会告诉你”你这个词可能用错的原因是你的母语背景”。 :::

DevLingo 选择 Claude 的原因:

  1. 结构化输出能力强:Claude 擅长生成格式化的 JSON,可靠性高
  2. 上下文理解深:Claude 能理解应用语境、代码上下文、L1 干扰
  3. 开发者友好:Claude 对技术术语、代码、开发工作流的理解优于通用 LLM
  4. 可控性:通过 prompt 工程,DevLingo 能精确控制输出格式和质量

DevLingo 的 Claude 调用包含精心设计的 prompt template:

You are an English learning assistant for developers.
The user selected: "{selectedText}"
Mode: {mode}
User's native language: {userLanguage}
Current application: {sourceApp}
Surrounding context: "{context}"
Respond with JSON in the following structure:
{
"mode": "word|phrase|sentence|paragraph|express",
... [detailed schema]
}
Important:
1. Examples must be from software development context
2. Provide 2-3 examples per item
3. For native speakers of {userLanguage}, highlight common interference patterns
4. If applicable, note pronunciation and stress patterns
5. Keep definitions concise (< 20 words)

这个 prompt 确保:

  • 输出格式一致
  • 例句来自开发语境
  • L1 干扰被重视
  • 结果对学习有针对性
功能字典 APIDevLingo AI
基础定义
多个例句✓(通常无针对性)✓(都是技术场景)
上下文感知✓(知道你用的什么应用)
L1 干扰提示
结构化输出✗(只是文本)✓(JSON,UI 友好)
技术术语加成✓(etymology, 行业基准等)
同义词辨析✗(列出同义词)✓(解释差异)
发音与 IPA✓(部分)✓(完整 + 4 种口音)

:::note 为什么分层不用 AI DevLingo 的分层查询系统确保:

  • 常用词汇(命中本地库):0ms AI,100% 快
  • 缓存命中(用户之前查过):0ms AI,100% 快
  • 冷门词汇(AI 调用):<2s 完成,仍然快

这样用户 95% 的查询无需 API 调用,既降低成本,也提升体验。 :::

DevLingo 的 AI 引擎不是为了”翻译”,而是为了”理解和教学”。它知道你在做什么,知道你的语言背景,知道怎样教你才最有效。