Skip to content

Commit b92121b

Browse files
committed
feat: add bing footnotes (#225)
1 parent 7070132 commit b92121b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/background/apis/bing-web.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export async function generateAnswersWithBingWebApi(
2929
jailbreakConversationId: sydneyMode,
3030
onProgress: (token) => {
3131
answer += token
32-
// remove reference markers [^number^]
33-
answer = answer.replaceAll(/\[\^\d+\^\]/g, '')
32+
// reference markers [^number^]
33+
answer = answer.replaceAll(/\[\^(\d+)\^\]/g, '<sup>$1</sup>')
3434
port.postMessage({ answer: answer, done: false, session: null })
3535
},
3636
...(session.bingWeb_conversationId
@@ -52,6 +52,15 @@ export async function generateAnswersWithBingWebApi(
5252
session.bingWeb_clientId = response.clientId
5353
session.bingWeb_invocationId = response.invocationId
5454

55+
if (response.details.sourceAttributions.length > 0) {
56+
const footnotes =
57+
'\n\\-\n' +
58+
response.details.sourceAttributions
59+
.map((attr, index) => `\\[${index + 1}]: [${attr.providerDisplayName}](${attr.seeMoreUrl})`)
60+
.join('\n')
61+
answer += footnotes
62+
}
63+
5564
pushRecord(session, question, answer)
5665
console.debug('conversation history', { content: session.conversationRecords })
5766
port.onMessage.removeListener(messageListener)

0 commit comments

Comments
 (0)