Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
feat(Bing): add gpts/persona support (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard-Weiss authored Jan 18, 2024
1 parent 981b69d commit 6ed889f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ server.post('/conversation', async (request, reply) => {
useBase64,
useUserSuffixMessage,
plugins,
persona,
} = body;
const messageOptions = {
conversationId: body.conversationId ? body.conversationId.toString() : undefined,
Expand All @@ -140,6 +141,7 @@ server.post('/conversation', async (request, reply) => {
...(clientToUseForMessage === 'bing' && { useBase64 }),
...(clientToUseForMessage === 'bing' && { useUserSuffixMessage }),
...(clientToUseForMessage === 'bing' && { plugins }),
...(clientToUseForMessage === 'bing' && { persona }),
onProgress,
abortController,
};
Expand Down
32 changes: 32 additions & 0 deletions src/BingAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -455,6 +456,7 @@ export default class BingAIClient {
useBase64: opts.useBase64,
useUserSuffixMessage: opts.useUserSuffixMessage,
noSearch,
persona,
};

const ws = await this.createWebSocketConnection(conversationSignature);
Expand Down Expand Up @@ -567,6 +569,7 @@ export default class BingAIClient {
useBase64,
useUserSuffixMessage,
noSearch,
persona,
} = webSocketParameters;
let toneOption;
if (toneStyle === 'creative') {
Expand All @@ -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) {
Expand Down Expand Up @@ -620,6 +624,7 @@ export default class BingAIClient {
'eredirecturl',
'clgalileo',
'gencontentv3',
...(personaString !== '' ? [personaString] : []),
...(modelVersionString !== '' ? [modelVersionString] : []),
...(noSearch !== undefined ? [noSearch] : []),
...pluginHex,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6ed889f

Please sign in to comment.