mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-17 21:53:42 +08:00
⚡️ feat: channel support plugin settings (#89)
This commit is contained in:
@@ -22,7 +22,9 @@ import {
|
||||
Autocomplete,
|
||||
FormHelperText,
|
||||
Checkbox,
|
||||
Switch
|
||||
Switch,
|
||||
FormControlLabel,
|
||||
Typography
|
||||
} from '@mui/material';
|
||||
|
||||
import { Formik } from 'formik';
|
||||
@@ -32,6 +34,7 @@ import { createFilterOptions } from '@mui/material/Autocomplete';
|
||||
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
|
||||
import CheckBoxIcon from '@mui/icons-material/CheckBox';
|
||||
|
||||
const pluginList = require('../type/Plugin.json');
|
||||
const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
|
||||
const checkedIcon = <CheckBoxIcon fontSize="small" />;
|
||||
|
||||
@@ -91,7 +94,24 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => {
|
||||
|
||||
return typeConfig[typeValue]?.input;
|
||||
};
|
||||
|
||||
const handleTypeChange = (setFieldValue, typeValue, values) => {
|
||||
// 处理插件事务
|
||||
if (pluginList[typeValue]) {
|
||||
const newPluginValues = {};
|
||||
const pluginConfig = pluginList[typeValue];
|
||||
for (const pluginName in pluginConfig) {
|
||||
const plugin = pluginConfig[pluginName];
|
||||
const oldValve = values['plugin'] ? values['plugin'][pluginName] || {} : {};
|
||||
newPluginValues[pluginName] = {};
|
||||
for (const paramName in plugin.params) {
|
||||
const param = plugin.params[paramName];
|
||||
newPluginValues[pluginName][paramName] = oldValve[paramName] || (param.type === 'bool' ? false : '');
|
||||
}
|
||||
}
|
||||
setFieldValue('plugin', newPluginValues);
|
||||
}
|
||||
|
||||
const newInput = initChannel(typeValue);
|
||||
|
||||
if (newInput) {
|
||||
@@ -233,6 +253,9 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => {
|
||||
|
||||
data.base_url = data.base_url ?? '';
|
||||
data.is_edit = true;
|
||||
if (data.plugin === null) {
|
||||
data.plugin = {};
|
||||
}
|
||||
initChannel(data.type);
|
||||
setInitialInput(data);
|
||||
} else {
|
||||
@@ -597,6 +620,53 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => {
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
{pluginList[values.type] &&
|
||||
Object.keys(pluginList[values.type]).map((pluginId) => {
|
||||
const plugin = pluginList[values.type][pluginId];
|
||||
return (
|
||||
<>
|
||||
<Divider sx={{ ...theme.typography.otherInput }} />
|
||||
<Typography variant="h3">{plugin.name}</Typography>
|
||||
{Object.keys(plugin.params).map((paramId) => {
|
||||
const param = plugin.params[paramId];
|
||||
const name = `plugin.${pluginId}.${paramId}`;
|
||||
return param.type === 'bool' ? (
|
||||
<FormControl key={name} fullWidth sx={{ ...theme.typography.otherInput }}>
|
||||
<FormControlLabel
|
||||
key={name}
|
||||
required
|
||||
control={
|
||||
<Switch
|
||||
key={name}
|
||||
name={name}
|
||||
checked={values.plugin?.[pluginId]?.[paramId] || false}
|
||||
onChange={(event) => {
|
||||
setFieldValue(name, event.target.checked);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
label="是否启用"
|
||||
/>
|
||||
<FormHelperText id="helper-tex-channel-key-label"> {param.description} </FormHelperText>
|
||||
</FormControl>
|
||||
) : (
|
||||
<FormControl key={name} fullWidth sx={{ ...theme.typography.otherInput }}>
|
||||
<TextField
|
||||
multiline
|
||||
key={name}
|
||||
name={name}
|
||||
value={values.plugin?.[pluginId]?.[paramId] || ''}
|
||||
label={param.name}
|
||||
placeholder={param.description}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<FormHelperText id="helper-tex-channel-key-label"> {param.description} </FormHelperText>
|
||||
</FormControl>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
})}
|
||||
<DialogActions>
|
||||
<Button onClick={onCancel}>取消</Button>
|
||||
<Button disableElevation disabled={isSubmitting} type="submit" variant="contained" color="primary">
|
||||
|
||||
@@ -9,7 +9,8 @@ const defaultConfig = {
|
||||
test_model: '',
|
||||
model_mapping: '',
|
||||
models: [],
|
||||
groups: ['default']
|
||||
groups: ['default'],
|
||||
plugin: {}
|
||||
},
|
||||
inputLabel: {
|
||||
name: '渠道名称',
|
||||
@@ -59,7 +60,7 @@ const typeConfig = {
|
||||
},
|
||||
14: {
|
||||
input: {
|
||||
models: ['claude-instant-1.2', 'claude-2.0', 'claude-2.1','claude-3-opus-20240229','claude-3-sonnet-20240229'],
|
||||
models: ['claude-instant-1.2', 'claude-2.0', 'claude-2.1', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229'],
|
||||
test_model: 'claude-3-sonnet-20240229'
|
||||
},
|
||||
modelGroup: 'Anthropic'
|
||||
@@ -76,8 +77,8 @@ const typeConfig = {
|
||||
},
|
||||
16: {
|
||||
input: {
|
||||
models: ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'],
|
||||
test_model: 'chatglm_lite'
|
||||
models: ['glm-3-turbo', 'glm-4', 'glm-4v', 'embedding-2', 'cogview-3'],
|
||||
test_model: 'glm-3-turbo'
|
||||
},
|
||||
modelGroup: 'Zhipu'
|
||||
},
|
||||
@@ -86,17 +87,7 @@ const typeConfig = {
|
||||
other: '插件参数'
|
||||
},
|
||||
input: {
|
||||
models: [
|
||||
'qwen-turbo',
|
||||
'qwen-plus',
|
||||
'qwen-max',
|
||||
'qwen-max-longcontext',
|
||||
'text-embedding-v1',
|
||||
'qwen-turbo-internet',
|
||||
'qwen-plus-internet',
|
||||
'qwen-max-internet',
|
||||
'qwen-max-longcontext-internet'
|
||||
],
|
||||
models: ['qwen-turbo', 'qwen-plus', 'qwen-max', 'qwen-max-longcontext', 'text-embedding-v1'],
|
||||
test_model: 'qwen-turbo'
|
||||
},
|
||||
prompt: {
|
||||
@@ -174,19 +165,22 @@ const typeConfig = {
|
||||
},
|
||||
prompt: {
|
||||
key: '按照如下格式输入:APISecret|groupID'
|
||||
}
|
||||
},
|
||||
modelGroup: 'MiniMax'
|
||||
},
|
||||
28: {
|
||||
input: {
|
||||
models: ['deepseek-coder', 'deepseek-chat'],
|
||||
test_model: 'deepseek-chat'
|
||||
}
|
||||
},
|
||||
modelGroup: 'Deepseek'
|
||||
},
|
||||
29: {
|
||||
input: {
|
||||
models: ['moonshot-v1-8k', 'moonshot-v1-32k', 'moonshot-v1-128k'],
|
||||
test_model: 'moonshot-v1-8k'
|
||||
}
|
||||
},
|
||||
modelGroup: 'Moonshot'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
48
web/src/views/Channel/type/Plugin.json
Normal file
48
web/src/views/Channel/type/Plugin.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"16": {
|
||||
"retrieval": {
|
||||
"name": "知识库",
|
||||
"description": "请前往开放平台的知识库上传文档,然后使用知识库功能进行检索。",
|
||||
"params": {
|
||||
"knowledge_id": {
|
||||
"name": "知识库ID",
|
||||
"description": "当涉及到知识库ID时,请前往开放平台的知识库模块进行创建或获取(是知识库ID不是文档ID!)",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"prompt_template": {
|
||||
"name": "知识库模板",
|
||||
"description": "请求模型时的知识库模板, 请查看文档填写,否则不用填写",
|
||||
"type": "string",
|
||||
"required": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"web_search": {
|
||||
"name": "网页搜索",
|
||||
"description": "使用网页搜索功能,对用户输入的内容进行搜索",
|
||||
"params": {
|
||||
"enable": {
|
||||
"name": "启用",
|
||||
"description": "是否启用网页搜索",
|
||||
"type": "bool",
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"17": {
|
||||
"web_search": {
|
||||
"name": "网页搜索",
|
||||
"description": "使用网页搜索功能,对用户输入的内容进行搜索",
|
||||
"params": {
|
||||
"enable": {
|
||||
"name": "启用",
|
||||
"description": "是否启用网页搜索",
|
||||
"type": "bool",
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user