Add option to disable Bing ai jailbreak mode
This commit is contained in:
parent
09596c1990
commit
599d186ba7
3 changed files with 21 additions and 8 deletions
22
bing.py
22
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)
|
||||
|
|
4
bot.py
4
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:
|
||||
|
|
3
main.py
3
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()
|
||||
|
|
Loading…
Reference in a new issue