更改了temperature参数与prompt,IPA更加精准
This commit is contained in:
@@ -15,7 +15,7 @@ async function callZhipuAPI(messages: { role: string, content: string }[], model
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: model,
|
model: model,
|
||||||
messages: messages,
|
messages: messages,
|
||||||
temperature: 0.5,
|
temperature: 0.2,
|
||||||
thinking: {
|
thinking: {
|
||||||
type: 'disabled'
|
type: 'disabled'
|
||||||
}
|
}
|
||||||
@@ -29,37 +29,31 @@ async function callZhipuAPI(messages: { role: string, content: string }[], model
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// callZhipuAPI(messages)
|
|
||||||
// .then(result => {
|
|
||||||
// console.log(result.choices[0].message.content);
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// console.error('错误:', error);
|
|
||||||
// });
|
|
||||||
|
|
||||||
async function getIPAFromLLM(text: string) {
|
async function getIPAFromLLM(text: string) {
|
||||||
|
console.log(text);
|
||||||
const messages = [
|
const messages = [
|
||||||
{
|
{
|
||||||
role: 'user', content: `
|
role: 'user', content: `
|
||||||
[TEXT]
|
请推断下面文本的语言,并返回其宽式国际音标(IPA),以JSON格式
|
||||||
请推断以上文本的语言,并返回其宽式国际音标(IPA),以JSON格式
|
[[TEXT]]
|
||||||
如:
|
结果如:
|
||||||
{
|
{
|
||||||
"lang": "german",
|
"lang": "german",
|
||||||
"ipa": "[ˈɡuːtn̩ ˈtaːk]"
|
"ipa": "[ˈɡuːtn̩ ˈtaːk]"
|
||||||
}
|
}
|
||||||
注意:直接返回json文本,
|
注意:
|
||||||
不要带markdown记号,
|
直接返回json文本,
|
||||||
ipa一定要加[],
|
ipa一定要加[],
|
||||||
lang的值是小写英语的语言名称
|
lang的值是小写字母的英文的语言名称
|
||||||
`.replace('[TEXT]', text)
|
`.replace('[TEXT]', text)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
const response = await callZhipuAPI(messages);
|
const response = await callZhipuAPI(messages);
|
||||||
return JSON.parse(response.choices[0].message.content);
|
let to_parse = response.choices[0].message.content.trim() as string;
|
||||||
|
if (to_parse.startsWith('`')) to_parse = to_parse.slice(7, to_parse.length - 3);
|
||||||
|
if (to_parse.length === 0) throw Error('ai啥也每说');
|
||||||
|
return JSON.parse(to_parse);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user