'commit'
This commit is contained in:
@@ -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}
|
||||
|
@@ -7,6 +7,11 @@
|
||||
<link rel="stylesheet" href="physics_quiz.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 权限问题链接移到顶部 -->
|
||||
<div style="position: fixed; top: 10px; right: 10px; z-index: 9999; background: rgba(255,255,255,0.9); padding: 5px 10px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
|
||||
<a href="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/11%E3%80%81%E5%AD%A6%E4%BC%B4Chrome%E5%BD%95%E9%9F%B3%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9.pdf" style="color: #007bff; text-decoration: none; font-size: 14px;">有权限问题?</a>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>物理知识测验 - 万有引力定律</h1>
|
||||
@@ -105,9 +110,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/11%E3%80%81%E5%AD%A6%E4%BC%B4Chrome%E5%BD%95%E9%9F%B3%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9.pdf">有权限问题?</a>
|
||||
</div>
|
||||
<!-- 移除底部的权限问题链接,已经移到顶部 -->
|
||||
|
||||
<!-- 引入看板娘相关脚本 -->
|
||||
<script src="https://l2dwidget.js.org/lib/L2Dwidget.min.js"></script>
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user