update: 2026-03-28 20:59
This commit is contained in:
@@ -35,28 +35,22 @@ function clearResults() {
|
||||
}
|
||||
|
||||
async function callKinshipAPI(relationChain) {
|
||||
const token = window.AUTH_CONFIG.getToken();
|
||||
if (!token) throw new Error('未登录,请先登录后使用AI功能');
|
||||
|
||||
const url = `${window.API_CONFIG.baseUrl}${window.API_CONFIG.endpoints.kinshipCalculator}`;
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ relation_chain: relationChain })
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
if (resp.status === 402) throw new Error('您的萌芽币余额不足,无法使用此功能');
|
||||
const err = await resp.json().catch(() => ({}));
|
||||
throw new Error(err.error || `API请求失败: ${resp.status} ${resp.statusText}`);
|
||||
const content = await window.AiChat.complete([
|
||||
{ role: 'user', content: window.AiPrompts.kinship(relationChain) },
|
||||
]);
|
||||
var parsed;
|
||||
try {
|
||||
parsed = JSON.parse(content);
|
||||
} catch (e) {
|
||||
var m = content.match(/\{[\s\S]*\}/);
|
||||
parsed = m ? JSON.parse(m[0]) : {};
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
if (!data.success) throw new Error(data.error || 'API响应异常');
|
||||
return data;
|
||||
return {
|
||||
success: true,
|
||||
mandarin_title: parsed.mandarin_title,
|
||||
dialect_titles: parsed.dialect_titles,
|
||||
notes: parsed.notes,
|
||||
};
|
||||
}
|
||||
|
||||
function renderDialects(dialectTitles) {
|
||||
|
||||
Reference in New Issue
Block a user