'commit'
This commit is contained in:
@@ -59,6 +59,16 @@ async def generate_dao_xue_an(request: Request):
|
|||||||
# 获取难度参数(默认为"默认难度")
|
# 获取难度参数(默认为"默认难度")
|
||||||
difficulty = params.get("difficulty", "默认难度")
|
difficulty = params.get("difficulty", "默认难度")
|
||||||
|
|
||||||
|
# 难度级别中英文映射
|
||||||
|
difficulty_map = {
|
||||||
|
"basic": "基础",
|
||||||
|
"intermediate": "提高",
|
||||||
|
"advanced": "进阶",
|
||||||
|
"默认难度": "默认难度"
|
||||||
|
}
|
||||||
|
# 转换为中文难度名称
|
||||||
|
chinese_difficulty = difficulty_map.get(difficulty, difficulty)
|
||||||
|
|
||||||
# 生成唯一文件名
|
# 生成唯一文件名
|
||||||
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
||||||
|
|
||||||
@@ -68,7 +78,7 @@ async def generate_dao_xue_an(request: Request):
|
|||||||
temp_md_path = temp_md.name
|
temp_md_path = temp_md.name
|
||||||
|
|
||||||
# 使用Pandoc转换为Word
|
# 使用Pandoc转换为Word
|
||||||
docx_filename = f"导学案_{difficulty}_{timestamp}.docx"
|
docx_filename = f"导学案_{chinese_difficulty}_{timestamp}.docx"
|
||||||
docx_path = os.path.join(save_dir, docx_filename)
|
docx_path = os.path.join(save_dir, docx_filename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Binary file not shown.
@@ -466,13 +466,32 @@
|
|||||||
userPrompt = `${userPrompt}\n\n${difficultyPrompts[difficulty]}`;
|
userPrompt = `${userPrompt}\n\n${difficultyPrompts[difficulty]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送请求(保持原有代码不变)
|
// 获取难度参数
|
||||||
|
let difficulty = "默认难度";
|
||||||
|
if (resourceType === 'daoXueAn') {
|
||||||
|
const difficultySelector = document.getElementById('daoXueAnDifficulty');
|
||||||
|
difficulty = difficultySelector.querySelector('.difficulty-btn.active').dataset.difficulty;
|
||||||
|
} else if (resourceType === 'zuoYe') {
|
||||||
|
const difficultySelector = document.getElementById('zuoYeDifficulty');
|
||||||
|
difficulty = difficultySelector.querySelector('.difficulty-btn.active').dataset.difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求参数
|
||||||
|
const requestData = {
|
||||||
|
resourceType: resourceType,
|
||||||
|
userPrompt: userPrompt,
|
||||||
|
difficulty: difficulty, // 添加此行传递难度参数
|
||||||
|
};
|
||||||
|
// 添加调试日志
|
||||||
|
console.log('请求参数:', requestData);
|
||||||
|
console.log('难度值:', difficulty);
|
||||||
const response = await fetch(`/api/teacher/${resourceType}`, {
|
const response = await fetch(`/api/teacher/${resourceType}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
system_prompt: systemPrompt,
|
system_prompt: systemPrompt,
|
||||||
user_prompt: userPrompt // 发送拼接后的提示词
|
user_prompt: userPrompt, // 发送拼接后的提示词
|
||||||
|
difficulty:difficulty
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -502,7 +521,9 @@
|
|||||||
|
|
||||||
if (cleanLine.includes('[下载链接]')) {
|
if (cleanLine.includes('[下载链接]')) {
|
||||||
const url = cleanLine.split('[下载链接]')[1].trim();
|
const url = cleanLine.split('[下载链接]')[1].trim();
|
||||||
const fileName = `${getResourceName(resourceType)}_${new Date().toLocaleDateString().replace(/\//g, '-')}.docx`;
|
console.log(url);
|
||||||
|
// 从URL中提取文件名(最后一个/后面的部分)
|
||||||
|
const fileName = url.split('/').pop();
|
||||||
resultContainer.innerHTML += `<a href="${url}" class="download-btn" download="${fileName}"><i class="bi bi-download me-2"></i>下载${getResourceName(resourceType)}\n</a>`;
|
resultContainer.innerHTML += `<a href="${url}" class="download-btn" download="${fileName}"><i class="bi bi-download me-2"></i>下载${getResourceName(resourceType)}\n</a>`;
|
||||||
shouldHideLoading = true;
|
shouldHideLoading = true;
|
||||||
} else if (cleanLine.includes('[转换失败]')) {
|
} else if (cleanLine.includes('[转换失败]')) {
|
||||||
@@ -527,15 +548,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置状态
|
|
||||||
function resetState(loadingElement, generateButton) {
|
|
||||||
loadingElement.style.display = 'none';
|
|
||||||
generateButton.disabled = false;
|
|
||||||
generateButton.classList.remove('btn-disabled');
|
|
||||||
generateButton.innerHTML = `<i class="bi bi-magic me-2"></i>生成${getResourceName(resourceType).replace(/^./, c => c.toLowerCase())}`;
|
|
||||||
}
|
|
||||||
function showComingSoon() {
|
function showComingSoon() {
|
||||||
alert("敬请期待");
|
alert("敬请期待");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user