-
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.
添加 GLM 全系模型
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 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,58 @@ | ||
async function glm_4_air_Translate(text, source_lang, target_lang) { | ||
try { | ||
const url = "https://open.bigmodel.cn/api/paas/v4/chat/completions"; | ||
const data = { | ||
model: "glm-4-air", | ||
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.GLM_API_KEY}`, | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const result = await response.json(); | ||
console.log(result.choices[0].message); | ||
|
||
return JSON.stringify({ | ||
model: "glm_4_air", | ||
raw: text, | ||
text: result.choices[0].message.content, | ||
from: source_lang, | ||
to: target_lang, | ||
}); | ||
} catch (error) { | ||
console.error("glm_4_air error:", error); | ||
return null; | ||
} | ||
} | ||
|
||
export { glm_4_air_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
async function glm_4_flash_Translate(text, source_lang, target_lang) { | ||
try { | ||
const url = "https://open.bigmodel.cn/api/paas/v4/chat/completions"; | ||
const data = { | ||
model: "glm-4-flash", | ||
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.GLM_API_KEY}`, | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const result = await response.json(); | ||
console.log(result.choices[0].message); | ||
|
||
return JSON.stringify({ | ||
model: "glm_4_flash", | ||
raw: text, | ||
text: result.choices[0].message.content, | ||
from: source_lang, | ||
to: target_lang, | ||
}); | ||
} catch (error) { | ||
console.error("glm_4_flash error:", error); | ||
return null; | ||
} | ||
} | ||
|
||
export { glm_4_flash_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
async function glm_4_plus_Translate(text, source_lang, target_lang) { | ||
try { | ||
const url = "https://open.bigmodel.cn/api/paas/v4/chat/completions"; | ||
const data = { | ||
model: "glm-4-plus", | ||
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.GLM_API_KEY}`, | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const result = await response.json(); | ||
console.log(result.choices[0].message); | ||
|
||
return JSON.stringify({ | ||
model: "glm_4_plus", | ||
raw: text, | ||
text: result.choices[0].message.content, | ||
from: source_lang, | ||
to: target_lang, | ||
}); | ||
} catch (error) { | ||
console.error("glm_4_plus error:", error); | ||
return null; | ||
} | ||
} | ||
|
||
export { glm_4_plus_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