From 807e7cc0721c3021cebb0cc02b2d6d6cc4d74af1 Mon Sep 17 00:00:00 2001 From: Richard-Weiss <76665424+Richard-Weiss@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:28:25 +0100 Subject: [PATCH] feat(Bing): add gpts/persona support --- bin/server.js | 2 ++ src/BingAIClient.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/bin/server.js b/bin/server.js index 80979107..cd1dbdd0 100755 --- a/bin/server.js +++ b/bin/server.js @@ -120,6 +120,7 @@ server.post('/conversation', async (request, reply) => { useBase64, useUserSuffixMessage, plugins, + persona, } = body; const messageOptions = { conversationId: body.conversationId ? body.conversationId.toString() : undefined, @@ -140,6 +141,7 @@ server.post('/conversation', async (request, reply) => { ...(clientToUseForMessage === 'bing' && { useBase64 }), ...(clientToUseForMessage === 'bing' && { useUserSuffixMessage }), ...(clientToUseForMessage === 'bing' && { plugins }), + ...(clientToUseForMessage === 'bing' && { persona }), onProgress, abortController, }; diff --git a/src/BingAIClient.js b/src/BingAIClient.js index 006f9dc4..e30116b6 100644 --- a/src/BingAIClient.js +++ b/src/BingAIClient.js @@ -343,6 +343,7 @@ export default class BingAIClient { invocationId = 0, toneStyle, modelVersion, + persona, context = jailbreakConversationId ? process.env.CONTEXT : null, parentMessageId = jailbreakConversationId === true ? crypto.randomUUID() : null, abortController = new AbortController(), @@ -455,6 +456,7 @@ export default class BingAIClient { useBase64: opts.useBase64, useUserSuffixMessage: opts.useUserSuffixMessage, noSearch, + persona, }; const ws = await this.createWebSocketConnection(conversationSignature); @@ -567,6 +569,7 @@ export default class BingAIClient { useBase64, useUserSuffixMessage, noSearch, + persona, } = webSocketParameters; let toneOption; if (toneStyle === 'creative') { @@ -584,6 +587,7 @@ export default class BingAIClient { const imageBaseURL = 'https://www.bing.com/images/blob?bcid='; const pluginIds = plugins.map(plugin => ({ id: plugin.id })); const pluginHex = plugins.map(plugin => plugin.hex).filter(Boolean); + const personaString = this.#resolvePersona(persona); let userMessageSuffix; if (useUserSuffixMessage === true) { @@ -620,6 +624,7 @@ export default class BingAIClient { 'eredirecturl', 'clgalileo', 'gencontentv3', + ...(personaString !== '' ? [personaString] : []), ...(modelVersionString !== '' ? [modelVersionString] : []), ...(noSearch !== undefined ? [noSearch] : []), ...pluginHex, @@ -702,6 +707,33 @@ export default class BingAIClient { return optionSetString; } + /** + * This method converts persona names from simple names to technical names. + * @param {String | undefined} persona Simple name of the persona to use. + * @returns {String} Technical name of the persona to use. + */ + static #resolvePersona(persona) { + let personaString = ''; + switch (persona) { + case 'designer': + personaString = 'ai_persona_designer_gpt'; + break; + case 'vacation_planner': + personaString = 'flux_vacation_planning_helper_v14'; + break; + case 'cooking_assistant': + personaString = 'flux_cooking_helper_v14'; + break; + case 'fitness_trainer': + personaString = 'flux_fitness_helper_v14'; + break; + default: + personaString = ''; + } + + return personaString; + } + /** * Used for creating the reply from the AI. * @param {WebSocket} ws The websocket the listener for the "message" even should be declared for.