feat: sydney is functional

This commit is contained in:
Daniel Avila 2023-03-08 19:47:23 -05:00
parent 0f54251459
commit 69b3edc52c
15 changed files with 157 additions and 22 deletions

34
api/app/sydney.js Normal file
View file

@ -0,0 +1,34 @@
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: new KeyvFile({ filename: './data/cache.json' })
});
let options = {
jailbreakConversationId: true,
onProgress: async (partialRes) => await progressCallback(partialRes),
};
if (convo) {
options = { ...options, ...convo };
}
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 };