'commit'
This commit is contained in:
@@ -12,6 +12,9 @@ router = APIRouter(prefix="/api", tags=["学伴"])
|
||||
# 配置日志
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 导入学伴工具函数
|
||||
from Util.XueBanUtil import get_xueban_response_async
|
||||
|
||||
|
||||
@router.post("/xueban/upload-audio")
|
||||
async def upload_audio(file: UploadFile = File(...)):
|
||||
@@ -73,4 +76,49 @@ async def process_asr(audio_path: str) -> dict:
|
||||
# 这里应该集成实际的ASR服务
|
||||
# 例如百度AI、阿里云、讯飞等ASR服务
|
||||
# 或者本地的ASR模型
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
@router.post("/xueban/chat")
|
||||
async def chat_with_xueban(request: Request):
|
||||
"""
|
||||
与学伴大模型聊天的接口
|
||||
- 参数: request body 中的 query_text (用户查询文本)
|
||||
- 返回: JSON包含聊天响应
|
||||
"""
|
||||
try:
|
||||
# 获取请求体数据
|
||||
data = await request.json()
|
||||
query_text = data.get("query_text", "")
|
||||
|
||||
if not query_text.strip():
|
||||
return JSONResponse(content={
|
||||
"success": False,
|
||||
"message": "查询文本不能为空"
|
||||
}, status_code=400)
|
||||
|
||||
# 记录日志
|
||||
logger.info(f"接收到学伴聊天请求: {query_text}")
|
||||
|
||||
# 调用异步接口获取学伴响应
|
||||
response_content = []
|
||||
async for chunk in get_xueban_response_async(query_text, stream=True):
|
||||
response_content.append(chunk)
|
||||
|
||||
full_response = "".join(response_content)
|
||||
|
||||
# 返回响应
|
||||
return JSONResponse(content={
|
||||
"success": True,
|
||||
"message": "聊天成功",
|
||||
"data": {
|
||||
"response": full_response
|
||||
}
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"学伴聊天失败: {str(e)}")
|
||||
return JSONResponse(content={
|
||||
"success": False,
|
||||
"message": f"聊天处理失败: {str(e)}"
|
||||
}, status_code=500)
|
Binary file not shown.
BIN
dsLightRag/Routes/__pycache__/XueBanRoute.cpython-310.pyc
Normal file
BIN
dsLightRag/Routes/__pycache__/XueBanRoute.cpython-310.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user