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

增加【清除获取的模型】的功能,主要是用于在获取模型列表后,不想要了,需要恢复系统自带的模型。 #4260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions locales/en-US/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"title": "Use Client-Side Fetching Mode"
},
"fetcher": {
"clear": "Clear The Obtained Models",
"fetch": "Get Model List",
"fetching": "Fetching Model List...",
"latestTime": "Last Updated: {{time}}",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-CN/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"title": "使用客户端请求模式"
},
"fetcher": {
"clear": "清除获取的模型",
"fetch": "获取模型列表",
"fetching": "正在获取模型列表...",
"latestTime": "上次更新时间:{{time}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icon, Tooltip } from '@lobehub/ui';
import { Typography } from 'antd';
import { createStyles } from 'antd-style';
import dayjs from 'dayjs';
import { LucideLoaderCircle, LucideRefreshCcwDot } from 'lucide-react';
import { CircleX, LucideLoaderCircle, LucideRefreshCcwDot } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';
Expand All @@ -16,6 +16,10 @@ import {
import { GlobalLLMProviderKey } from '@/types/user/settings';

const useStyles = createStyles(({ css, token }) => ({
buttons: css`
display: flex;
`,

hover: css`
cursor: pointer;

Expand All @@ -40,8 +44,9 @@ interface ModelFetcherProps {
const ModelFetcher = memo<ModelFetcherProps>(({ provider }) => {
const { styles } = useStyles();
const { t } = useTranslation('setting');
const [useFetchProviderModelList] = useUserStore((s) => [
const [useFetchProviderModelList, clearObtainedModels] = useUserStore((s) => [
s.useFetchProviderModelList,
s.clearObtainedModels,
s.setModelProviderConfig,
]);
const enabledAutoFetch = useUserStore(modelConfigSelectors.isAutoFetchModelsEnabled(provider));
Expand All @@ -52,37 +57,55 @@ const ModelFetcher = memo<ModelFetcherProps>(({ provider }) => {
(s) => modelProviderSelectors.getModelCardsById(provider)(s).length,
);

const remoteModels = useUserStore((s) =>
modelProviderSelectors.remoteProviderModelCards(provider)(s),
);

const { mutate, isValidating } = useFetchProviderModelList(provider, enabledAutoFetch);

return (
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
<Flexbox align={'center'} gap={0} horizontal justify={'space-between'}>
<div>{t('llm.modelList.total', { count: totalModels })}</div>
<Tooltip
overlayStyle={{ pointerEvents: 'none' }}
title={
latestFetchTime
? t('llm.fetcher.latestTime', {
time: dayjs(latestFetchTime).format('YYYY-MM-DD HH:mm:ss'),
})
: t('llm.fetcher.noLatestTime')
}
>
<Flexbox
align={'center'}
className={styles.hover}
gap={4}
horizontal
onClick={() => mutate()}
<div className={styles.buttons}>
<Tooltip
overlayStyle={{ pointerEvents: 'none' }}
title={
latestFetchTime
? t('llm.fetcher.latestTime', {
time: dayjs(latestFetchTime).format('YYYY-MM-DD HH:mm:ss'),
})
: t('llm.fetcher.noLatestTime')
}
>
<Icon
icon={isValidating ? LucideLoaderCircle : LucideRefreshCcwDot}
size={'small'}
spin={isValidating}
/>
<div>{isValidating ? t('llm.fetcher.fetching') : t('llm.fetcher.fetch')}</div>
</Flexbox>
</Tooltip>
<Flexbox
align={'center'}
className={styles.hover}
gap={4}
horizontal
onClick={() => mutate()}
>
<Icon
icon={isValidating ? LucideLoaderCircle : LucideRefreshCcwDot}
size={'small'}
spin={isValidating}
/>
<div>{isValidating ? t('llm.fetcher.fetching') : t('llm.fetcher.fetch')}</div>
</Flexbox>
</Tooltip>
{remoteModels && remoteModels.length > 0 && (
<Flexbox
align={'center'}
className={styles.hover}
gap={4}
horizontal
onClick={() => clearObtainedModels(provider)}
>
<Icon icon={CircleX} size={'small'} />
<div>{t('llm.fetcher.clear')}</div>
</Flexbox>
)}
</div>
</Flexbox>
</Typography.Text>
);
Expand Down
1 change: 1 addition & 0 deletions src/locales/default/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default {
title: '使用客户端请求模式',
},
fetcher: {
clear: '清除获取的模型',
fetch: '获取模型列表',
fetching: '正在获取模型列表...',
latestTime: '上次更新时间:{{time}}',
Expand Down
17 changes: 16 additions & 1 deletion src/store/user/slices/modelList/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { modelProviderSelectors } from './selectors/modelProvider';
* 设置操作
*/
export interface ModelListAction {
clearObtainedModels: (provider: GlobalLLMProviderKey) => Promise<void>;
dispatchCustomModelCards: (
provider: GlobalLLMProviderKey,
payload: CustomModelCardDispatch,
Expand Down Expand Up @@ -61,6 +62,13 @@ export const createModelListSlice: StateCreator<
[],
ModelListAction
> = (set, get) => ({
clearObtainedModels: async (provider: GlobalLLMProviderKey) => {
await get().setModelProviderConfig(provider, {
remoteModelCards: [],
});

get().refreshDefaultModelProviderList();
},
dispatchCustomModelCards: async (provider, payload) => {
const prevState = settingsSelectors.providerConfig(provider)(get());

Expand All @@ -85,7 +93,14 @@ export const createModelListSlice: StateCreator<
const serverChatModels = modelProviderSelectors.serverProviderModelCards(provider)(get());
const remoteChatModels = modelProviderSelectors.remoteProviderModelCards(provider)(get());

return serverChatModels ?? remoteChatModels ?? defaultChatModels;
if (serverChatModels && serverChatModels.length > 0) {
return serverChatModels;
}
if (remoteChatModels && remoteChatModels.length > 0) {
return remoteChatModels;
}

return defaultChatModels;
};

const defaultModelProviderList = produce(DEFAULT_MODEL_PROVIDER_LIST, (draft) => {
Expand Down
Loading