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

feat(Bing): add gpts/persona support #8

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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