-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加 彩云小译,星火lite 翻译 优化引擎命名
- Loading branch information
Showing
13 changed files
with
134 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// caiyun.js | ||
const API_URL = 'http://api.interpreter.caiyunai.com/v1/translator'; | ||
const TOKEN = process.env.CAIYUN_API_KEY | ||
|
||
async function caiyun_Translate(text, source_lang = "auto", target_lang = "zh") { | ||
try { | ||
const payload = { | ||
source: Array.isArray(text) ? text : [text], | ||
trans_type: `${source_lang}2${target_lang}`, | ||
request_id: "demo", | ||
detect: true | ||
}; | ||
|
||
const response = await fetch(API_URL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-Authorization": `token ${TOKEN}` | ||
}, | ||
body: JSON.stringify(payload) | ||
}); | ||
|
||
const data = await response.json(); | ||
|
||
return JSON.stringify({ | ||
model: "caiyun", | ||
raw: text, | ||
text: data.target[0], | ||
from: source_lang, | ||
to: target_lang | ||
}); | ||
} catch (error) { | ||
console.error("Caiyun API error:", error); | ||
return null; | ||
} | ||
} | ||
|
||
export { caiyun_Translate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
async function xinghuo_lite_Translate(text, source_lang, target_lang) { | ||
try { | ||
const url = "https://spark-api-open.xf-yun.com/v1/chat/completions"; | ||
const data = { | ||
model: "lite", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: "You are a professional translation engine, please translate the text into a colloquial, professional, elegant and fluent content, without the style of machine translation. You must only translate the text content, never interpret it.", | ||
}, | ||
{ | ||
role: "assistant", | ||
content: "Ok, I will only translate the text content, never interpret it.", | ||
}, | ||
{ | ||
role: "user", | ||
content: `Translate into Chinese """hello"""`, | ||
}, | ||
{ | ||
role: "assistant", | ||
content: "你好", | ||
}, | ||
{ | ||
role: "user", | ||
content: `Translate into ${target_lang} """${text}"""`, | ||
}, | ||
] | ||
}; | ||
|
||
const headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${process.env.XINGHUO_API_KEY}`, | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const result = await response.json(); | ||
|
||
return JSON.stringify({ | ||
model: "xinghuo_lite", | ||
raw: text, | ||
text: result.choices[0].message.content, | ||
from: source_lang, | ||
to: target_lang, | ||
}); | ||
} catch (error) { | ||
console.error("xinghuo_lite error:", error); | ||
return null; | ||
} | ||
} | ||
|
||
export { xinghuo_lite_Translate }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters