Skip to content

Commit

Permalink
fix(bing): try to fix everything caused by "current user message in d…
Browse files Browse the repository at this point in the history
…ocument context" (waylaidwanderer#264)

* fix(bing): use another method to bypass moderation of the current message

* fix(bing): fix summarize new document
  • Loading branch information
InterestingDarkness authored Apr 2, 2023
1 parent 3c9614c commit d4cc1f9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/BingAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ import HttpsProxyAgent from 'https-proxy-agent';
*/
const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');

const insertRandomSeparator = (str) => {
// Split the string into an array of individual characters
const chars = str.split('');
// Use the map function to join each character together and randomly insert a separator or not
return chars.map((char, index) => {
// If not the first character, randomly decide whether to insert a separator based on a random number
if (index !== 0 && Math.random() >= 0.5) {
// Generate a random number and use a "-" as the separator if it is greater than or equal to 0.5, otherwise use "_"
const separator = Math.random() >= 0.5 ? '-' : '_';
return separator + char;
}
return char;
}).join('');
};

export default class BingAIClient {
constructor(options) {
const cacheOptions = options.cache || {};
Expand Down Expand Up @@ -315,7 +330,7 @@ export default class BingAIClient {
isStartOfSession: invocationId === 0,
message: {
author: 'user',
text: jailbreakConversationId ? 'Continue the conversation' : message,
text: jailbreakConversationId ? insertRandomSeparator(message) : message,
messageType: jailbreakConversationId ? 'SearchQuery' : 'Chat',
},
conversationSignature,
Expand Down

0 comments on commit d4cc1f9

Please sign in to comment.