@alauda/doom 0.18.10 → 0.18.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,8 @@ import matter from 'gray-matter';
12
12
  import { AzureOpenAI, RateLimitError } from 'openai';
13
13
  import { pRateLimit } from 'p-ratelimit';
14
14
  import { glob } from 'tinyglobby';
15
+ import { fetchApi } from 'x-fetch';
16
+ import { parse } from 'yaml';
15
17
  import { cyan, red } from 'yoctocolors';
16
18
  import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
17
19
  import { pathExists } from '../utils/index.js';
@@ -32,10 +34,7 @@ const DEFAULT_SYSTEM_PROMPT = `
32
34
  - MDX 组件中包含的内容需要翻译,MDX 组件参数的值不需要翻译,但以下这些特殊的 MDX 组件参数值需要翻译
33
35
  * 组件示例: <Tab label="参数值">组件包含的内容</Tab>,label 是 key 不用翻译,"参数值" 需要翻译
34
36
  - 以下是常见的相关术语词汇对应表(中文 -> English)
35
- * ACP -> ACP
36
- * 灵雀云 -> Alauda
37
- * 容器组 -> Pods
38
- * global 集群 -> global cluster
37
+ <%= terms %>
39
38
  - 如果存在下列注释,请保留不用翻译,更不要修改注释内容
40
39
  - {/* release-notes-for-bugs */}
41
40
  - <!-- release-notes-for-bugs -->
@@ -64,22 +63,29 @@ const DEFAULT_SYSTEM_PROMPT = `
64
63
  <%= additionalPrompts %>
65
64
  `.trim();
66
65
  let openai;
66
+ const resolveTerms = async () => {
67
+ const terms = await fetchApi('https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
68
+ const parsedTerms = parse(terms);
69
+ return parsedTerms.map(({ en, zh = en }) => ` * ${zh} -> ${en}`).join('\n');
70
+ };
67
71
  export const translate = async ({ source, sourceContent, target, targetContent = '', systemPrompt, userPrompt = '', additionalPrompts = '', }) => {
68
72
  if (!openai) {
69
73
  openai = new AzureOpenAI({
70
74
  endpoint: process.env.AZURE_OPENAI_ENDPOINT ||
71
75
  'https://apt-docs-openai.openai.azure.com',
72
76
  apiKey: process.env.AZURE_OPENAI_API_KEY || 'doom',
73
- apiVersion: process.env.OPENAI_API_VERSION || '2025-01-01-preview',
77
+ apiVersion: process.env.OPENAI_API_VERSION || '2025-03-01-preview',
74
78
  });
75
79
  }
76
80
  const sourceLang = LANGUAGE_CODES[source];
77
81
  const targetLang = LANGUAGE_CODES[target];
82
+ const terms = await resolveTerms();
83
+ logger.debug('Resolved terms:\n' + terms);
78
84
  const { choices } = await openai.beta.chat.completions.parse({
79
85
  messages: [
80
86
  {
81
87
  role: 'system',
82
- content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, userPrompt, additionalPrompts }, { async: true }),
88
+ content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, userPrompt, additionalPrompts, terms }, { async: true }),
83
89
  },
84
90
  {
85
91
  role: 'user',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.18.10",
3
+ "version": "0.18.12",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
@@ -45,7 +45,7 @@
45
45
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
46
46
  "@playwright/browser-chromium": "^1.51.1",
47
47
  "@rsbuild/plugin-yaml": "^1.0.2",
48
- "@rspress/core": "1.43.10",
48
+ "@rspress/core": "1.43.11",
49
49
  "@shikijs/transformers": "^3.2.1",
50
50
  "chokidar": "^4.0.3",
51
51
  "cli-progress": "^3.12.0",
@@ -72,6 +72,7 @@
72
72
  "swagger2openapi": "^7.0.8",
73
73
  "tinyglobby": "^0.2.12",
74
74
  "type-fest": "^4.39.1",
75
+ "x-fetch": "^0.2.5",
75
76
  "yaml": "^2.7.1",
76
77
  "yoctocolors": "^2.1.1"
77
78
  },