Skip to content

Commit

Permalink
fix: fix model editing now working properly (close #288)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Jul 22, 2023
1 parent 0495b9a commit 3c94011
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions web/src/pages/Channel/EditChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const EditChannel = () => {
};
const [batch, setBatch] = useState(false);
const [inputs, setInputs] = useState(originInputs);
const [originModelOptions, setOriginModelOptions] = useState([]);
const [modelOptions, setModelOptions] = useState([]);
const [groupOptions, setGroupOptions] = useState([]);
const [basicModels, setBasicModels] = useState([]);
Expand All @@ -44,19 +45,6 @@ const EditChannel = () => {
data.models = [];
} else {
data.models = data.models.split(',');
setTimeout(() => {
let localModelOptions = [...modelOptions];
data.models.forEach((model) => {
if (!localModelOptions.find((option) => option.key === model)) {
localModelOptions.push({
key: model,
text: model,
value: model
});
}
});
setModelOptions(localModelOptions);
}, 1000);
}
if (data.group === '') {
data.groups = [];
Expand All @@ -76,13 +64,16 @@ const EditChannel = () => {
const fetchModels = async () => {
try {
let res = await API.get(`/api/channel/models`);
setModelOptions(res.data.data.map((model) => ({
let localModelOptions = res.data.data.map((model) => ({
key: model.id,
text: model.id,
value: model.id
})));
}));
setOriginModelOptions(localModelOptions);
setFullModels(res.data.data.map((model) => model.id));
setBasicModels(res.data.data.filter((model) => !model.id.startsWith('gpt-4')).map((model) => model.id));
setBasicModels(res.data.data.filter((model) => {
return model.id.startsWith('gpt-3') || model.id.startsWith('text-');
}).map((model) => model.id));
} catch (error) {
showError(error.message);
}
Expand All @@ -101,6 +92,20 @@ const EditChannel = () => {
}
};

useEffect(() => {
let localModelOptions = [...originModelOptions];
inputs.models.forEach((model) => {
if (!localModelOptions.find((option) => option.key === model)) {
localModelOptions.push({
key: model,
text: model,
value: model
});
}
});
setModelOptions(localModelOptions);
}, [originModelOptions, inputs.models]);

useEffect(() => {
if (isEdit) {
loadChannel().then();
Expand Down Expand Up @@ -280,15 +285,20 @@ const EditChannel = () => {
<Input
action={
<Button type={'button'} onClick={()=>{
if (customModel.trim() === "") return;
if (inputs.models.includes(customModel)) return;
let localModels = [...inputs.models];
localModels.push(customModel);
let localModelOptions = [...modelOptions];
let localModelOptions = [];
localModelOptions.push({
key: customModel,
text: customModel,
value: customModel,
});
setModelOptions(localModelOptions);
setModelOptions(modelOptions=>{
return [...modelOptions, ...localModelOptions];
});
setCustomModel('');
handleInputChange(null, { name: 'models', value: localModels });
}}>填入</Button>
}
Expand Down

0 comments on commit 3c94011

Please sign in to comment.