feat(chatgpt-browser): add support for multiple GPT models

This commit adds support for multiple GPT models in the chatGPT-browser
client. The available models are now stored in a Map object, which maps
the model label to its corresponding model.

The commit adds a new component, ChatGPTOptions, to the client
UI to allow the user to select the GPT model to use in the chat. The
component is only displayed when the chatGPT-browser endpoint is
selected.
This commit is contained in:
Daniel Avila 2023-04-02 14:34:12 -04:00
parent eef2303c8e
commit aa4fd57459
9 changed files with 69 additions and 13 deletions

View file

@ -1,11 +1,11 @@
require('dotenv').config();
const { KeyvFile } = require('keyv-file');
// const set = new Set([
// 'gpt-4',
// 'text-davinci-002-render',
// 'text-davinci-002-render-paid',
// 'text-davinci-002-render-sha'
// ]);
const modelMap = new Map([
['Default (GPT-3.5)', 'text-davinci-002-render-sha'],
['Legacy (GPT-3.5)', 'text-davinci-002-render-paid'],
['GPT-4', 'gpt-4']
]);
const browserClient = async ({
text,
@ -25,7 +25,7 @@ const browserClient = async ({
reverseProxyUrl: 'https://bypass.duti.tech/api/conversation',
// Access token from https://chat.openai.com/api/auth/session
accessToken: process.env.CHATGPT_TOKEN,
model,
model: modelMap.get(model),
// debug: true
proxy: process.env.PROXY || null
};
@ -37,7 +37,7 @@ const browserClient = async ({
options = { ...options, parentMessageId, conversationId };
}
// console.log('gptBrowser options', options, clientOptions);
console.log('gptBrowser clientOptions', clientOptions);
if (parentMessageId === '00000000-0000-0000-0000-000000000000') {
delete options.conversationId;

View file

@ -67,7 +67,9 @@ const projectPath = path.join(__dirname, '..', '..', 'client');
? { availableModels: ['gpt-4', 'text-davinci-003', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301'] }
: false;
const bingAI = !!process.env.BING_TOKEN;
const chatGPTBrowser = !!process.env.CHATGPT_TOKEN;
const chatGPTBrowser = process.env.OPENAI_KEY
? { availableModels: ['Default (GPT-3.5)', 'Legacy (GPT-3.5)', 'GPT-4'] }
: false;
res.send(JSON.stringify({ azureOpenAI, openAI, bingAI, chatGPTBrowser }));
});
@ -86,7 +88,7 @@ const projectPath = path.join(__dirname, '..', '..', 'client');
})();
let messageCount = 0;
process.on('uncaughtException', err => {
process.on('uncaughtException', (err) => {
if (!err.message.includes('fetch failed')) {
console.error('There was an uncaught error:', err.message);
}

View file

@ -50,6 +50,7 @@ router.post('/', async (req, res) => {
});
}
// eslint-disable-next-line no-use-before-define
return await ask({
userMessage,
endpointOption,

View file

@ -56,6 +56,7 @@ router.post('/', async (req, res) => {
});
}
// eslint-disable-next-line no-use-before-define
return await ask({
userMessage,
endpointOption,