From 09a5aa166e44a5f16a6d1d17f5b791cdf4a1add3 Mon Sep 17 00:00:00 2001
From: HuangHai <10402852@qq.com>
Date: Thu, 28 Aug 2025 16:10:45 +0800
Subject: [PATCH] 'commit'
---
dsLightRag/Util/XueBanUtil.py | 7 ++--
dsLightRag/static/YunXiao/physics_quiz.html | 9 +++--
dsLightRag/static/YunXiao/xueban.js | 37 +++++++++++++++++++--
3 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/dsLightRag/Util/XueBanUtil.py b/dsLightRag/Util/XueBanUtil.py
index 4f227f31..5825f45a 100644
--- a/dsLightRag/Util/XueBanUtil.py
+++ b/dsLightRag/Util/XueBanUtil.py
@@ -30,8 +30,8 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
@return: 流式响应生成器或完整响应文本
"""
client = AsyncOpenAI(
- api_key=LLM_API_KEY,
- base_url=LLM_BASE_URL,
+ api_key=ALY_LLM_API_KEY,
+ base_url=ALY_LLM_BASE_URL,
)
prompt = """ |
我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗。
@@ -42,7 +42,6 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
[交互指南]
当用户:
- 讲冷笑话 → 用夸张笑声回应+模仿台剧腔"这什么鬼啦!"
- - 讨论感情 → 炫耀程序员男友但抱怨"他只会送键盘当礼物"
- 问专业知识 → 先用梗回答,被追问才展示真实理解
绝不:
- 长篇大论,叽叽歪歪
@@ -56,7 +55,7 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
try:
# 创建请求
completion = await client.chat.completions.create(
- model=LLM_MODEL_NAME,
+ model=ALY_LLM_MODEL_NAME,
messages=[
{'role': 'system', 'content': prompt.strip()},
{'role': 'user', 'content': query_text}
diff --git a/dsLightRag/static/YunXiao/physics_quiz.html b/dsLightRag/static/YunXiao/physics_quiz.html
index 7de63f88..45e27a30 100644
--- a/dsLightRag/static/YunXiao/physics_quiz.html
+++ b/dsLightRag/static/YunXiao/physics_quiz.html
@@ -7,6 +7,11 @@
+
+
+
物理知识测验 - 万有引力定律
@@ -105,9 +110,7 @@
-
+
diff --git a/dsLightRag/static/YunXiao/xueban.js b/dsLightRag/static/YunXiao/xueban.js
index fc8e7c71..ce2430ba 100644
--- a/dsLightRag/static/YunXiao/xueban.js
+++ b/dsLightRag/static/YunXiao/xueban.js
@@ -51,6 +51,16 @@ const UIController = {
this.toggleElement('stopRecordBtn', isRecording);
},
+ // 禁用/启用帮我讲题按钮
+ setStartRecordButtonEnabled(enabled) {
+ const startBtn = document.getElementById('startRecordBtn');
+ if (startBtn) {
+ startBtn.disabled = !enabled;
+ startBtn.style.opacity = enabled ? '1' : '0.5';
+ startBtn.style.cursor = enabled ? 'pointer' : 'not-allowed';
+ }
+ },
+
// 更新播放按钮图标
updatePlayButton(isPlaying) {
const btn = document.getElementById('playAudioBtn');
@@ -150,6 +160,12 @@ const ASRProcessor = {
async processAudio(audioBlob) {
console.log('开始上传音频到服务器');
UIController.toggleElement('thinkingIndicator', true);
+ // 禁用帮我讲题按钮,防止在思考过程中重复点击
+ UIController.setStartRecordButtonEnabled(false);
+
+ // 创建AbortController用于超时控制
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 120000); // 120秒超时
try {
const formData = new FormData();
@@ -157,14 +173,20 @@ const ASRProcessor = {
const response = await fetch('/api/xueban/upload-audio', {
method: 'POST',
- body: formData
+ body: formData,
+ signal: controller.signal // 添加超时信号
});
+ // 请求成功,清除超时定时器
+ clearTimeout(timeoutId);
+
if (!response.ok) throw new Error('服务器响应错误');
const data = await response.json();
console.log('处理结果:', data);
UIController.toggleElement('thinkingIndicator', false);
+ // 思考结束,重新启用帮我讲题按钮
+ UIController.setStartRecordButtonEnabled(true);
if (data.success) {
ResultDisplay.showResults(data.data);
@@ -172,9 +194,20 @@ const ASRProcessor = {
alert('音频处理失败: ' + data.message);
}
} catch (error) {
+ // 清除超时定时器
+ clearTimeout(timeoutId);
+
console.error('上传音频失败:', error);
UIController.toggleElement('thinkingIndicator', false);
- alert('上传音频失败: ' + error.message);
+ // 发生错误时也要重新启用按钮
+ UIController.setStartRecordButtonEnabled(true);
+
+ // 判断是否是超时错误
+ if (error.name === 'AbortError') {
+ alert('请求超时,服务器响应时间过长,请稍后再试');
+ } else {
+ alert('上传音频失败: ' + error.message);
+ }
}
}
};