feat: newbing接入
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from revChatGPT.V1 import Chatbot, Error
|
||||
from revChatGPT.V1 import Chatbot
|
||||
|
||||
class revChatGPT:
|
||||
def __init__(self, config):
|
||||
@@ -32,16 +32,12 @@ class revChatGPT:
|
||||
for data in self.chatbot.ask(prompt):
|
||||
resp = data["message"]
|
||||
break
|
||||
except Error as e:
|
||||
except BaseException as e:
|
||||
try:
|
||||
if e.code == 2:
|
||||
print("[RevChatGPT] 频率限制")
|
||||
print("[RevChatGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
|
||||
err_count += 1
|
||||
if err_count >= retry_count:
|
||||
raise e
|
||||
else:
|
||||
print("[RevChatGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
|
||||
err_count += 1
|
||||
if err_count >= retry_count:
|
||||
raise e
|
||||
except BaseException:
|
||||
err_count += 1
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
from EdgeGPT import Chatbot, ConversationStyle
|
||||
import json
|
||||
|
||||
class revEdgeGPT:
|
||||
def __init__(self):
|
||||
with open('./cookies.json', 'r') as f:
|
||||
cookies = json.load(f)
|
||||
self.bot = Chatbot(cookies=cookies)
|
||||
|
||||
async def chat(self, prompt):
|
||||
resp = 'err'
|
||||
err_count = 0
|
||||
retry_count = 5
|
||||
|
||||
while err_count < retry_count:
|
||||
try:
|
||||
resp = await self.bot.ask(prompt=prompt, conversation_style=ConversationStyle.creative)
|
||||
resp = resp['item']['messages'][len(resp['item']['messages'])-1]['text']
|
||||
break
|
||||
except BaseException as e:
|
||||
err_count += 1
|
||||
if err_count >= retry_count:
|
||||
raise e
|
||||
print("[RevEdgeGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
|
||||
|
||||
print("[RevEdgeGPT] "+str(resp))
|
||||
return resp
|
||||
+15
-2
@@ -61,12 +61,13 @@ direct_message_mode = True
|
||||
abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/'
|
||||
|
||||
# 版本
|
||||
version = '2.7 ChineseAreGood Ver.'
|
||||
version = '2.9'
|
||||
|
||||
# 语言模型提供商
|
||||
REV_CHATGPT = 'rev_chatgpt'
|
||||
OPENAI_OFFICIAL = 'openai_official'
|
||||
REV_ERNIE = 'rev_ernie'
|
||||
REV_EDGEGPT = 'rev_edgegpt'
|
||||
provider = ''
|
||||
|
||||
# 逆向库对象及负载均衡
|
||||
@@ -184,7 +185,7 @@ def upload():
|
||||
初始化机器人
|
||||
'''
|
||||
def initBot(cfg, prov):
|
||||
global chatgpt, provider, rev_chatgpt, baidu_judge, rev_ernie
|
||||
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
|
||||
|
||||
provider = prov
|
||||
@@ -246,6 +247,10 @@ def initBot(cfg, prov):
|
||||
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 'baidu_aip' in cfg and 'enable' in cfg['baidu_aip'] and cfg['baidu_aip']['enable']:
|
||||
@@ -659,6 +664,14 @@ def oper_msg(message, at=False, msg_ref = None):
|
||||
print("[System-Err] Rev ERNIE API错误。原因如下:\n"+str(e))
|
||||
send_qq_msg(message, f"Rev ERNIE API错误。原因如下:\n{str(e)} \n前往官方频道反馈~")
|
||||
return
|
||||
elif provider == REV_EDGEGPT:
|
||||
try:
|
||||
chatgpt_res = "[RevBing]"
|
||||
chatgpt_res = asyncio.run(rev_edgegpt.chat(qq_msg))
|
||||
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.flush()
|
||||
|
||||
@@ -33,6 +33,8 @@ def privider_chooser(cfg):
|
||||
return 'rev_chatgpt'
|
||||
elif 'rev_ernie' in cfg and cfg['rev_ernie']['enable']:
|
||||
return 'rev_ernie'
|
||||
elif 'rev_edgegpt' in cfg and cfg['rev_edgegpt']['enable']:
|
||||
return 'rev_edgegpt'
|
||||
else:
|
||||
return 'openai_official'
|
||||
|
||||
|
||||
+2
-1
@@ -2,4 +2,5 @@ requests
|
||||
openai
|
||||
qq-botpy
|
||||
revChatGPT~=4.0.8
|
||||
baidu-aip
|
||||
baidu-aip
|
||||
EdgeGPT~=0.1.2
|
||||
Reference in New Issue
Block a user