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), label: getModelShowName(item.name),
})); }));
setModels(modelArray); setModels(modelArray);
if (modelArray.length > 0) {
setCurrent(modelArray[0].value); setCurrent(modelArray[0].value);
}
}, [router.currentRoute]); }, [router.currentRoute]);
useEffect(() => { useEffect(() => {
const cloneConfig = cloneDeep(config.config); const cloneConfig = cloneDeep(config.config);

View File

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