mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 07:54:19 +00:00
Bug修复
This commit is contained in:
+5
-25
@@ -4,7 +4,6 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import json
|
||||
@@ -21,8 +20,6 @@ import pkg.plugin.models as plugin_models
|
||||
sessions = {}
|
||||
|
||||
|
||||
|
||||
|
||||
class SessionOfflineStatus:
|
||||
ON_GOING = 'on_going'
|
||||
EXPLICITLY_CLOSED = 'explicitly_closed'
|
||||
@@ -131,15 +128,13 @@ class Session:
|
||||
logging.debug('{},lock release successfully,{}'.format(self.name, self.response_lock))
|
||||
|
||||
# 从配置文件获取会话预设信息
|
||||
# get_only: 仅返回初始prompt, 不更改该session的bot_name和bot_filter
|
||||
def get_default_prompt(self, use_default: str = None, get_only = False):
|
||||
|
||||
config = pkg.utils.context.get_config()
|
||||
|
||||
import pkg.openai.dprompt as dprompt
|
||||
|
||||
if use_default is None:
|
||||
use_default = dprompt.get_current()
|
||||
|
||||
use_default = dprompt.get_current()
|
||||
current_default_prompt = \
|
||||
[
|
||||
{
|
||||
@@ -150,15 +145,15 @@ class Session:
|
||||
'content': 'ok'
|
||||
}
|
||||
]
|
||||
|
||||
# 根据设置进行prompt预设模式
|
||||
|
||||
if config.preset_mode == "full_scenario":
|
||||
|
||||
import os
|
||||
logging.info("A")
|
||||
##
|
||||
dir = os.path.join(os.getcwd(), config.full_prompt_dir)
|
||||
json_file = os.path.join(dir, use_default) + '.json'
|
||||
|
||||
logging.info("B")
|
||||
logging.info("try to load json: {}".format(json_file))
|
||||
|
||||
try:
|
||||
@@ -189,8 +184,6 @@ class Session:
|
||||
self.schedule()
|
||||
|
||||
self.response_lock = threading.Lock()
|
||||
self.bot_name = 'ai'
|
||||
self.bot_filter = None
|
||||
self.prompt = self.get_default_prompt()
|
||||
|
||||
# 设定检查session最后一次对话是否超过过期时间的计时器
|
||||
@@ -264,23 +257,10 @@ class Session:
|
||||
del (res_ans_spt[0])
|
||||
res_ans = '\n\n'.join(res_ans_spt)
|
||||
|
||||
#检测是否包含ai人格否定
|
||||
logging.debug('bot_filter: {}'.format(self.bot_filter))
|
||||
if config.filter_ai_warning and self.bot_filter:
|
||||
import re
|
||||
match = re.search(self.bot_filter['reg'], res_ans)
|
||||
logging.debug(self.bot_filter)
|
||||
logging.debug(res_ans)
|
||||
if match:
|
||||
logging.debug('回复:{}, 检测到人格否定,替换中。。'.format(res_ans))
|
||||
res_ans = self.bot_filter['replace']
|
||||
logging.debug('替换为: {}'.format(res_ans))
|
||||
|
||||
# 将此次对话的双方内容加入到prompt中
|
||||
self.prompt.append({'role': 'user', 'content': text})
|
||||
self.prompt.append({'role': 'assistant', 'content': res_ans})
|
||||
|
||||
|
||||
if self.just_switched_to_exist_session:
|
||||
self.just_switched_to_exist_session = False
|
||||
self.set_ongoing()
|
||||
|
||||
Reference in New Issue
Block a user