Skip to content

Commit

Permalink
♻️ refactor: Support disable clientFetch by modelConfig (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
cy948 committed Jul 9, 2024
1 parent ffbb399 commit fb3876c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const filterEnabledModels = (provider: ModelProviderCard) => {
return provider.chatModels.filter((v) => v.enabled).map((m) => m.id);
};

export const isProviderDisableBroswerRequest = (id: string) => {
const provider = DEFAULT_MODEL_PROVIDER_LIST.find((v) => v.id === id && v.disableBrowserRequest);
return !!provider;
};

export { default as AnthropicProviderCard } from './anthropic';
export { default as AzureProviderCard } from './azure';
export { default as BaichuanProviderCard } from './baichuan';
Expand Down
8 changes: 6 additions & 2 deletions src/config/modelProviders/qwen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const Qwen: ModelProviderCard = {
tokens: 32_000,
},
{
description: '通义千问千亿级别超大规模语言模型,支持中文、英文等不同语言输入,当前通义千问2.5产品版本背后的API模型',
description:
'通义千问千亿级别超大规模语言模型,支持中文、英文等不同语言输入,当前通义千问2.5产品版本背后的API模型',
displayName: 'Qwen Max',
enabled: true,
id: 'qwen-max',
tokens: 8000,
},
{
description: '通义千问千亿级别超大规模语言模型,支持中文、英文等不同语言输入,扩展了上下文窗口',
description:
'通义千问千亿级别超大规模语言模型,支持中文、英文等不同语言输入,扩展了上下文窗口',
displayName: 'Qwen Max LongContext',
id: 'qwen-max-longcontext',
tokens: 30_000,
Expand All @@ -50,6 +52,8 @@ const Qwen: ModelProviderCard = {
},
],
checkModel: 'qwen-turbo',
defaultShowBrowserRequest: false,
disableBrowserRequest: true,
id: 'qwen',
modelList: { showModelFetcher: true },
name: 'Qwen',
Expand Down
8 changes: 8 additions & 0 deletions src/store/user/slices/modelList/selectors/modelConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ describe('modelConfigSelectors', () => {
} as UserSettingsState) as unknown as UserStore;
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(true);
});

// Qwen provider not work in broswer request. Please skip this case if it work in future.
// Issue: https://github.com/lobehub/lobe-chat/issues/3108
// PR: https://github.com/lobehub/lobe-chat/pull/3133
it('client fecth should be disabled if provider is disable broswer request', () => {
const s = merge(initialSettingsState, {}) as unknown as UserStore;
expect(modelConfigSelectors.isAutoFetchModelsEnabled('qwen')(s)).toBe(false);
});
});

describe('getCustomModelCardById', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/store/user/slices/modelList/selectors/modelConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isProviderDisableBroswerRequest } from '@/config/modelProviders';
import { UserStore } from '@/store/user';
import { GlobalLLMProviderKey } from '@/types/user/settings';

Expand All @@ -21,6 +22,8 @@ const isProviderFetchOnClient = (provider: GlobalLLMProviderKey | string) => (s:
// If the provider in the whitelist, follow the user settings
if (providerWhitelist.has(provider) && typeof config?.fetchOnClient !== 'undefined')
return config?.fetchOnClient;
// If the provider already disable broswer request in model config, force on Server.
if (isProviderDisableBroswerRequest(provider)) return false;

// 1. If no baseUrl and apikey input, force on Server.
const isProviderEndpointNotEmpty =
Expand Down

0 comments on commit fb3876c

Please sign in to comment.