From f71b1f99cd292743d93ab3b4baf29cd232d46e65 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sun, 19 Mar 2023 17:06:29 +0800 Subject: [PATCH] feat: support gpt-4 (#22) --- src/background/apis/chatgpt-web.mjs | 9 +++++++-- src/config.mjs | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/background/apis/chatgpt-web.mjs b/src/background/apis/chatgpt-web.mjs index ffaee9a..178cf01 100644 --- a/src/background/apis/chatgpt-web.mjs +++ b/src/background/apis/chatgpt-web.mjs @@ -38,7 +38,7 @@ export async function sendModerations(token, question, conversationId, messageId export async function getModels(token) { const response = JSON.parse((await request(token, 'GET', '/models')).responseText) - return response.models + if (response.models) return response.models.map((m) => m.slug) } /** @@ -71,7 +71,12 @@ export async function generateAnswersWithChatgptWebApi(port, question, session, const models = await getModels(accessToken).catch(() => { port.onMessage.removeListener(stopListener) }) + console.debug('models', models) const config = await getUserConfig() + const selectedModel = Models[config.modelName].value + const usedModel = + models && models.includes(selectedModel) ? selectedModel : Models[chatgptWebModelKeys[0]].value + console.debug('usedModel', usedModel) let answer = '' await fetchSSE(`${config.customChatGptWebApiUrl}${config.customChatGptWebApiPath}`, { @@ -94,7 +99,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session, }, }, ], - model: models ? models[0].slug : Models[chatgptWebModelKeys[0]].value, + model: usedModel, parent_message_id: session.parentMessageId, }), onMessage(message) { diff --git a/src/config.mjs b/src/config.mjs index 5833644..6f995bf 100644 --- a/src/config.mjs +++ b/src/config.mjs @@ -14,13 +14,16 @@ import { languages } from 'countries-list' */ export const Models = { chatgptFree: { value: 'text-davinci-002-render-sha', desc: 'ChatGPT (Web)' }, - chatgptApi: { value: 'gpt-3.5-turbo', desc: 'ChatGPT (GPT-3.5)' }, - gptDavinci: { value: 'text-davinci-003', desc: 'GPT3' }, + chatgptPlus: { value: 'gpt-4', desc: 'ChatGPT (Web, GPT-4)' }, + chatgptApi35: { value: 'gpt-3.5-turbo', desc: 'ChatGPT (GPT-3.5-turbo)' }, + chatgptApi4_8k: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k)' }, + chatgptApi4_32k: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k)' }, + gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' }, } -export const chatgptWebModelKeys = ['chatgptFree'] +export const chatgptWebModelKeys = ['chatgptFree', 'chatgptPlus'] export const gptApiModelKeys = ['gptDavinci'] -export const chatgptApiModelKeys = ['chatgptApi'] +export const chatgptApiModelKeys = ['chatgptApi35', 'chatgptApi4_8k', 'chatgptApi4_32k'] export const TriggerMode = { always: 'Always',