Skip to content

Commit

Permalink
根据reviewAI的建议进行了代码的规范
Browse files Browse the repository at this point in the history
  • Loading branch information
code-october committed Jun 4, 2024
1 parent 5f84cc8 commit d2dd9af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,8 @@ export function Settings() {
text={Locale.Settings.Access.OpenAI.AvailableModels.Action}
onClick={async () => {
if (await showConfirm(Locale.Settings.Access.OpenAI.AvailableModels.Confirm)) {
const availableModelsStr = await accessStore.fetchAvailableModels(accessStore.openaiUrl, accessStore.openaiApiKey);
config.update((config) => (config.customModels = availableModelsStr));
const availableModelIds = await accessStore.fetchAvailableModels(accessStore.openaiUrl, accessStore.openaiApiKey);
config.update((config) => (config.customModels = availableModelIds));
}
}}
type="primary"
Expand Down
40 changes: 15 additions & 25 deletions app/store/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,32 @@ export const useAccessStore = createPersistStore(
fetchState = 2;
});
},
fetchAvailableModels(url: string, apiKey: string): Promise<string>{
// if (fetchState > 0 || getClientConfig()?.buildMode === "export")
// return Promise.resolve(DEFAULT_ACCESS_STATE.customModels);
fetchAvailableModels(url: string, apiKey: string): Promise<string> {
if (fetchState > 0) return Promise.resolve(DEFAULT_ACCESS_STATE.customModels);

fetchState = 1;
return fetch(url+"/v1/models", {
method: "get",
body: null,
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`,
},
})
.then((res) => res.json())
.then((res) => {
// 如果res里的data数组长度大于0,则说明有可用的模型,提取其中的id属性,使用英文逗号进行字符串连接
if (res.data && res.data.length > 0){
const excludedKeywords = ['text-', 'moderation', 'embedding', 'dall-e-', 'davinci', 'babbage', 'midjourney', 'whisper', 'tts'];
const availableModels = res.data
.filter((model: any) => !excludedKeywords.some(keyword => model.id.toLowerCase().includes(keyword.toLowerCase())))
.map((model: any) => model.id)
.join(',');
console.log("availableModels",availableModels);
return `-all,${availableModels}`;
}
else{
return DEFAULT_ACCESS_STATE.customModels;
}
.then(res => res.json())
.then(res => {
const models = res.data || [];
const excludedKeywords = ['text-', 'moderation', 'embedding', 'dall-e-', 'davinci', 'babbage', 'midjourney', 'whisper', 'tts'];
const availableModels = models
.filter(model => !excludedKeywords.some(keyword => model.id.toLowerCase().includes(keyword.toLowerCase())))
.map(model => model.id)
.join(',');
// console.log("availableModels", availableModels);
return `-all,${availableModels}`;
})
.catch((error) => {
.catch(error => {
console.error("[Access] failed to fetch available models: ", error);
return DEFAULT_ACCESS_STATE.customModels;
})
.finally(() => {
fetchState = 2;
});
.finally(() => fetchState = 2);
}
}),
{
Expand Down

0 comments on commit d2dd9af

Please sign in to comment.