feat: 支持在配置文件自定义回复前缀 #57

This commit is contained in:
Soulter
2023-03-30 04:53:26 +00:00
parent 608bd0398e
commit b7b7877dfc
2 changed files with 26 additions and 5 deletions
+8
View File
@@ -1,5 +1,7 @@
# 如果你不知道怎么部署,请务必查看https://soulter.top/posts/qpdg.html
# 不一定需要key了,如果你没有key但有openAI账号或者必应账号,也可以使用下面的逆向库
# 注意:已支持多key自动切换,方法:
# key:
# - sk-xxxxxx
@@ -53,6 +55,12 @@ direct_message_mode: true
# http_proxy: http://localhost:7890
# https_proxy: http://localhost:7890
# 自定义回复前缀,如[Rev]或其他,务必加引号以防止不必要的bug。
reply_prefix:
openai_official: "[GPT]"
rev_chatgpt: "[Rev]"
rev_edgegpt: "[RevBing]"
################外带程序(插件)################
+18 -5
View File
@@ -82,6 +82,9 @@ gpt_config = {}
# 百度内容审核实例
baidu_judge = None
# 回复前缀
reply_prefix = ''
def new_sub_thread(func, args=()):
thread = threading.Thread(target=func, args=args, daemon=True)
@@ -189,10 +192,13 @@ def upload():
'''
def initBot(cfg, prov):
global chatgpt, provider, rev_chatgpt, baidu_judge, rev_ernie, rev_edgegpt
global now_personality, gpt_config, config, uniqueSession, history_dump_interval, frequency_count, frequency_time,announcement, direct_message_mode, version
global reply_prefix, now_personality, gpt_config, config, uniqueSession, history_dump_interval, frequency_count, frequency_time,announcement, direct_message_mode, version
provider = prov
config = cfg
reply_prefix_config = None
if 'reply_prefix' in cfg:
reply_prefix_config = cfg['reply_prefix']
# 语言模型提供商
if prov == REV_CHATGPT:
@@ -209,6 +215,8 @@ def initBot(cfg, prov):
except:
print("[System] 创建rev_ChatGPT负载失败")
if REV_CHATGPT in reply_prefix_config:
reply_prefix = reply_prefix_config[REV_CHATGPT]
else:
input("[System-err] 请退出本程序, 然后在配置文件中填写rev_ChatGPT相关配置")
elif prov == OPENAI_OFFICIAL:
@@ -247,12 +255,17 @@ def initBot(cfg, prov):
# 得到GPT配置信息
if 'openai' in cfg and 'chatGPTConfigs' in cfg['openai']:
gpt_config = cfg['openai']['chatGPTConfigs']
if OPENAI_OFFICIAL in reply_prefix_config:
reply_prefix = reply_prefix_config[OPENAI_OFFICIAL]
elif prov == REV_ERNIE:
from addons.revERNIE import revernie
rev_ernie = revernie.wx
elif prov == REV_EDGEGPT:
from addons.revEdgeGPT import revedgegpt
rev_edgegpt = revedgegpt.revEdgeGPT()
if REV_EDGEGPT in reply_prefix_config:
reply_prefix = reply_prefix_config[REV_EDGEGPT]
# 百度内容审核
@@ -703,14 +716,14 @@ def oper_msg(message, at=False, msg_ref = None):
elif provider == REV_CHATGPT:
try:
chatgpt_res = "[Rev]"+str(get_rev_ChatGPT_response(qq_msg))
chatgpt_res = reply_prefix+str(get_rev_ChatGPT_response(qq_msg))
except BaseException as e:
print("[System-Err] Rev ChatGPT API错误。原因如下:\n"+str(e))
send_qq_msg(message, f"Rev ChatGPT API错误。原因如下:\n{str(e)} \n前往官方频道反馈~")
return
elif provider == REV_ERNIE:
try:
chatgpt_res = "[RevERNIE]"+str(rev_ernie.chatViaSelenium(qq_msg))
chatgpt_res = reply_prefix+str(rev_ernie.chatViaSelenium(qq_msg))
except BaseException as e:
print("[System-Err] Rev ERNIE API错误。原因如下:\n"+str(e))
send_qq_msg(message, f"Rev ERNIE API错误。原因如下:\n{str(e)} \n前往官方频道反馈~")
@@ -721,14 +734,14 @@ def oper_msg(message, at=False, msg_ref = None):
send_qq_msg(message, f"[RevBing] 正忙,请稍后再试",msg_ref=msg_ref)
return
else:
chatgpt_res = "[RevBing]"
chatgpt_res = reply_prefix
chatgpt_res += str(asyncio.run_coroutine_threadsafe(rev_edgegpt.chat(qq_msg), client.loop).result())
except BaseException as e:
print("[System-Err] Rev NewBing API错误。原因如下:\n"+str(e))
send_qq_msg(message, f"Rev NewBing API错误。原因如下:\n{str(e)} \n前往官方频道反馈~")
return
# 记录日志
logf.write("[GPT] "+ str(chatgpt_res)+'\n')
logf.write(f"{reply_prefix} {str(chatgpt_res)}\n")
logf.flush()
if qq_msg[0] != '':