LibreChat/api/app/clients/bingai.js
Danny Avila bb75b6df3b feat(bingai.js): add context and systemMessage parameters to askBing function
feat(conversationPreset.js): add context and systemMessage fields to conversation preset schema
feat(askBingAI.js): pass context and systemMessage parameters to ask function
feat(Settings.jsx): add toneStyle prop to BingAISettings component
feat(BingAIOptions/index.jsx): add useEffect to check if advanced mode is needed
feat(cleanupPreset.js): add context and systemMessage fields to cleaned up preset object
feat(getDefaultConversation.js): add context and systemMessage fields to default conversation object
feat(handleSubmit.js): add context and systemMessage fields to message object
2023-04-04 12:53:41 -04:00

84 lines
2.5 KiB
JavaScript

require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const askBing = async ({
text,
parentMessageId,
conversationId,
jailbreak,
jailbreakConversationId,
context,
systemMessage,
conversationSignature,
clientId,
invocationId,
toneStyle,
onProgress
}) => {
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
const store = {
store: new KeyvFile({ filename: './data/cache.json' })
};
const bingAIClient = 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,
proxy: process.env.PROXY || null
});
let options = {
jailbreakConversationId: jailbreakConversationId || jailbreak,
context,
systemMessage,
parentMessageId,
conversationId: jailbreakConversationId ? jailbreakConversationId : conversationId,
toneStyle,
onProgress
};
if (conversationSignature) options.conversationSignature = conversationSignature;
if (conversationSignature) options.clientId = clientId;
if (conversationSignature) options.invocationId = invocationId;
if (conversationSignature) options.toneStyle = toneStyle;
if (options?.jailbreakConversationId == 'false') {
options.jailbreakConversationId = false;
}
console.log('bing options', options);
const res = await bingAIClient.sendMessage(text, options);
return res;
// Example response for reference
// {
// conversationSignature: 'wwZ2GC/qRgEqP3VSNIhbPGwtno5RcuBhzZFASOM+Sxg=',
// conversationId: '51D|BingProd|026D3A4017554DE6C446798144B6337F4D47D5B76E62A31F31D0B1D0A95ED868',
// clientId: '914800201536527',
// invocationId: 1,
// conversationExpiryTime: '2023-02-15T21:48:46.2892088Z',
// response: 'Hello, this is Bing. Nice to meet you. 😊',
// details: {
// text: 'Hello, this is Bing. Nice to meet you. 😊',
// author: 'bot',
// createdAt: '2023-02-15T15:48:43.0631898+00:00',
// timestamp: '2023-02-15T15:48:43.0631898+00:00',
// messageId: '9d0c9a80-91b1-49ab-b9b1-b457dc3fe247',
// requestId: '5b252ef8-4f09-4c08-b6f5-4499d2e12fba',
// offense: 'None',
// adaptiveCards: [ [Object] ],
// sourceAttributions: [],
// feedback: { tag: null, updatedOn: null, type: 'None' },
// contentOrigin: 'DeepLeo',
// privacy: null,
// suggestedResponses: [ [Object], [Object], [Object] ]
// }
// }
};
module.exports = { askBing };