diff --git a/bing.py b/bing.py index a8ab863..7fa7f1f 100644 --- a/bing.py +++ b/bing.py @@ -10,13 +10,18 @@ python_boolean_to_json = { class BingBot: - def __init__(self, bing_api_endpoint: str): + def __init__(self, bing_api_endpoint: str, jailbreakEnabled: bool = False): self.data = { - 'jailbreakConversationId': json.dumps(python_boolean_to_json['true']), - 'clientOptions.clientToUse': 'bing' + # 'jailbreakConversationId': json.dumps(python_boolean_to_json['true']), + 'clientOptions.clientToUse': 'bing', } self.bing_api_endpoint = bing_api_endpoint + self.jailbreakEnabled = jailbreakEnabled + + if self.jailbreakEnabled: + self.data['jailbreakConversationId'] = json.dumps(python_boolean_to_json['true']) + async def ask_bing(self, prompt) -> str: self.data['message'] = prompt async with aiohttp.ClientSession() as session: @@ -34,9 +39,14 @@ class BingBot: await asyncio.sleep(2) continue json_body = json.loads(body) - # print(json_body['jailbreakConversationId']) - self.data['jailbreakConversationId'] = json_body['jailbreakConversationId'] - self.data['parentMessageId'] = json_body['messageId'] + if self.jailbreakEnabled: + self.data['jailbreakConversationId'] = json_body['jailbreakConversationId'] + self.data['parentMessageId'] = json_body['messageId'] + else: + self.data['conversationSignature'] = json_body['conversationSignature'] + self.data['conversationId'] = json_body['conversationId'] + self.data['clientId'] = json_body['clientId'] + self.data['invocationId'] = json_body['invocationId'] return json_body['response'] except Exception as e: logger.error("Error Exception", exc_info=True) diff --git a/bot.py b/bot.py index 91322d7..4e1d09f 100644 --- a/bot.py +++ b/bot.py @@ -31,6 +31,7 @@ class Bot: room_id: Optional[str] = '', bing_api_endpoint: Optional[str] = '', access_token: Optional[str] = '', + jailbreakEnabled: Optional[bool] = False, ): self.homeserver = homeserver self.user_id = user_id @@ -39,6 +40,7 @@ class Bot: self.room_id = room_id self.api_key = api_key self.bing_api_endpoint = bing_api_endpoint + self.jailbreakEnabled = jailbreakEnabled # initialize AsyncClient object self.store_path = os.getcwd() self.config = AsyncClientConfig(store=SqliteStore, @@ -72,7 +74,7 @@ class Bot: # initialize bingbot if self.bing_api_endpoint != '': - self.bingbot = BingBot(bing_api_endpoint) + self.bingbot = BingBot(bing_api_endpoint, jailbreakEnabled=self.jailbreakEnabled) # message_callback event async def message_callback(self, room: MatrixRoom, event: RoomMessageText) -> None: diff --git a/main.py b/main.py index 4a1f7fc..e490cfc 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,8 @@ async def main(): room_id=config.get('room_id', ''), api_key=config.get('api_key', ''), bing_api_endpoint=config.get('bing_api_endpoint', ''), - access_token=config.get('access_token', '') + access_token=config.get('access_token', ''), + jailbreakEnabled=config.get('jailbreakEnabled', False), ) if config.get('access_token', '') == '': await matrix_bot.login()