mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-16 11:18:17 +08:00
feat: better custom model support
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// and it has not yet had a negative impact on maintenance.
|
||||
// If necessary, I will refactor.
|
||||
|
||||
import { getUserConfig, maxResponseTokenLength, Models } from '../../config/index.mjs'
|
||||
import { getUserConfig, maxResponseTokenLength } from '../../config/index.mjs'
|
||||
import { fetchSSE } from '../../utils/fetch-sse'
|
||||
import { getConversationPairs } from '../../utils/get-conversation-pairs'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
@@ -52,7 +52,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
|
||||
},
|
||||
body: JSON.stringify({
|
||||
messages: prompt,
|
||||
model: Models[modelName].value,
|
||||
model: modelName,
|
||||
stream: true,
|
||||
max_tokens: maxResponseTokenLength,
|
||||
}),
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
defaultConfig,
|
||||
getUserConfig,
|
||||
gptApiModelKeys,
|
||||
isUsingCustomModel,
|
||||
Models,
|
||||
} from '../config/index.mjs'
|
||||
import { isSafari } from '../utils/is-safari'
|
||||
@@ -60,7 +61,10 @@ Browser.runtime.onConnect.addListener((port) => {
|
||||
if (!session) return
|
||||
const config = await getUserConfig()
|
||||
if (!session.modelName) session.modelName = config.modelName
|
||||
if (!session.aiName) session.aiName = Models[session.modelName].desc
|
||||
if (!session.aiName)
|
||||
session.aiName =
|
||||
Models[session.modelName].desc +
|
||||
(isUsingCustomModel(config) ? ` (${config.customModelName})` : '')
|
||||
port.postMessage({ session })
|
||||
|
||||
try {
|
||||
@@ -101,8 +105,8 @@ Browser.runtime.onConnect.addListener((port) => {
|
||||
port,
|
||||
session.question,
|
||||
session,
|
||||
config.apiKey,
|
||||
session.modelName,
|
||||
'',
|
||||
config.customModelName,
|
||||
)
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -18,14 +18,14 @@ export const Models = {
|
||||
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' },
|
||||
chatglm6bInt4: { value: 'chatglm-6b-int4', desc: 'ChatGLM-6B-Int4' },
|
||||
customModel: { value: '', desc: 'Custom Model' },
|
||||
}
|
||||
|
||||
export const chatgptWebModelKeys = ['chatgptFree35', 'chatgptPlus4']
|
||||
export const bingWebModelKeys = ['bingFree4']
|
||||
export const gptApiModelKeys = ['gptApiDavinci']
|
||||
export const chatgptApiModelKeys = ['chatgptApi35', 'chatgptApi4_8k', 'chatgptApi4_32k']
|
||||
export const customApiModelKeys = ['chatglm6bInt4']
|
||||
export const customApiModelKeys = ['customModel']
|
||||
|
||||
export const TriggerMode = {
|
||||
always: 'Always',
|
||||
@@ -66,13 +66,14 @@ export const defaultConfig = {
|
||||
preferredLanguage: navigator.language.substring(0, 2),
|
||||
insertAtTop: isMobile(),
|
||||
lockWhenAnswer: false,
|
||||
customModelApiUrl: 'http://localhost:8000/chat/completions',
|
||||
customModelName: 'chatglm-6b-int4',
|
||||
|
||||
// advanced
|
||||
|
||||
customChatGptWebApiUrl: 'https://chat.openai.com',
|
||||
customChatGptWebApiPath: '/backend-api/conversation',
|
||||
customOpenAiApiUrl: 'https://api.openai.com',
|
||||
customModelApiUrl: 'http://localhost:8000/chat/completions',
|
||||
siteRegex: 'match nothing',
|
||||
userSiteRegexOnly: false,
|
||||
inputQuery: '',
|
||||
|
||||
+16
-1
@@ -81,7 +81,9 @@ function GeneralPart({ config, updateConfig }) {
|
||||
<span style="display: flex; gap: 15px;">
|
||||
<select
|
||||
style={
|
||||
isUsingApiKey(config) || isUsingMultiModeModel(config) ? 'width: 50%;' : undefined
|
||||
isUsingApiKey(config) || isUsingMultiModeModel(config) || isUsingCustomModel(config)
|
||||
? 'width: 50%;'
|
||||
: undefined
|
||||
}
|
||||
required
|
||||
onChange={(e) => {
|
||||
@@ -146,6 +148,19 @@ function GeneralPart({ config, updateConfig }) {
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{isUsingCustomModel(config) && (
|
||||
<span style="width: 50%; display: flex; gap: 5px;">
|
||||
<input
|
||||
type="text"
|
||||
value={config.customModelName}
|
||||
placeholder="Model Name"
|
||||
onChange={(e) => {
|
||||
const customModelName = e.target.value
|
||||
updateConfig({ customModelName: customModelName })
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{isUsingCustomModel(config) && (
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user