|
@@ -98,6 +98,12 @@ async def handle_self_cmd_async(request: Request,wxid,msg): |
|
|
await request.app.state.gewe_service.wxchat.save_wxchat_config_async(wxid, agent_config.model_dump()) |
|
|
await request.app.state.gewe_service.wxchat.save_wxchat_config_async(wxid, agent_config.model_dump()) |
|
|
logger.info(f'{wxid} {"启动" if commands[msg_content] else "关闭"}托管') |
|
|
logger.info(f'{wxid} {"启动" if commands[msg_content] else "关闭"}托管') |
|
|
|
|
|
|
|
|
|
|
|
# async def handle_kf_assistant_async(request: Request,wxid,msg): |
|
|
|
|
|
# msg_data=msg.get("Data") |
|
|
|
|
|
# from_wxid=msg_data["FromUserName"]["string"] |
|
|
|
|
|
# msg_content=msg_data["Content"]["string"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def handle_messages_async(request: Request,token_id,msg): |
|
|
async def handle_messages_async(request: Request,token_id,msg): |
|
|
#msg_data=msg.get("Data") |
|
|
#msg_data=msg.get("Data") |
|
|
type_name =msg.get("TypeName") |
|
|
type_name =msg.get("TypeName") |
|
@@ -119,43 +125,6 @@ async def handle_messages_async(request: Request,token_id,msg): |
|
|
case _: |
|
|
case _: |
|
|
logger.warning(f'未知消息类型:{type_name}') |
|
|
logger.warning(f'未知消息类型:{type_name}') |
|
|
|
|
|
|
|
|
# async def gpt_client_async(request,messages: list, wixd: str, friend_wxid: str): |
|
|
|
|
|
# c = await request.app.state.gewe_service.get_wxchat_config_from_cache_async(wixd) |
|
|
|
|
|
# api_key = c.get('agentTokenId', "sk-jr69ONIehfGKe9JFphuNk4DU5Y5wooHKHhQv7oSnFzVbwCnW65fXO9kvH") |
|
|
|
|
|
# print(f'流程key:{api_key}\n') |
|
|
|
|
|
|
|
|
|
|
|
# #api_key="sk-jr69ONIehfGKe9JFphuNk4DU5Y5wooHKHhQv7oSnFzVbwCnW65fXO9kvH" #测试 |
|
|
|
|
|
# #api_key="sk-uJDBdKmJVb2cmfldGOvlIY6Qx0AzqWMPD3lS1IzgQYzHNOXv9SKNI" #开发2 |
|
|
|
|
|
|
|
|
|
|
|
# api_url = "http://106.15.182.218:3000/api/v1/chat/completions" |
|
|
|
|
|
# headers = { |
|
|
|
|
|
# "Content-Type": "application/json", |
|
|
|
|
|
# "Authorization": f"Bearer {api_key}" |
|
|
|
|
|
# } |
|
|
|
|
|
|
|
|
|
|
|
# session_id = f'{wixd}-{friend_wxid}' |
|
|
|
|
|
# data = { |
|
|
|
|
|
# "model": "", |
|
|
|
|
|
# "messages": messages, |
|
|
|
|
|
# "chatId": session_id, |
|
|
|
|
|
# "detail": True |
|
|
|
|
|
# } |
|
|
|
|
|
|
|
|
|
|
|
# logger.info("[CHATGPT] 请求={}".format(json.dumps(data, ensure_ascii=False))) |
|
|
|
|
|
|
|
|
|
|
|
# async with aiohttp.ClientSession() as session: |
|
|
|
|
|
# try: |
|
|
|
|
|
# async with session.post(url=api_url, headers=headers, data=json.dumps(data), timeout=600) as response: |
|
|
|
|
|
# response.raise_for_status() |
|
|
|
|
|
# response_data = await response.json() |
|
|
|
|
|
# logger.info("[CHATGPT] 响应={}".format(json.dumps(response_data, separators=(',', ':'), ensure_ascii=False))) |
|
|
|
|
|
# return response_data |
|
|
|
|
|
# except aiohttp.ClientError as e: |
|
|
|
|
|
# logger.error(f"[CHATGPT] 请求失败: {e}") |
|
|
|
|
|
# raise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def gpt_client_async(request, messages: list, wixd: str, friend_wxid: str): |
|
|
async def gpt_client_async(request, messages: list, wixd: str, friend_wxid: str): |
|
|
max_retries = 3 |
|
|
max_retries = 3 |
|
|
retry_delay = 5 # 重试间隔时间(秒) |
|
|
retry_delay = 5 # 重试间隔时间(秒) |
|
@@ -455,6 +424,26 @@ async def handle_text_async(request: Request,token_id,app_id, wxid,msg_data,from |
|
|
contact_nick_name=next(filter(lambda x:x.get("userName") == callback_to_user,contacts_brief),{}).get("nickName","") |
|
|
contact_nick_name=next(filter(lambda x:x.get("userName") == callback_to_user,contacts_brief),{}).get("nickName","") |
|
|
assistant_msg_content=f'AI管家转人工提醒:【{contact_nick_name}】有{found_keywords[0]}需求' |
|
|
assistant_msg_content=f'AI管家转人工提醒:【{contact_nick_name}】有{found_keywords[0]}需求' |
|
|
await request.app.state.gewe_service.post_text_async(token_id, app_id, 'wxid_9pocbage7cdb22', assistant_msg_content) |
|
|
await request.app.state.gewe_service.post_text_async(token_id, app_id, 'wxid_9pocbage7cdb22', assistant_msg_content) |
|
|
|
|
|
|
|
|
|
|
|
k,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async('wxid_9pocbage7cdb22') |
|
|
|
|
|
if not k: |
|
|
|
|
|
logger.warning(f'助理微信号 wxid_9pocbage7cdb22 不存在') |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
staus=loginfo.get('status','0') |
|
|
|
|
|
if staus != '1': |
|
|
|
|
|
logger.warning(f'助理微信号 wxid_9pocbage7cdb22 不在线') |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
kf_token_id=loginfo.get('tokenId','') |
|
|
|
|
|
kf_appid=loginfo.get('appId','') |
|
|
|
|
|
|
|
|
|
|
|
assistant_msg_content=f'收到,{assistant_msg_content}' |
|
|
|
|
|
await request.app.state.gewe_service.post_text_async(kf_token_id, kf_appid, callback_to_user, assistant_msg_content) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|