Skip to content

Commit

Permalink
fix(bingAI): markdown and error formatting for final stream response (d…
Browse files Browse the repository at this point in the history
…anny-avila#829)

* fix(bingAI): markdown formatting for final stream response due to new strict payload validation on the frontend

* fix: add missing prop to bing Error response
  • Loading branch information
danny-avila authored Aug 23, 2023
1 parent 7dc27b1 commit d38e463
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions api/server/routes/ask/bingAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const ask = async ({
let { text, parentMessageId: userParentMessageId, messageId: userMessageId } = userMessage;

let responseMessageId = crypto.randomUUID();
const model = endpointOption?.jailbreak ? 'Sydney' : 'BingAI';

if (preSendRequest) {
sendMessage(res, { message: userMessage, created: true });
Expand All @@ -115,13 +116,15 @@ const ask = async ({
lastSavedTimestamp = currentTimestamp;
saveMessage({
messageId: responseMessageId,
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
sender: model,
conversationId,
parentMessageId: overrideParentMessageId || userMessageId,
model,
text: text,
unfinished: true,
cancelled: false,
error: false,
isCreatedByUser: false,
});
}
},
Expand Down Expand Up @@ -178,14 +181,16 @@ const ask = async ({
messageId: responseMessageId,
newMessageId: newResponseMessageId,
parentMessageId: overrideParentMessageId || newUserMessageId,
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
sender: model,
text: await handleText(response, true),
model,
suggestions:
response.details.suggestedResponses &&
response.details.suggestedResponses.map((s) => s.text),
unfinished,
cancelled: false,
error: false,
isCreatedByUser: false,
};

await saveMessage(responseMessage);
Expand Down Expand Up @@ -246,14 +251,15 @@ const ask = async ({
if (partialText?.length > 2) {
const responseMessage = {
messageId: responseMessageId,
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
sender: model,
conversationId,
parentMessageId: overrideParentMessageId || userMessageId,
text: partialText,
model: endpointOption.modelOptions.model,
model,
unfinished: true,
cancelled: false,
error: false,
isCreatedByUser: false,
};

saveMessage(responseMessage);
Expand All @@ -269,13 +275,15 @@ const ask = async ({
console.log(error);
const errorMessage = {
messageId: responseMessageId,
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
sender: model,
conversationId,
parentMessageId: overrideParentMessageId || userMessageId,
unfinished: false,
cancelled: false,
error: true,
text: error.message,
model,
isCreatedByUser: false,
};
await saveMessage(errorMessage);
handleError(res, errorMessage);
Expand Down
1 change: 0 additions & 1 deletion client/src/components/Messages/Content/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const EditMessage = ({

const resubmitMessage = () => {
const text = textEditor?.current?.innerText ?? '';
console.log('siblingIdx:', siblingIdx);
if (message.isCreatedByUser) {
ask({
text,
Expand Down

0 comments on commit d38e463

Please sign in to comment.