fix: error handling titles, remove openAI req

This commit is contained in:
Daniel Avila 2023-03-10 07:43:43 -05:00
parent 12cf3405e4
commit 4e616cd2ed
4 changed files with 59 additions and 37 deletions

View file

@ -2,27 +2,32 @@ require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const askBing = async ({ text, progressCallback, convo }) => {
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api'));
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
const bingAIClient = new BingAIClient({
// "_U" cookie from bing.com
const clientOptions = {
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' }) }
});
};
const cookies = process.env.BING_COOKIES;
if (cookies?.length > 0) {
clientOptions.cookies = cookies;
delete clientOptions.userToken;
}
const bingAIClient = new BingAIClient(clientOptions);
let options = {
onProgress: async (partialRes) => await progressCallback(partialRes),
onProgress: async (partialRes) => await progressCallback(partialRes)
};
if (convo) {
options = { ...options, ...convo };
}
const res = await bingAIClient.sendMessage(text, options
);
const res = await bingAIClient.sendMessage(text, options);
return res;