1.添加定时任务(每天凌晨四点处理redis记录的删除,存储入mysql持久化操作)
2.修复了prompt中没有用户输入信息的bug 3.优化了更新类接口代码(删除了db.add()代码)
This commit is contained in:
1 parent
de370f77ac
commit
065528f509
7 files changed
+65
-16
No files matched your search
@@ -89,13 +89,20 @@ def vad_preprocess(audio):
|
||||
return ('A'*1280)
|
||||
return audio[:1280],audio[1280:]
|
||||
|
||||
#更新session活跃时间
|
||||
def update_session_activity(session_id,db):
|
||||
try:
|
||||
db.query(Session).filter(Session.id == session_id).update({"last_activity": datetime.now()})
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
db.roolback()
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
||||
#--------------------------------------------------------
|
||||
|
||||
# 创建新聊天
|
||||
async def create_chat_handler(chat: ChatCreateRequest, db, redis):
|
||||
# 创建新的UserCharacter记录
|
||||
new_chat = UserCharacter(user_id=chat.user_id, character_id=chat.character_id)
|
||||
|
||||
try:
|
||||
db.add(new_chat)
|
||||
db.commit()
|
||||
@@ -279,8 +286,6 @@ async def sct_llm_handler(ws,session_id,response_type,llm_info,tts_info,db,redis
|
||||
logger.debug(f"llm返回结果: {llm_response}")
|
||||
await ws.send_text(json.dumps({"type": "end", "code": 200, "msg": ""}, ensure_ascii=False))
|
||||
is_end = False #重置is_end标志位
|
||||
session_content = get_session_content(session_id,redis,db)
|
||||
messages = json.loads(session_content["messages"])
|
||||
messages.append({'role': 'assistant', "content": llm_response})
|
||||
session_content["messages"] = json.dumps(messages,ensure_ascii=False) #更新对话
|
||||
redis.set(session_id,json.dumps(session_content,ensure_ascii=False)) #更新session
|
||||
@@ -304,6 +309,7 @@ async def streaming_chat_temporary_handler(ws: WebSocket, db, redis):
|
||||
|
||||
|
||||
session_id = await future_session_id #获取session_id
|
||||
update_session_activity(session_id,db)
|
||||
response_type = await future_response_type #获取返回类型
|
||||
tts_info = json.loads(get_session_content(session_id,redis,db)["tts_info"])
|
||||
llm_info = json.loads(get_session_content(session_id,redis,db)["llm_info"])
|
||||
@@ -425,8 +431,6 @@ async def scl_llm_handler(ws,session_id,response_type,llm_info,tts_info,db,redis
|
||||
await ws.send_text(json.dumps({"type": "end", "code": 200, "msg": ""}, ensure_ascii=False))
|
||||
is_end = False
|
||||
|
||||
session_content = get_session_content(session_id,redis,db)
|
||||
messages = json.loads(session_content["messages"])
|
||||
messages.append({'role': 'assistant', "content": llm_response})
|
||||
session_content["messages"] = json.dumps(messages,ensure_ascii=False) #更新对话
|
||||
redis.set(session_id,json.dumps(session_content,ensure_ascii=False)) #更新session
|
||||
@@ -454,6 +458,7 @@ async def streaming_chat_lasting_handler(ws,db,redis):
|
||||
asyncio.create_task(scl_asr_handler(user_input_q,llm_input_q,input_finished_event,asr_finished_event))
|
||||
|
||||
session_id = await future_session_id #获取session_id
|
||||
update_session_activity(session_id,db)
|
||||
response_type = await future_response_type #获取返回类型
|
||||
tts_info = json.loads(get_session_content(session_id,redis,db)["tts_info"])
|
||||
llm_info = json.loads(get_session_content(session_id,redis,db)["llm_info"])
|
||||
@@ -575,8 +580,6 @@ async def voice_call_llm_handler(ws,session_id,llm_info,tts_info,db,redis,asr_re
|
||||
await ws.send_text(json.dumps({"type": "end", "code": 200, "msg": ""}, ensure_ascii=False))
|
||||
is_end = False
|
||||
|
||||
session_content = get_session_content(session_id,redis,db)
|
||||
messages = json.loads(session_content["messages"])
|
||||
messages.append({'role': 'assistant', "content": llm_response})
|
||||
session_content["messages"] = json.dumps(messages,ensure_ascii=False) #更新对话
|
||||
redis.set(session_id,json.dumps(session_content,ensure_ascii=False)) #更新session
|
||||
@@ -622,6 +625,7 @@ async def voice_call_handler(ws, db, redis):
|
||||
|
||||
#获取session内容
|
||||
session_id = await future #获取session_id
|
||||
update_session_activity(session_id,db)
|
||||
tts_info = json.loads(get_session_content(session_id,redis,db)["tts_info"])
|
||||
llm_info = json.loads(get_session_content(session_id,redis,db)["llm_info"])
|
||||
|
||||
|
||||
Reference in new issue
Block a user