You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
11 KiB

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>问答系统</title>
<style>
body {
font-family: 'Microsoft YaHei', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #333;
text-align: center;
}
.data-area {
background-color: white;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.input-area {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
textarea {
width: 100%;
height: 40px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
resize: none;
margin-bottom: 10px;
margin-right: 20px; /* 新增右侧边距 */
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #45a049;
}
#clearBtn {
background-color: #f44336;
}
#clearBtn:hover {
background-color: #d32f2f;
}
#saveWordBtn {
background-color: #2196F3;
}
#saveWordBtn:hover {
background-color: #0b7dda;
}
.icon {
margin-right: 5px;
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 2s linear infinite;
margin: 20px auto;
display: none;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.doc-links {
display: flex;
gap: 20px;
margin: 20px 0;
align-items: center;
}
.doc-link {
padding: 8px 15px;
background-color: #e7f3fe;
border-radius: 4px;
color: #2196F3;
text-decoration: none;
transition: all 0.3s;
}
.doc-link:hover {
background-color: #d0e3fa;
}
.doc-checkboxes {
display: flex;
gap: 20px;
margin-bottom: 10px;
}
.doc-checkboxes label {
display: flex;
align-items: center;
gap: 5px;
cursor: pointer;
}
.examples {
margin: 20px 0;
}
.example-category {
margin-bottom: 15px;
}
.example-category h3 {
margin-bottom: 10px;
color: #333;
}
.example-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.example-item {
padding: 8px 12px;
background-color: #e9f5ff;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
}
.example-item:hover {
background-color: #d0e3fa;
}
.input-area textarea#questionInput {
margin-right: 10px !important;
width: calc(100% - 10px);
box-sizing: border-box;
}
#answerArea {
min-height: 240px; /* 12行高度 */
height: auto;
overflow-y: auto; /* 添加滚动条 */
}
</style>
</head>
<body>
<div class="container">
<h1>【东师理想】教学大模型知识库</h1>
<div class="data-area" id="answerArea">
<div style="color:#666; padding:20px; text-align:center;">
<p>请在下方输入您的问题,答案将在此处显示</p>
<p>您也可以点击"示例问题"快速体验</p>
</div>
</div>
<div class="input-area">
<textarea id="questionInput" placeholder="请输入您的问题..."></textarea>
<div class="examples">
<div class="example-category">
<h3>知识库内问题示例:</h3>
<div class="example-list">
<div class="example-item" onclick="fillExample('小学数学中有哪些模型?')">小学数学中有哪些模型?</div>
<div class="example-item" onclick="fillExample('帮我写一下 “如何理解点、线、面、体、角”的教学设计')">
帮我写一下 “如何理解点、线、面、体、角”的教学设计
</div>
<div class="example-item" onclick="fillExample('文言虚词')">请解释一下“文言虚词”</div>
</div>
</div>
<div class="example-category">
<h3>知识库外问题示例:</h3>
<div class="example-list">
<div class="example-item" onclick="fillExample('微积分的基本定理是什么?')">微积分的基本定理是什么?
</div>
<div class="example-item" onclick="fillExample('线性代数在AI中的应用')">线性代数在AI中的应用</div>
</div>
</div>
</div>
<div class="doc-links">
<h3>知识库范围</h3>
<div class="doc-checkboxes">
<label>
<input type="checkbox" name="documents" value="MATH_DATA_1">
小学数学教学中的若干问题
</label>
<label>
<input type="checkbox" name="documents" value="MATH_DATA_2">
小学数学知识点
</label>
<label>
<input type="checkbox" name="documents" value="CHINESE_DATA_1">
高中语文文言文
</label>
</div>
</div>
<div><h3>知识库文稿下载</h3>
<a href="/static/Txt/小学数学教学中的若干问题.docx" class="doc-link">小学数学教学中的若干问题</a>
<a href="/static/Txt/小学数学知识点.docx" class="doc-link">小学数学知识点</a>
<a href="/static/Txt/高中文言文.docx" class="doc-link">高中语文文言文</a>
</div>
<br>
<button id="submitBtn" onclick="submitQuestion()"><span class="icon">💡</span>提问</button>
<button id="clearBtn" onclick="clearAll()"><span class="icon">🗑️</span>清空</button>
<button id="saveWordBtn" onclick="saveToWord()"><span class="icon">📄</span>保存为Word</button>
<div class="loader" id="loader"></div>
</div>
</div>
<script>
function fillExample(question) {
document.getElementById('questionInput').value = question;
}
function submitQuestion() {
const question = document.getElementById('questionInput').value.trim();
const checkboxes = document.querySelectorAll('input[name="documents"]:checked');
if (!question) {
alert('请输入问题!');
return;
}
if (checkboxes.length === 0) {
alert('请至少选择一个原稿!');
return;
}
const selectedDocs = Array.from(checkboxes).map(cb => cb.value);
const loader = document.getElementById('loader');
loader.style.display = 'block';
fetch('/api/rag', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: question,
documents: selectedDocs
})
})
.then(response => response.json()) // 改回使用json()
.then(data => {
loader.style.display = 'none';
if (data && data.data) {
document.getElementById('answerArea').innerHTML = data.data;
} else {
alert('服务器返回了无效数据');
}
})
.catch(error => {
loader.style.display = 'none';
console.error('Error:', error);
alert('请求失败: ' + error.message);
});
}
function clearAll() {
document.getElementById('questionInput').value = '';
document.getElementById('answerArea').innerHTML = '';
document.querySelectorAll('input[name="documents"]').forEach(cb => cb.checked = false);
}
function saveToWord() {
const htmlContent = document.getElementById('answerArea').innerHTML;
const checkboxes = document.querySelectorAll('input[name="documents"]:checked');
if (!htmlContent) {
alert('没有内容可保存!');
return;
}
if (checkboxes.length === 0) {
alert('请至少选择一个原稿!');
return;
}
const selectedDocs = Array.from(checkboxes).map(cb => cb.value);
const loader = document.getElementById('loader');
loader.style.display = 'block';
fetch('/api/save-word', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
html_content: htmlContent,
documents: selectedDocs
})
})
.then(response => response.blob())
.then(blob => {
loader.style.display = 'none';
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '小学数学问答.docx';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
})
.catch(error => {
loader.style.display = 'none';
console.error('Error:', error);
alert('保存失败,请稍后再试!');
});
}
</script>
</body>
</html>