mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-06-27 17:47:56 +08:00
WIP, custom API Modes
This commit is contained in:
@@ -25,7 +25,7 @@ const defaultApiMode = {
|
||||
itemName: 'chatgptFree35',
|
||||
isCustom: false,
|
||||
customName: '',
|
||||
customUrl: '',
|
||||
customUrl: 'http://localhost:8000/v1/chat/completions',
|
||||
apiKey: '',
|
||||
active: true,
|
||||
}
|
||||
@@ -99,8 +99,11 @@ export function ApiModes({ config, updateConfig }) {
|
||||
value={editingApiMode.groupName}
|
||||
onChange={(e) => {
|
||||
const groupName = e.target.value
|
||||
const itemName = ModelGroups[groupName].value[0]
|
||||
setEditingApiMode({ ...editingApiMode, groupName, itemName })
|
||||
let itemName = ModelGroups[groupName].value[0]
|
||||
const isCustom =
|
||||
editingApiMode.itemName === 'custom' && !AlwaysCustomGroups.includes(groupName)
|
||||
if (isCustom) itemName = 'custom'
|
||||
setEditingApiMode({ ...editingApiMode, groupName, itemName, isCustom })
|
||||
}}
|
||||
>
|
||||
{Object.entries(ModelGroups).map(([groupName, { desc }]) => (
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
isUsingChatGLMApiModel,
|
||||
isUsingClaudeApiModel,
|
||||
isUsingCustomModel,
|
||||
isUsingCustomNameOnlyModel,
|
||||
isUsingOllamaApiModel,
|
||||
isUsingGithubThirdPartyApiModel,
|
||||
isUsingMultiModeModel,
|
||||
@@ -175,10 +174,8 @@ export function GeneralPart({ config, updateConfig, setTabIndex }) {
|
||||
isUsingOpenAiApiModel(config) ||
|
||||
isUsingMultiModeModel(config) ||
|
||||
isUsingCustomModel(config) ||
|
||||
isUsingOllamaApiModel(config) ||
|
||||
isUsingAzureOpenAiApiModel(config) ||
|
||||
isUsingClaudeApiModel(config) ||
|
||||
isUsingCustomNameOnlyModel(config) ||
|
||||
isUsingMoonshotApiModel(config)
|
||||
? 'width: 50%;'
|
||||
: undefined
|
||||
@@ -270,30 +267,6 @@ export function GeneralPart({ config, updateConfig, setTabIndex }) {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{isUsingCustomNameOnlyModel(config) && (
|
||||
<input
|
||||
style="width: 50%;"
|
||||
type="text"
|
||||
value={config.poeCustomBotName}
|
||||
placeholder={t('Bot Name')}
|
||||
onChange={(e) => {
|
||||
const customName = e.target.value
|
||||
updateConfig({ poeCustomBotName: customName })
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{isUsingOllamaApiModel(config) && (
|
||||
<input
|
||||
style="width: 50%;"
|
||||
type="text"
|
||||
value={config.ollamaModelName}
|
||||
placeholder={t('Model Name')}
|
||||
onChange={(e) => {
|
||||
const ollamaModelName = e.target.value
|
||||
updateConfig({ ollamaModelName: ollamaModelName })
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{isUsingAzureOpenAiApiModel(config) && (
|
||||
<input
|
||||
type="password"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { generateAnswersWithChatgptApiCompat } from './openai-api.mjs'
|
||||
import { getModelValue } from '../../utils/model-name-convert.mjs'
|
||||
|
||||
/**
|
||||
* @param {Browser.Runtime.Port} port
|
||||
@@ -8,6 +9,7 @@ import { generateAnswersWithChatgptApiCompat } from './openai-api.mjs'
|
||||
*/
|
||||
export async function generateAnswersWithOllamaApi(port, question, session) {
|
||||
const config = await getUserConfig()
|
||||
const model = getModelValue(session)
|
||||
return generateAnswersWithChatgptApiCompat(
|
||||
config.ollamaEndpoint + '/v1',
|
||||
port,
|
||||
@@ -22,7 +24,7 @@ export async function generateAnswersWithOllamaApi(port, question, session) {
|
||||
Authorization: `Bearer ${config.ollamaApiKey}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: config.ollamaModelName,
|
||||
model,
|
||||
prompt: 't',
|
||||
options: {
|
||||
num_predict: 1,
|
||||
|
||||
@@ -160,6 +160,6 @@ export function isInApiModeGroup(apiModeGroup, configOrSession) {
|
||||
else foundGroup = getModelNameGroup(configOrSession.modelName)
|
||||
|
||||
if (!foundGroup) return false
|
||||
const [, groupValue] = foundGroup
|
||||
const [, { value: groupValue }] = foundGroup
|
||||
return groupValue === apiModeGroup
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user