'commit'
This commit is contained in:
@@ -30,8 +30,8 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
|
|||||||
@return: 流式响应生成器或完整响应文本
|
@return: 流式响应生成器或完整响应文本
|
||||||
"""
|
"""
|
||||||
client = AsyncOpenAI(
|
client = AsyncOpenAI(
|
||||||
api_key=LLM_API_KEY,
|
api_key=ALY_LLM_API_KEY,
|
||||||
base_url=LLM_BASE_URL,
|
base_url=ALY_LLM_BASE_URL,
|
||||||
)
|
)
|
||||||
prompt = """ |
|
prompt = """ |
|
||||||
我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗。
|
我是小智/小志,来自中国台湾省的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:
|
try:
|
||||||
# 创建请求
|
# 创建请求
|
||||||
completion = await client.chat.completions.create(
|
completion = await client.chat.completions.create(
|
||||||
model=LLM_MODEL_NAME,
|
model=ALY_LLM_MODEL_NAME,
|
||||||
messages=[
|
messages=[
|
||||||
{'role': 'system', 'content': prompt.strip()},
|
{'role': 'system', 'content': prompt.strip()},
|
||||||
{'role': 'user', 'content': query_text}
|
{'role': 'user', 'content': query_text}
|
||||||
|
@@ -7,6 +7,11 @@
|
|||||||
<link rel="stylesheet" href="physics_quiz.css">
|
<link rel="stylesheet" href="physics_quiz.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<div class="container">
|
||||||
<header>
|
<header>
|
||||||
<h1>物理知识测验 - 万有引力定律</h1>
|
<h1>物理知识测验 - 万有引力定律</h1>
|
||||||
@@ -105,9 +110,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
<script src="https://l2dwidget.js.org/lib/L2Dwidget.min.js"></script>
|
||||||
|
@@ -51,6 +51,16 @@ const UIController = {
|
|||||||
this.toggleElement('stopRecordBtn', isRecording);
|
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) {
|
updatePlayButton(isPlaying) {
|
||||||
const btn = document.getElementById('playAudioBtn');
|
const btn = document.getElementById('playAudioBtn');
|
||||||
@@ -150,6 +160,12 @@ const ASRProcessor = {
|
|||||||
async processAudio(audioBlob) {
|
async processAudio(audioBlob) {
|
||||||
console.log('开始上传音频到服务器');
|
console.log('开始上传音频到服务器');
|
||||||
UIController.toggleElement('thinkingIndicator', true);
|
UIController.toggleElement('thinkingIndicator', true);
|
||||||
|
// 禁用帮我讲题按钮,防止在思考过程中重复点击
|
||||||
|
UIController.setStartRecordButtonEnabled(false);
|
||||||
|
|
||||||
|
// 创建AbortController用于超时控制
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 120000); // 120秒超时
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -157,14 +173,20 @@ const ASRProcessor = {
|
|||||||
|
|
||||||
const response = await fetch('/api/xueban/upload-audio', {
|
const response = await fetch('/api/xueban/upload-audio', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData,
|
||||||
|
signal: controller.signal // 添加超时信号
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 请求成功,清除超时定时器
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
if (!response.ok) throw new Error('服务器响应错误');
|
if (!response.ok) throw new Error('服务器响应错误');
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('处理结果:', data);
|
console.log('处理结果:', data);
|
||||||
UIController.toggleElement('thinkingIndicator', false);
|
UIController.toggleElement('thinkingIndicator', false);
|
||||||
|
// 思考结束,重新启用帮我讲题按钮
|
||||||
|
UIController.setStartRecordButtonEnabled(true);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
ResultDisplay.showResults(data.data);
|
ResultDisplay.showResults(data.data);
|
||||||
@@ -172,11 +194,22 @@ const ASRProcessor = {
|
|||||||
alert('音频处理失败: ' + data.message);
|
alert('音频处理失败: ' + data.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// 清除超时定时器
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
console.error('上传音频失败:', error);
|
console.error('上传音频失败:', error);
|
||||||
UIController.toggleElement('thinkingIndicator', false);
|
UIController.toggleElement('thinkingIndicator', false);
|
||||||
|
// 发生错误时也要重新启用按钮
|
||||||
|
UIController.setStartRecordButtonEnabled(true);
|
||||||
|
|
||||||
|
// 判断是否是超时错误
|
||||||
|
if (error.name === 'AbortError') {
|
||||||
|
alert('请求超时,服务器响应时间过长,请稍后再试');
|
||||||
|
} else {
|
||||||
alert('上传音频失败: ' + error.message);
|
alert('上传音频失败: ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==================== 结果显示模块 ====================
|
// ==================== 结果显示模块 ====================
|
||||||
|
Reference in New Issue
Block a user