From 9327f2c2df06452f77c6375c8fa39eafb5e33c7b Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 26 Mar 2023 22:20:14 +0800 Subject: [PATCH 1/4] [bug fixed]caused by EdgeGPT 0.1.10 update --- model/bing/jailbroken_sydney.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model/bing/jailbroken_sydney.py b/model/bing/jailbroken_sydney.py index bacaff3..581f788 100644 --- a/model/bing/jailbroken_sydney.py +++ b/model/bing/jailbroken_sydney.py @@ -50,7 +50,7 @@ class SydneyBot(Chatbot): conversation_style: EdgeGPT.CONVERSATION_STYLE_TYPE = None, message_id: str = None, ) -> dict: - #开启新对话 + # 开启新对话 self.chat_hub = SydneyHub(Conversation( self.cookiePath, self.cookies, self.proxy)) self.parent_message_id = message_id if message_id != None else uuid.uuid4() @@ -129,7 +129,7 @@ class SydneyHub(ChatHub): prompt: str, conversation_style: EdgeGPT.CONVERSATION_STYLE_TYPE = None, ) -> Generator[str, None, None]: - async for item in super().ask_stream(prompt, conversation_style): + async for item in super().ask_stream(prompt=prompt, conversation_style=conversation_style): yield item @@ -142,8 +142,8 @@ class SydneyHubRequest(ChatHubRequest): conversation_id: str, invocation_id: int = 0, ) -> None: - super().__init__(conversation_signature, client_id, - conversation_id, invocation_id) + super().__init__(conversation_signature=conversation_signature, client_id=client_id, + conversation_id=conversation_id, invocation_id=invocation_id) self.previous_messages = "" def update( @@ -153,7 +153,7 @@ class SydneyHubRequest(ChatHubRequest): options: list | None = None, ) -> None: self.invocation_id = 0 - super().update(prompt, conversation_style, options) + super().update(prompt=prompt, conversation_style=conversation_style, options=options) self.struct["arguments"][0]["message"]["messageType"] = "SearchQuery" self.struct["arguments"][0]["previousMessages"] = [ {"text": "N/A\n\n"+self.previous_messages, "author": 'bot', }] From dc4f2423b5406c983e92ee86c090e5f52798f404 Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 26 Mar 2023 22:33:26 +0800 Subject: [PATCH 2/4] [bug fixed]caused by EdgeGPT 0.1.10 update --- model/bing/jailbroken_sydney.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/bing/jailbroken_sydney.py b/model/bing/jailbroken_sydney.py index 581f788..9cd0ece 100644 --- a/model/bing/jailbroken_sydney.py +++ b/model/bing/jailbroken_sydney.py @@ -127,9 +127,10 @@ class SydneyHub(ChatHub): async def ask_stream( self, prompt: str, + wss_link: str = "wss://sydney.bing.com/sydney/ChatHub", conversation_style: EdgeGPT.CONVERSATION_STYLE_TYPE = None, ) -> Generator[str, None, None]: - async for item in super().ask_stream(prompt=prompt, conversation_style=conversation_style): + async for item in super().ask_stream(prompt=prompt, conversation_style=conversation_style, wss_link=wss_link): yield item From 947dcf81a7a380b534a6bcc8eedaaaaf2f92b3b8 Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 26 Mar 2023 23:31:26 +0800 Subject: [PATCH 3/4] [bing]handling errors caused by the content filter --- model/bing/jailbroken_sydney.py | 3 +++ model/bing/new_bing_model.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/model/bing/jailbroken_sydney.py b/model/bing/jailbroken_sydney.py index 9cd0ece..cfc6cbb 100644 --- a/model/bing/jailbroken_sydney.py +++ b/model/bing/jailbroken_sydney.py @@ -44,6 +44,9 @@ class SydneyBot(Chatbot): return ordered_messages + def pop_last_conversation(self): + self.conversations_cache[self.conversation_key]["messages"].pop() + async def ask( self, prompt: str, diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index fc78be5..aaddaa9 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -1,7 +1,7 @@ # encoding:utf-8 import asyncio from model.model import Model -from config import model_conf_val +from config import model_conf_val,common_conf_val from common import log from EdgeGPT import Chatbot, ConversationStyle from ImageGen import ImageGen @@ -29,6 +29,10 @@ class BingModel(Model): def reply(self, query: str, context=None) -> tuple[str, dict]: if not context or not context.get('type') or context.get('type') == 'TEXT': + clear_memory_commands = common_conf_val('clear_memory_commands', ['#清除记忆']) + if query in clear_memory_commands: + user_session[context['from_user_id']]=None + return '记忆已清除' bot = user_session.get(context['from_user_id'], None) if (bot == None): bot = self.bot @@ -46,8 +50,13 @@ class BingModel(Model): task = bot.ask(query, conversation_style=self.style,message_id=bot.user_message_id) else: task = bot.ask(query, conversation_style=self.style) - answer = asyncio.run(task) - + + try: + answer = asyncio.run(task) + except Exception as e: + bot.pop_last_conversation() + log.exception(answer) + return f"AI生成内容被微软内容过滤器拦截,已删除最后一次提问的记忆,请尝试使用其他文字描述问题,若AI依然无法正常回复,请使用{clear_memory_commands[0]}命令清楚全部记忆" # 最新一条回复 try: reply = answer["item"]["messages"][-1] From bd59fd056db84e13716a48738c212f899c921937 Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 26 Mar 2023 23:33:21 +0800 Subject: [PATCH 4/4] edit description text --- model/bing/new_bing_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index aaddaa9..e72d083 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -56,7 +56,7 @@ class BingModel(Model): except Exception as e: bot.pop_last_conversation() log.exception(answer) - return f"AI生成内容被微软内容过滤器拦截,已删除最后一次提问的记忆,请尝试使用其他文字描述问题,若AI依然无法正常回复,请使用{clear_memory_commands[0]}命令清楚全部记忆" + return f"AI生成内容被微软内容过滤器拦截,已删除最后一次提问的记忆,请尝试使用其他文字描述问题,若AI依然无法正常回复,请使用{clear_memory_commands[0]}命令清除全部记忆" # 最新一条回复 try: reply = answer["item"]["messages"][-1]