Merge pull request #39 from devchat-ai/fix_config_show_error_while_net_errors

Improve error handling during configuration loading
This commit is contained in:
boob.yang 2024-05-08 18:36:17 +08:00 committed by GitHub
commit fc781cece3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -119,7 +119,9 @@ const Config = observer(() => {
label: getModelShowName(item.name),
}));
setModels(modelArray);
setCurrent(modelArray[0].value);
if (modelArray.length > 0) {
setCurrent(modelArray[0].value);
}
}, [router.currentRoute]);
useEffect(() => {
const cloneConfig = cloneDeep(config.config);

View File

@ -12,17 +12,16 @@ const defaultAPIBase = [
export const fetchLLMs = async ({modelsUrl,devchatApiKey}) => {
return new Promise<{data:any}>((resolve, reject) => {
try {
// 添加 header: "Authorization: Bearer ${devchatApiKey}"
axios.get(`${modelsUrl}/models`, { headers: { 'Authorization': `Bearer ${devchatApiKey}` }}).then((res) => {
// 获取 models 模版列表
if (res?.data?.data && Array.isArray(res?.data?.data)) {
resolve(res.data);
}
}).catch((e) => {
console.error("fetchLLMs error:", e);
reject(e);
});
} catch (e) {
reject(e);
}
}
);
};
@ -180,8 +179,12 @@ export const ConfigStore = types
this.updateSettle(true);
},
refreshModelList: flow(function* (){
const { data } = yield fetchLLMs({modelsUrl:self.modelsUrl,devchatApiKey:self.devchatApiKey});
setTemplate(data,self.provider);
try {
const { data } = yield fetchLLMs({modelsUrl:self.modelsUrl,devchatApiKey:self.devchatApiKey});
setTemplate(data,self.provider);
} catch (e) {
console.log("fetchLLMs error:", e);
}
}),
writeConfig: function () {
const writeConfig = cloneDeep(self.config);