From bb75b6df3b6ccf33763f46e3104e0029fc472eb3 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 4 Apr 2023 12:53:41 -0400 Subject: [PATCH] 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 --- api/app/clients/bingai.js | 6 +++++- api/models/schema/conversationPreset.js | 8 ++++++++ api/server/routes/askBingAI.js | 3 +++ .../src/components/Endpoints/BingAI/Settings.jsx | 6 +++--- client/src/components/Endpoints/Settings.jsx | 1 + .../src/components/Input/BingAIOptions/index.jsx | 16 +++++++++++----- client/src/utils/cleanupPreset.js | 2 ++ client/src/utils/getDefaultConversation.js | 2 ++ client/src/utils/handleSubmit.js | 2 ++ 9 files changed, 37 insertions(+), 9 deletions(-) diff --git a/api/app/clients/bingai.js b/api/app/clients/bingai.js index 0865a10b8d..5dbc377b63 100644 --- a/api/app/clients/bingai.js +++ b/api/app/clients/bingai.js @@ -7,6 +7,8 @@ const askBing = async ({ conversationId, jailbreak, jailbreakConversationId, + context, + systemMessage, conversationSignature, clientId, invocationId, @@ -30,8 +32,10 @@ const askBing = async ({ let options = { jailbreakConversationId: jailbreakConversationId || jailbreak, + context, + systemMessage, parentMessageId, - conversationId, + conversationId: jailbreakConversationId ? jailbreakConversationId : conversationId, toneStyle, onProgress }; diff --git a/api/models/schema/conversationPreset.js b/api/models/schema/conversationPreset.js index aead0ab796..219c5c5045 100644 --- a/api/models/schema/conversationPreset.js +++ b/api/models/schema/conversationPreset.js @@ -55,6 +55,14 @@ module.exports = { type: String, default: null }, + context: { + type: String, + default: null + }, + systemMessage: { + type: String, + default: null + }, clientId: { type: String, default: null diff --git a/api/server/routes/askBingAI.js b/api/server/routes/askBingAI.js index eb6e18e328..50dd517433 100644 --- a/api/server/routes/askBingAI.js +++ b/api/server/routes/askBingAI.js @@ -35,6 +35,8 @@ router.post('/', async (req, res) => { const endpointOption = { jailbreak: req.body?.jailbreak || false, jailbreakConversationId: req.body?.jailbreakConversationId || null, + systemMessage: req.body?.systemMessage || null, + context: req.body?.context || null, conversationSignature: req.body?.conversationSignature || null, clientId: req.body?.clientId || null, invocationId: req.body?.invocationId || null, @@ -58,6 +60,7 @@ router.post('/', async (req, res) => { }); } + // eslint-disable-next-line no-use-before-define return await ask({ isNewConversation, userMessage, diff --git a/client/src/components/Endpoints/BingAI/Settings.jsx b/client/src/components/Endpoints/BingAI/Settings.jsx index 2017e63fd3..730169ea80 100644 --- a/client/src/components/Endpoints/BingAI/Settings.jsx +++ b/client/src/components/Endpoints/BingAI/Settings.jsx @@ -77,7 +77,7 @@ function Settings(props) { disabled={readonly} value={context || ''} onChange={e => setContext(e.target.value || null)} - placeholder="Bing can use up to 7k tokens for 'context', text that it can reference per 1 conversation. The specific limit is not known but may run into errors exceeding 7k tokens" + placeholder="Bing can use up to 7k tokens for 'context', which it can reference for the conversation. The specific limit is not known but may run into errors exceeding 7k tokens" className={cn( defaultTextProps, 'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2' @@ -126,10 +126,10 @@ function Settings(props) { disabled={readonly} value={systemMessage || ''} onChange={e => setSystemMessage(e.target.value || null)} - placeholder="WARNING: Misuse of this feature can get you BANNED from using Bing! Click on 'System Message' for full instructions and the default message if omitted, which is the 'Sydney' preset that is considered safe." + placeholder="WARNING: Misuse of this feature can get you BANNED from using Bing! Click on 'System Message' for full instructions and the default message if omitted, which is the 'Sydney' preset that is considered safe. Leave blank for the default message." className={cn( defaultTextProps, - 'flex max-h-[300px] min-h-[148px] w-full resize-none px-3 py-2 ' + 'flex max-h-[300px] min-h-[148px] w-full resize-none px-3 py-2 placeholder:text-red-400' )} /> diff --git a/client/src/components/Endpoints/Settings.jsx b/client/src/components/Endpoints/Settings.jsx index be224f5112..109d5d56c3 100644 --- a/client/src/components/Endpoints/Settings.jsx +++ b/client/src/components/Endpoints/Settings.jsx @@ -24,6 +24,7 @@ const Settings = ({ preset, ...props }) => { else if (endpoint === 'bingAI') return ( { + if (endpoint !== 'bingAI') return; + + const mustInAdvancedMode = context !== null || systemMessage !== null; + + if (mustInAdvancedMode && !advancedMode) setAdvancedMode(true); + }, [conversation, advancedMode]); if (endpoint !== 'bingAI') return null; if (conversationId !== 'new') return null; @@ -49,8 +57,6 @@ function BingAIOptions() { })); }; - const { toneStyle } = conversation; - const cardStyle = 'transition-colors shadow-md rounded-md min-w-[75px] font-normal bg-white border-black/10 hover:border-black/10 focus:border-black/10 dark:border-black/10 dark:hover:border-black/10 dark:focus:border-black/10 border dark:bg-gray-700 text-black dark:text-white'; const defaultClasses = @@ -114,7 +120,7 @@ function BingAIOptions() { +
{ endpoint, presetId: _preset?.presetId || null, jailbreak: _preset?.jailbreak || false, + context: _preset?.context || null, + systemMessage: _preset?.systemMessage || null, jailbreakpresetId: _preset?._jailbreakpresetId || null, presetSignature: null, clientId: null, diff --git a/client/src/utils/getDefaultConversation.js b/client/src/utils/getDefaultConversation.js index c8141e02d7..bb6fdea767 100644 --- a/client/src/utils/getDefaultConversation.js +++ b/client/src/utils/getDefaultConversation.js @@ -16,6 +16,8 @@ const buildDefaultConversation = ({ conversation, endpoint, lastConversationSetu ...conversation, endpoint, jailbreak: lastConversationSetup?.jailbreak || false, + systemMessage: lastConversationSetup?.systemMessage || null, + context: lastConversationSetup?.context || null, jailbreakConversationId: lastConversationSetup?.jailbreakConversationId || null, conversationSignature: null, clientId: null, diff --git a/client/src/utils/handleSubmit.js b/client/src/utils/handleSubmit.js index 01a9b72495..a3f7b739f1 100644 --- a/client/src/utils/handleSubmit.js +++ b/client/src/utils/handleSubmit.js @@ -42,6 +42,8 @@ const useMessageHandler = () => { jailbreak: currentConversation?.jailbreak || false, jailbreakConversationId: currentConversation?.jailbreakConversationId || null, conversationSignature: currentConversation?.conversationSignature || null, + systemMessage: currentConversation?.systemMessage || null, + context: currentConversation?.context || null, clientId: currentConversation?.clientId || null, invocationId: currentConversation?.invocationId || 1, toneStyle: currentConversation?.toneStyle || 'fast'