Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor: Support disable clientFetch by default #3133

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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,
arvinxx marked this conversation as resolved.
Show resolved Hide resolved
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
Loading