Skip to content

Commit

Permalink
fix(bing): keeping repeating introduction due to empty message string…
Browse files Browse the repository at this point in the history
… + use a more native method to pass web page context (waylaidwanderer#350)

* fix

fix waylaidwanderer#289

* fix "fast" mode web page context, more “native” to original Bing

* some small adjustments

* We still need this to avoid repeating introduction in some cases
  • Loading branch information
InterestingDarkness authored May 16, 2023
1 parent 0e06421 commit 0bd6cde
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/BingAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,13 @@ export default class BingAIClient {
author: 'system',
},
...previousCachedMessages,
// We still need this to avoid repeating introduction in some cases
{
text: message,
author: 'user',
},
] : undefined;

if (context) {
previousMessages.push({
text: context,
author: 'context', // not a real/valid author, we're just piggybacking on the existing logic
});
}

// prepare messages for prompt injection
previousMessagesFormatted = previousMessages?.map((previousMessage) => {
switch (previousMessage.author) {
Expand All @@ -257,13 +251,15 @@ export default class BingAIClient {
case 'bot':
return `[assistant](#message)\n${previousMessage.text}`;
case 'system':
return `N/A\n\n[system](#additional_instructions)\n- ${previousMessage.text}`;
case 'context':
return `[user](#context)\n${previousMessage.text}`;
return `[system](#additional_instructions)\n${previousMessage.text}`;
default:
throw new Error(`Unknown message author: ${previousMessage.author}`);
}
}).join('\n\n');

if (context) {
previousMessagesFormatted = `${context}\n\n${previousMessagesFormatted}`;
}
}

const userMessage = {
Expand Down Expand Up @@ -312,6 +308,7 @@ export default class BingAIClient {
'cricinfo',
'cricinfov2',
'dv3sugg',
'nojbfedge',
],
sliceIds: [
'222dtappid',
Expand All @@ -322,7 +319,7 @@ export default class BingAIClient {
isStartOfSession: invocationId === 0,
message: {
author: 'user',
text: jailbreakConversationId ? '' : message,
text: message,
messageType: jailbreakConversationId ? 'SearchQuery' : 'Chat',
},
conversationSignature,
Expand Down

0 comments on commit 0bd6cde

Please sign in to comment.