mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-15 12:15:37 +08:00
WIP, custom API Modes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import BingAIClient from '../clients/bing/index.mjs'
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { pushRecord, setAbortController } from './shared.mjs'
|
||||
import { isCustomModelName, modelNameToCustomPart } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
/**
|
||||
* @param {Runtime.Port} port
|
||||
@@ -19,7 +20,7 @@ export async function generateAnswersWithBingWebApi(
|
||||
const { controller, messageListener, disconnectListener } = setAbortController(port)
|
||||
const config = await getUserConfig()
|
||||
let modelMode
|
||||
if (session.modelName.includes('-')) modelMode = session.modelName.split('-')[1]
|
||||
if (isCustomModelName(session.modelName)) modelMode = modelNameToCustomPart(session.modelName)
|
||||
else modelMode = config.modelMode
|
||||
|
||||
console.debug('mode', modelMode)
|
||||
|
||||
@@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import { t } from 'i18next'
|
||||
import { sha3_512 } from 'js-sha3'
|
||||
import randomInt from 'random-int'
|
||||
import { modelNameToValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
async function request(token, method, path, data) {
|
||||
const apiUrl = (await getUserConfig()).customChatGptWebApiUrl
|
||||
@@ -233,7 +234,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
|
||||
isNeedWebsocket(accessToken).catch(() => undefined),
|
||||
])
|
||||
console.debug('models', models)
|
||||
const selectedModel = Models[session.modelName].value
|
||||
const selectedModel = modelNameToValue(session.modelName)
|
||||
const usedModel =
|
||||
models && models.includes(selectedModel) ? selectedModel : Models[chatgptWebModelKeys[0]].value
|
||||
console.debug('usedModel', usedModel)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { getUserConfig, Models } from '../../config/index.mjs'
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { pushRecord, setAbortController } from './shared.mjs'
|
||||
import { fetchSSE } from '../../utils/fetch-sse.mjs'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
|
||||
import { modelNameToValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
/**
|
||||
* @param {Runtime.Port} port
|
||||
@@ -31,7 +32,7 @@ export async function generateAnswersWithClaudeApi(port, question, session) {
|
||||
'x-api-key': config.claudeApiKey,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: Models[modelName].value,
|
||||
model: modelNameToValue(modelName),
|
||||
messages: prompt,
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { pushRecord, setAbortController } from './shared.mjs'
|
||||
import Claude from '../clients/claude'
|
||||
import { Models } from '../../config/index.mjs'
|
||||
import { modelNameToValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
/**
|
||||
* @param {Runtime.Port} port
|
||||
@@ -35,7 +35,7 @@ export async function generateAnswersWithClaudeWebApi(
|
||||
const params = {
|
||||
progress: progressFunc,
|
||||
done: doneFunc,
|
||||
model: Models[modelName].value,
|
||||
model: modelNameToValue(modelName),
|
||||
signal: controller.signal,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { pushRecord, setAbortController } from './shared.mjs'
|
||||
import { Models, setUserConfig } from '../../config/index.mjs'
|
||||
import { setUserConfig } from '../../config/index.mjs'
|
||||
import { fetchSSE } from '../../utils/fetch-sse'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { modelNameToValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
export class MoonshotWeb {
|
||||
/**
|
||||
@@ -596,7 +597,7 @@ export async function generateAnswersWithMoonshotWebApi(
|
||||
const params = {
|
||||
progress: progressFunc,
|
||||
done: doneFunc,
|
||||
model: Models[modelName].value,
|
||||
model: modelNameToValue(modelName),
|
||||
signal: controller.signal,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// api version
|
||||
|
||||
import { Models, getUserConfig } from '../../config/index.mjs'
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { fetchSSE } from '../../utils/fetch-sse.mjs'
|
||||
import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
pushRecord,
|
||||
setAbortController,
|
||||
} from './shared.mjs'
|
||||
import { modelNameToValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
/**
|
||||
* @param {Browser.Runtime.Port} port
|
||||
@@ -54,7 +55,7 @@ export async function generateAnswersWithGptCompletionApi(
|
||||
},
|
||||
body: JSON.stringify({
|
||||
prompt: prompt,
|
||||
model: Models[modelName].value,
|
||||
model: modelNameToValue(modelName),
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
@@ -154,7 +155,7 @@ export async function generateAnswersWithChatgptApiCompat(
|
||||
},
|
||||
body: JSON.stringify({
|
||||
messages: prompt,
|
||||
model: Models[modelName].value,
|
||||
model: modelNameToValue(modelName),
|
||||
stream: true,
|
||||
max_tokens: config.maxResponseTokenLength,
|
||||
temperature: config.temperature,
|
||||
|
||||
Reference in New Issue
Block a user