update: 2026-03-28 20:59

This commit is contained in:
2026-03-28 20:59:52 +08:00
parent e21d58e603
commit 1c81d4e6ea
611 changed files with 27847 additions and 65061 deletions

View File

@@ -56,7 +56,9 @@
</div>
</div>
<script src="/aimodelapp/shared/ai-prompts.js"></script>
<script src="env.js"></script>
<script src="/aimodelapp/shared/ai-chat.js"></script>
<script src="script.js"></script>
</body>
</html>

View File

@@ -8,46 +8,12 @@ const translateBtn = document.getElementById('translateBtn');
const loadingDiv = document.getElementById('loading');
const translationResultContainer = document.getElementById('translationResult');
// 调用后端API
// 调用后端统一 chat提示词在前端
async function callBackendAPI(sourceText, targetLanguage) {
try {
// 获取JWT token
const token = localStorage.getItem('token');
if (!token) {
throw new Error('未登录请先登录后使用AI功能');
}
const response = await fetch(`${window.API_CONFIG.baseUrl}/api/aimodelapp/translation`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
source_text: sourceText,
target_language: targetLanguage
})
});
if (!response.ok) {
if (response.status === 402) {
throw new Error('您的萌芽币余额不足,无法使用此功能');
}
const errorData = await response.json();
throw new Error(errorData.error || `API请求失败: ${response.status} ${response.statusText}`);
}
const data = await response.json();
if (data.success) {
return data.translation_result;
} else {
throw new Error(data.error || 'API响应格式异常');
}
} catch (error) {
console.error('API调用错误:', error);
throw error;
}
const content = await window.AiChat.complete(
[{ role: 'user', content: window.AiPrompts.translation(sourceText, targetLanguage) }]
);
return content;
}
// 解析AI响应