Merge pull request #48 from Soulter/42-openai_api_domain_customization
fix: 解决newbing换话题的问题;解决newbing回复慢的问题
This commit is contained in:
@@ -4,11 +4,26 @@ import json
|
||||
|
||||
class revEdgeGPT:
|
||||
def __init__(self):
|
||||
self.busy = False
|
||||
self.wait_stack = []
|
||||
with open('./cookies.json', 'r') as f:
|
||||
cookies = json.load(f)
|
||||
self.bot = Chatbot(cookies=cookies)
|
||||
|
||||
def is_busy(self):
|
||||
return self.busy
|
||||
|
||||
async def reset(self):
|
||||
try:
|
||||
await self.bot.reset()
|
||||
return False
|
||||
except BaseException:
|
||||
return True
|
||||
|
||||
async def chat(self, prompt):
|
||||
if self.busy:
|
||||
return
|
||||
self.busy = True
|
||||
resp = 'err'
|
||||
err_count = 0
|
||||
retry_count = 5
|
||||
@@ -17,12 +32,16 @@ class revEdgeGPT:
|
||||
try:
|
||||
resp = await self.bot.ask(prompt=prompt, conversation_style=ConversationStyle.creative)
|
||||
resp = resp['item']['messages'][len(resp['item']['messages'])-1]['text']
|
||||
if resp == prompt:
|
||||
resp += '\n\n如果你没有让我复述你的话,那代表我可能不想和你继续这个话题了,请输入/reset重置会话😶'
|
||||
break
|
||||
except BaseException as e:
|
||||
print(e.with_traceback)
|
||||
err_count += 1
|
||||
if err_count >= retry_count:
|
||||
raise e
|
||||
print("[RevEdgeGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
|
||||
self.busy = False
|
||||
|
||||
print("[RevEdgeGPT] "+str(resp))
|
||||
return resp
|
||||
@@ -666,8 +666,12 @@ def oper_msg(message, at=False, msg_ref = None):
|
||||
return
|
||||
elif provider == REV_EDGEGPT:
|
||||
try:
|
||||
if rev_edgegpt.is_busy():
|
||||
send_qq_msg(message, f"[RevBing] 正忙,请稍后再试",msg_ref=msg_ref)
|
||||
return
|
||||
else:
|
||||
chatgpt_res = "[RevBing]"
|
||||
chatgpt_res = asyncio.run(rev_edgegpt.chat(qq_msg))
|
||||
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前往官方频道反馈~")
|
||||
@@ -744,7 +748,7 @@ def get_stat():
|
||||
def command_oper(qq_msg, message, session_id, name, user_id, user_name, at):
|
||||
go = False # 是否处理完指令后继续执行msg_oper后面的代码
|
||||
msg = ''
|
||||
global session_dict, now_personality, provider
|
||||
global session_dict, now_personality, provider, rev_edgegpt, client
|
||||
|
||||
# 指令返回值,/set设置人格是1
|
||||
type = -1
|
||||
@@ -752,8 +756,12 @@ def command_oper(qq_msg, message, session_id, name, user_id, user_name, at):
|
||||
# 指令控制
|
||||
if qq_msg == "/reset" or qq_msg == "/重置":
|
||||
msg = ''
|
||||
if provider == REV_EDGEGPT and rev_edgegpt is not None:
|
||||
asyncio.run_coroutine_threadsafe(rev_edgegpt.reset(), client.loop).result()
|
||||
else:
|
||||
session_dict[session_id] = []
|
||||
if at:
|
||||
|
||||
msg = f"{name}(id: {session_id})的历史记录重置成功\n\n{announcement}"
|
||||
else:
|
||||
msg = f"你的历史记录重置成功"
|
||||
|
||||
Reference in New Issue
Block a user