Skip to content

Commit

Permalink
♻️ refactor: Support disable clientFetch by default (lobehub#3133)
Browse files Browse the repository at this point in the history
* ♻️ refactor: Support disable clientFetch by modelConfig (lobehub#3108)

* ✅ test: - clientfetch for qwen

* ♻️ refactor: Remove `defaultShowBrowserRequest` in qwen modelConfig
  • Loading branch information
cy948 authored and jasonhp committed Jul 12, 2024
1 parent 9f69455 commit cac970e
Show file tree
Hide file tree
Showing 4 changed files with 33 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 @@ -73,6 +73,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
7 changes: 5 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,7 @@ const Qwen: ModelProviderCard = {
},
],
checkModel: 'qwen-turbo',
disableBrowserRequest: true,
id: 'qwen',
modelList: { showModelFetcher: true },
name: 'Qwen',
Expand Down
19 changes: 19 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,25 @@ 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, {
settings: {
languageModel: {
qwen: { fetchOnClient: true },
},
keyVaults: {
qwen: {
apiKey: 'apikey',
},
},
},
} as UserSettingsState) as unknown as UserStore;
expect(modelConfigSelectors.isAutoFetchModelsEnabled('qwen')(s)).toBe(false);
});
});

describe('getCustomModelCardById', () => {
Expand Down
4 changes: 4 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 @@ -18,6 +19,9 @@ const providerWhitelist = new Set(['ollama']);
const isProviderFetchOnClient = (provider: GlobalLLMProviderKey | string) => (s: UserStore) => {
const config = getProviderConfigById(provider)(s);

// If the provider already disable broswer request in model config, force on Server.
if (isProviderDisableBroswerRequest(provider)) return false;

// If the provider in the whitelist, follow the user settings
if (providerWhitelist.has(provider) && typeof config?.fetchOnClient !== 'undefined')
return config?.fetchOnClient;
Expand Down

0 comments on commit cac970e

Please sign in to comment.