-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from danny-avila/updateAI
feat: add sydney (jailbroken bing) and more bing styling with citations
- Loading branch information
Showing
28 changed files
with
377 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const citationRegex = /\[\^\d+?\^]/g; | ||
|
||
const citeText = (res, noLinks = false) => { | ||
let result = res.text || res; | ||
const citations = Array.from(new Set(result.match(citationRegex))); | ||
if (citations?.length === 0) return result; | ||
|
||
if (noLinks) { | ||
citations.forEach((citation) => { | ||
const digit = citation.match(/\d+?/g)[0]; | ||
result = result.replaceAll(citation, `<sup>[${digit}](#) </sup>`); | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
let sources = res.details.sourceAttributions; | ||
if (sources?.length === 0) return result; | ||
sources = sources.map((source) => source.seeMoreUrl); | ||
|
||
citations.forEach((citation) => { | ||
const digit = citation.match(/\d+?/g)[0]; | ||
result = result.replaceAll(citation, `<sup>[${digit}](${sources[digit - 1]}) </sup>`); | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
module.exports = citeText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// const regex = / \[\d+\..*?\]\(.*?\)/g; | ||
const regex = / \[.*?]\(.*?\)/g; | ||
|
||
const getCitations = (res) => { | ||
const textBlocks = res.details.adaptiveCards[0].body; | ||
if (!textBlocks) return ''; | ||
let links = textBlocks[textBlocks.length - 1]?.text.match(regex); | ||
if (links?.length === 0 || !links) return ''; | ||
links = links.map((link) => link.trim()); | ||
return links.join('\n'); | ||
}; | ||
|
||
module.exports = getCitations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require('dotenv').config(); | ||
const { KeyvFile } = require('keyv-file'); | ||
|
||
const askSydney = async ({ text, progressCallback, convo }) => { | ||
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api')); | ||
|
||
const sydneyClient = new BingAIClient({ | ||
// "_U" cookie from bing.com | ||
userToken: process.env.BING_TOKEN, | ||
// If the above doesn't work, provide all your cookies as a string instead | ||
// cookies: '', | ||
debug: false, | ||
cache: { store: new KeyvFile({ filename: './data/cache.json' }) } | ||
}); | ||
|
||
let options = { | ||
jailbreakConversationId: true, | ||
onProgress: async (partialRes) => await progressCallback(partialRes), | ||
}; | ||
|
||
if (convo.parentMessageId) { | ||
options = { ...options, jailbreakConversationId: convo.jailbreakConversationId, parentMessageId: convo.parentMessageId }; | ||
} | ||
|
||
console.log('sydney options', options); | ||
|
||
const res = await sydneyClient.sendMessage(text, options | ||
); | ||
|
||
return res; | ||
|
||
// for reference: | ||
// https://github.com/waylaidwanderer/node-chatgpt-api/blob/main/demos/use-bing-client.js | ||
}; | ||
|
||
module.exports = { askSydney }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.