feat: support gpt-4 (#22)

This commit is contained in:
josc146
2023-03-19 17:06:29 +08:00
parent 2f849fe8ec
commit f71b1f99cd
2 changed files with 14 additions and 6 deletions
+7 -2
View File
@@ -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) {
+7 -4
View File
@@ -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',