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:
commit
fc781cece3
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user