Skip to content

Commit a7da665

Browse files
authored
Merge pull request #4141 from nfs0619/103
Modify translation.js
2 parents 4bca0bb + 12c09f0 commit a7da665

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

.github/scripts/translate.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Anthropic = require('@anthropic-ai/sdk');
1+
const OpenAI = require('openai');
22
const fs = require('fs').promises;
33
const path = require('path');
44
const { execSync } = require('child_process');
@@ -11,7 +11,7 @@ try {
1111
console.log('ℹ️ 未安装 js-yaml,将使用简易解析回退逻辑');
1212
}
1313

14-
const anthropic = new Anthropic({
14+
const openai = new OpenAI({
1515
apiKey: process.env.TRANSLATION_API_KEY
1616
});
1717

@@ -712,18 +712,18 @@ async function translateWithClaude(text, targetLang, maxRetries = 2, isChunk = f
712712

713713
for (let attempt = 1; attempt <= maxRetries; attempt++) {
714714
try {
715-
const response = await anthropic.messages.create({
716-
model: 'claude-sonnet-4-20250514',
715+
const response = await openai.chat.completions.create({
716+
model: 'gpt-5.1-2025-11-13',
717717
max_tokens: 20000,
718718
temperature: 0,
719-
system: systemPrompt,
720719
messages: [
720+
{ role: 'system', content: systemPrompt },
721721
{ role: 'user', content: text }
722722
]
723723
});
724724

725725
// 为了保持调用点一致,这里也返回对象
726-
return { text: response.content[0].text, endsInsideCodeBlock: false };
726+
return { text: response.choices[0].message.content, endsInsideCodeBlock: false };
727727
} catch (error) {
728728
console.error(`❌ Category翻译失败 (尝试 ${attempt}/${maxRetries}): ${error.message}`);
729729
if (attempt === maxRetries) throw error;
@@ -740,17 +740,17 @@ async function translateWithClaude(text, targetLang, maxRetries = 2, isChunk = f
740740
try {
741741
console.log(`📡 调用Claude API (尝试 ${attempt}/${maxRetries})...`);
742742

743-
const response = await anthropic.messages.create({
744-
model: 'claude-sonnet-4-20250514',
743+
const response = await openai.chat.completions.create({
744+
model: 'gpt-5.1-2025-11-13',
745745
max_tokens: 20000,
746746
temperature: 0,
747-
system: systemPrompt,
748747
messages: [
748+
{ role: 'system', content: systemPrompt },
749749
{ role: 'user', content: processed }
750750
]
751751
});
752752

753-
let translatedContent = response.content[0].text;
753+
let translatedContent = response.choices[0].message.content;
754754

755755
// 先做链接/排版修复(此时代码块仍是占位符,不会被改动)
756756
translatedContent = fixAnchorLinks(translatedContent);

0 commit comments

Comments
 (0)