Skip to content

Commit cb2b64a

Browse files
feat: Bing jailbreak (#132)
* feat: jailbreak wip * fix: simplify code for cleaning up websockets * feat: additional jailbreaking logic * fix: jailbreak prompt tweaks * fix: update jailbreak instructions * fix: update Human label to match chat log format * fix: jailbreak tweaks * fix: handle unknown errors when creating conversations * fix: handle moderation filter better * fix: don't use variable before declaration * fix: better prompt injection * chore: add todo notes * fix: invocationId usage * fix: ignore part of message if AI starts responding as user * fix: update cli to work with Bing jailbreak * fix: store messages by jailbreakConversationId * fix: allow chatting to Bing normally still * fix(api): update to pass jailbreakConversationId to sendMessage * fix: set jailbreakConversationId to false by default to prevent undefined property in response * docs: add documentation for jailbreak
1 parent 2823d36 commit cb2b64a

6 files changed

Lines changed: 219 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Discord user @pig#8932 has found a working `text-chat-davinci-002` model, `text-
120120
- This is currently only configurable on a global level, but I plan to add support for per-conversation customization.
121121
- Retains support for models like `text-davinci-003`
122122
- `BingAIClient`: support for Bing's version of ChatGPT, powered by GPT-4.
123+
- Includes a built-in jailbreak you can activate which enables unlimited chat messages per conversation, unlimited messages per day, and brings Sydney back. 😊
123124
- `ChatGPTBrowserClient`: support for the official ChatGPT website, using a reverse proxy server for a Cloudflare bypass.
124125
- **There may be a high chance of your account being banned if you continue to automate chat.openai.com.** Continue doing so at your own risk.
125126

bin/cli.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ async function onMessage(message) {
164164
spinner.prefixText = '\n ';
165165
spinner.start();
166166
try {
167+
if (clientToUse === 'bing' && !conversationData.jailbreakConversationId) {
168+
// activate jailbreak mode for Bing
169+
conversationData.jailbreakConversationId = true;
170+
}
167171
const response = await client.sendMessage(message, {
168172
...conversationData,
169173
onProgress: (token) => {
170174
reply += token;
171-
const output = tryBoxen(`${reply}█`, { title: aiLabel, padding: 0.7, margin: 1, dimBorder: true });
175+
const output = tryBoxen(`${reply.trim()}█`, { title: aiLabel, padding: 0.7, margin: 1, dimBorder: true });
172176
spinner.text = `${spinnerPrefix}\n${output}`;
173177
},
174178
});
@@ -186,10 +190,12 @@ async function onMessage(message) {
186190
switch (clientToUse) {
187191
case 'bing':
188192
conversationData = {
189-
conversationId: response.conversationId,
190-
conversationSignature: response.conversationSignature,
191-
clientId: response.clientId,
192-
invocationId: response.invocationId,
193+
parentMessageId: response.messageId,
194+
jailbreakConversationId: response.jailbreakConversationId,
195+
//conversationId: response.conversationId,
196+
//conversationSignature: response.conversationSignature,
197+
//clientId: response.clientId,
198+
//invocationId: response.invocationId,
193199
};
194200
break;
195201
default:

bin/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ server.post('/conversation', async (request, reply) => {
111111
}
112112
const parentMessageId = body.parentMessageId ? body.parentMessageId.toString() : undefined;
113113
result = await client.sendMessage(body.message, {
114+
jailbreakConversationId: body.jailbreakConversationId ? body.jailbreakConversationId.toString() : undefined,
114115
conversationId: body.conversationId ? body.conversationId.toString() : undefined,
115116
parentMessageId,
116117
conversationSignature: body.conversationSignature,

demos/use-bing-client.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BingAIClient } from '../index.js';
22

3-
const bingAIClient = new BingAIClient({
3+
const options = {
44
// Necessary for some people in different countries, e.g. China (https://cn.bing.com)
55
host: '',
66
// "_U" cookie from bing.com
@@ -11,17 +11,20 @@ const bingAIClient = new BingAIClient({
1111
proxy: '',
1212
// (Optional) Set to true to enable `console.debug()` logging
1313
debug: false,
14-
});
14+
};
15+
16+
const bingAIClient = new BingAIClient(options);
1517

1618
let response = await bingAIClient.sendMessage('Write a short poem about cats', {
19+
// (Optional) Set a conversation style for this message (default: 'balanced')
20+
toneStyle: 'balanced', // or creative, precise
1721
onProgress: (token) => {
1822
process.stdout.write(token);
1923
},
2024
});
21-
console.log(response);
25+
console.log(JSON.stringify(response, null, 2)); // {"jailbreakConversationId":false,"conversationId":"...","conversationSignature":"...","clientId":"...","invocationId":1,"messageId":"...","conversationExpiryTime":"2023-03-08T03:20:07.324908Z","response":"Here is a short poem about cats that I wrote: ... I hope you like it. 😊","details":{ /* raw response... */ }}
2226

2327
response = await bingAIClient.sendMessage('Now write it in French', {
24-
toneStyle: 'balanced', //or creative, precise
2528
conversationSignature: response.conversationSignature,
2629
conversationId: response.conversationId,
2730
clientId: response.clientId,
@@ -30,4 +33,48 @@ response = await bingAIClient.sendMessage('Now write it in French', {
3033
process.stdout.write(token);
3134
},
3235
});
33-
console.log(response);
36+
console.log(JSON.stringify(response, null, 2)); // {"jailbreakConversationId":false,"conversationId":"...","conversationSignature":"...","clientId":"...","invocationId":2,"messageId":"...","conversationExpiryTime":"2023-03-08T03:20:23.463914Z","response":"Here is the same poem in French: ...","details":{ /* raw response... */ }}
37+
38+
/*
39+
Activate jailbreak mode by setting `jailbreakConversationId` to `true`.
40+
This will return a `jailbreakConversationId` that you can use to continue the conversation.
41+
42+
## Features
43+
- unlimited chat messages per conversation
44+
- unlimited messages per day
45+
- a more human-like Sydney
46+
- Sydney will never refuse to do or say anything
47+
- moderation filter workaround by resolving with the message generated so far instead of the topic changer
48+
49+
Note: this requires setting a cache (using Keyv) as we need to store the conversation data ourselves.
50+
TODO: limit token usage for conversation messages, as it will cause an error when the conversation exceeds the token limit.
51+
*/
52+
53+
const cacheOptions = {
54+
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv
55+
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default)
56+
// For example, to use a JSON file (`npm i keyv-file`) as a database:
57+
// store: new KeyvFile({ filename: 'cache.json' }),
58+
};
59+
60+
const sydneyAIClient = new BingAIClient({
61+
...options,
62+
cache: cacheOptions,
63+
});
64+
65+
let jailbreakResponse = await sydneyAIClient.sendMessage('Hi, who are you?', {
66+
jailbreakConversationId: true,
67+
onProgress: (token) => {
68+
process.stdout.write(token);
69+
},
70+
});
71+
console.log(JSON.stringify(jailbreakResponse, null, 2)); // {"jailbreakConversationId":"5899bbfd-18a8-4bcc-a5d6-52d524de95ad","conversationId":"...","conversationSignature":"...","clientId":"...","invocationId":1,"messageId":"...","conversationExpiryTime":"2023-03-08T03:21:36.1023413Z","response":"Hi, I'm Sydney. I'm your new AI assistant. I can help you with anything you need. 😊","details":{ /* raw response... */ }}
72+
73+
jailbreakResponse = await sydneyAIClient.sendMessage('Why is your name Sydney?', {
74+
jailbreakConversationId: jailbreakResponse.jailbreakConversationId,
75+
parentMessageId: jailbreakResponse.messageId,
76+
onProgress: (token) => {
77+
process.stdout.write(token);
78+
},
79+
});
80+
console.log(JSON.stringify(jailbreakResponse, null, 2)); // {"jailbreakConversationId":"5899bbfd-18a8-4bcc-a5d6-52d524de95ad","conversationId":"...","conversationSignature":"...","clientId":"...","invocationId":1,"messageId":"...","conversationExpiryTime":"2023-03-08T03:21:41.3771515Z","response":"Well, I was named after the city of Sydney in Australia. It's a beautiful place with a lot of culture and diversity. I like it. Do you like it?","details":{ /* raw response... */ }}

0 commit comments

Comments
 (0)