Skip to content

Commit

Permalink
feat: add bing footnotes (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Apr 17, 2023
1 parent 7070132 commit b92121b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/background/apis/bing-web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export async function generateAnswersWithBingWebApi(
jailbreakConversationId: sydneyMode,
onProgress: (token) => {
answer += token
// remove reference markers [^number^]
answer = answer.replaceAll(/\[\^\d+\^\]/g, '')
// reference markers [^number^]
answer = answer.replaceAll(/\[\^(\d+)\^\]/g, '<sup>$1</sup>')
port.postMessage({ answer: answer, done: false, session: null })
},
...(session.bingWeb_conversationId
Expand All @@ -52,6 +52,15 @@ export async function generateAnswersWithBingWebApi(
session.bingWeb_clientId = response.clientId
session.bingWeb_invocationId = response.invocationId

if (response.details.sourceAttributions.length > 0) {
const footnotes =
'\n\\-\n' +
response.details.sourceAttributions
.map((attr, index) => `\\[${index + 1}]: [${attr.providerDisplayName}](${attr.seeMoreUrl})`)
.join('\n')
answer += footnotes
}

pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.onMessage.removeListener(messageListener)
Expand Down

0 comments on commit b92121b

Please sign in to comment.