|
@@ -319,7 +319,7 @@ def ai_chat_text(token_id,app_id,wxid,msg_data,msg_content): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(reply_content, list) : |
|
|
if isinstance(reply_content, list) : |
|
|
reply_content=reply_content[0].get('text').get("content") |
|
|
|
|
|
|
|
|
reply_content=remove_markdown_symbol(reply_content[0].get('text').get("content")) |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
reply_content=text |
|
|
reply_content=text |
|
@@ -327,8 +327,8 @@ def ai_chat_text(token_id,app_id,wxid,msg_data,msg_content): |
|
|
memory.USER_INTERACTIVE_CACHE[wxid] = { |
|
|
memory.USER_INTERACTIVE_CACHE[wxid] = { |
|
|
"interactive":False |
|
|
"interactive":False |
|
|
} |
|
|
} |
|
|
reply_content=res["choices"][0]["message"]["content"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply_content=remove_markdown_symbol(res["choices"][0]["message"]["content"]) |
|
|
|
|
|
|
|
|
gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,reply_content) |
|
|
gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,reply_content) |
|
|
gewe_chat.wxchat.save_session_messages_to_cache(hash_key, {"role": "assistant", "content": reply_content}) |
|
|
gewe_chat.wxchat.save_session_messages_to_cache(hash_key, {"role": "assistant", "content": reply_content}) |
|
|
# 回复的对话 |
|
|
# 回复的对话 |
|
@@ -873,8 +873,31 @@ def check_chatroom(userName): |
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
# def remove_markdown_symbol(text: str): |
|
|
|
|
|
# # 移除markdown格式,目前先移除** |
|
|
|
|
|
# if not text or not isinstance(text, str): |
|
|
|
|
|
# return text |
|
|
|
|
|
# return re.sub(r'\*\*(.*?)\*\*', r'\1', text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_markdown_symbol(text: str): |
|
|
def remove_markdown_symbol(text: str): |
|
|
# 移除markdown格式,目前先移除** |
|
|
# 移除markdown格式,目前先移除** |
|
|
if not text or not isinstance(text, str): |
|
|
if not text or not isinstance(text, str): |
|
|
return text |
|
|
return text |
|
|
return re.sub(r'\*\*(.*?)\*\*', r'\1', text) |
|
|
|
|
|
|
|
|
# 去除加粗、斜体等格式 |
|
|
|
|
|
#text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text) # 去除加粗 |
|
|
|
|
|
text=re.sub(r'\*\*(.*?)\*\*', r'\1', text) |
|
|
|
|
|
text = re.sub(r'\*([^*]+)\*', r'\1', text) # 去除斜体 |
|
|
|
|
|
text = re.sub(r'__([^_]+)__', r'\1', text) # 去除加粗(下划线) |
|
|
|
|
|
text = re.sub(r'_(.*?)_', r'\1', text) # 去除斜体(下划线) |
|
|
|
|
|
|
|
|
|
|
|
# 去除行内代码块 |
|
|
|
|
|
text = re.sub(r'`([^`]+)`', r'\1', text) |
|
|
|
|
|
|
|
|
|
|
|
# 去除换行符\n,或者多余的空格 |
|
|
|
|
|
#text = re.sub(r'\n+', ' ', text) |
|
|
|
|
|
|
|
|
|
|
|
# 去除列表编号等 |
|
|
|
|
|
#text = re.sub(r'^\d+\.\s*', '', text, flags=re.MULTILINE) |
|
|
|
|
|
print(text) |
|
|
|
|
|
return text |