Skip to content

Commit

Permalink
Merge branch 'lobehub:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cookieY authored Jan 8, 2025
2 parents e2ad119 + 0578d6d commit b7a325d
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 17 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

# Changelog

### [Version 1.44.1](https://github.com/lobehub/lobe-chat/compare/v1.44.0...v1.44.1)

<sup>Released on **2025-01-08**</sup>

#### 🐛 Bug Fixes

- **misc**: Fix model select not auto update and sort issue.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

- **misc**: Fix model select not auto update and sort issue, closes [#5330](https://github.com/lobehub/lobe-chat/issues/5330) ([dc76d6f](https://github.com/lobehub/lobe-chat/commit/dc76d6f))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

## [Version 1.44.0](https://github.com/lobehub/lobe-chat/compare/v1.43.6...v1.44.0)

<sup>Released on **2025-01-07**</sup>
Expand Down
7 changes: 7 additions & 0 deletions changelog/v1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[
{
"children": {
"fixes": ["Fix model select not auto update and sort issue."]
},
"date": "2025-01-08",
"version": "1.44.1"
},
{
"children": {
"features": ["Brand new AI provider."]
Expand Down
2 changes: 1 addition & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const nextConfig: NextConfig = {
source: '/welcome',
},
],
serverExternalPackages: ['@electric-sql/pglite', 'shiki/wasm', 'sharp'],
serverExternalPackages: ['@electric-sql/pglite', 'sharp'],

transpilePackages: ['pdfjs-dist', 'mermaid'],

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lobehub/chat",
"version": "1.44.0",
"version": "1.44.1",
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
"keywords": [
"framework",
Expand Down
25 changes: 18 additions & 7 deletions src/components/ModelSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IconAvatarProps, ModelIcon, ProviderIcon } from '@lobehub/icons';
import { Icon, Tooltip } from '@lobehub/ui';
import { Avatar, Icon, Tooltip } from '@lobehub/ui';
import { Typography } from 'antd';
import { createStyles } from 'antd-style';
import { Infinity, LucideEye, LucidePaperclip, ToyBrick } from 'lucide-react';
Expand All @@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';

import { ModelAbilities } from '@/types/aiModel';
import { AiProviderSourceType } from '@/types/aiProvider';
import { ChatModelCard } from '@/types/llm';
import { formatTokenNumber } from '@/utils/format';

Expand Down Expand Up @@ -153,16 +154,26 @@ export const ModelItemRender = memo<ModelItemRenderProps>(({ showInfoTag = true,
});

interface ProviderItemRenderProps {
logo?: string;
name: string;
provider: string;
source?: AiProviderSourceType;
}

export const ProviderItemRender = memo<ProviderItemRenderProps>(({ provider, name }) => (
<Flexbox align={'center'} gap={4} horizontal>
<ProviderIcon provider={provider} size={20} type={'mono'} />
{name}
</Flexbox>
));
export const ProviderItemRender = memo<ProviderItemRenderProps>(
({ provider, name, source, logo }) => {
return (
<Flexbox align={'center'} gap={4} horizontal>
{source === 'custom' && !!logo ? (
<Avatar avatar={logo} size={20} style={{ filter: 'grayscale(1)' }} title={name} />
) : (
<ProviderIcon provider={provider} size={20} type={'mono'} />
)}
{name}
</Flexbox>
);
},
);

interface LabelRendererProps {
Icon: FC<IconAvatarProps>;
Expand Down
6 changes: 4 additions & 2 deletions src/database/repositories/aiInfra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AiInfraRepos {
return list
.filter((item) => item.enabled)
.sort((a, b) => a.sort! - b.sort!)
.map((item) => ({ id: item.id, name: item.name, source: item.source }));
.map((item) => ({ id: item.id, logo: item.logo, name: item.name, source: item.source }));
};

getEnabledModels = async () => {
Expand All @@ -86,7 +86,9 @@ export class AiInfraRepos {
{ concurrency: 10 },
);

return [...modelList.flat(), ...userEnabledModels] as EnabledAiModel[];
return [...modelList.flat(), ...userEnabledModels].sort(
(a, b) => (a?.sort || -1) - (b?.sort || -1),
) as EnabledAiModel[];
};

getAiProviderModelList = async (providerId: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/database/server/models/aiModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class AiModelModel {
enabled: aiModels.enabled,
id: aiModels.id,
providerId: aiModels.providerId,
sort: aiModels.sort,
source: aiModels.source,
type: aiModels.type,
})
Expand Down
9 changes: 8 additions & 1 deletion src/features/ModelSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ const ModelSelect = memo<ModelSelectProps>(({ value, onChange, showAbility = tru
}

return enabledList.map((provider) => ({
label: <ProviderItemRender name={provider.name} provider={provider.id} />,
label: (
<ProviderItemRender
logo={provider.logo}
name={provider.name}
provider={provider.id}
source={provider.source}
/>
),
options: getChatModels(provider),
}));
}, [enabledList]);
Expand Down
9 changes: 8 additions & 1 deletion src/features/ModelSwitchPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ const ModelSwitchPanel = memo<PropsWithChildren>(({ children }) => {
return enabledList.map((provider) => ({
children: getModelItems(provider),
key: provider.id,
label: <ProviderItemRender name={provider.name} provider={provider.id} />,
label: (
<ProviderItemRender
logo={provider.logo}
name={provider.name}
provider={provider.id}
source={provider.source}
/>
),
type: 'group',
}));
}, [enabledList]);
Expand Down
4 changes: 2 additions & 2 deletions src/store/aiInfra/slices/aiProvider/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const createAiProviderSlice: StateCreator<
await get().refreshAiProviderRuntimeState();
},
refreshAiProviderRuntimeState: async () => {
await mutate(AiProviderSwrKey.fetchAiProviderRuntimeState);
await mutate([AiProviderSwrKey.fetchAiProviderRuntimeState, true]);
},
removeAiProvider: async (id) => {
await aiProviderService.deleteAiProvider(id);
Expand Down Expand Up @@ -187,8 +187,8 @@ export const createAiProviderSlice: StateCreator<

// 3. 组装最终数据结构
const enabledChatModelList = data.enabledAiProviders.map((provider) => ({
...provider,
children: getModelListByType(provider.id, 'chat'),
id: provider.id,
name: provider.name || provider.id,
}));

Expand Down
1 change: 1 addition & 0 deletions src/store/user/slices/modelList/selectors/modelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const modelProviderListForModelSelect = (s: UserStore): EnabledProviderWithModel
displayName: m.displayName,
id: m.id,
})),
source: 'builtin',
}));

const getModelCardById = (id: string) => (s: UserStore) => {
Expand Down
4 changes: 4 additions & 0 deletions src/types/aiModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { z } from 'zod';

import { AiProviderSourceType } from '@/types/aiProvider';

export type ModelPriceCurrency = 'CNY' | 'USD';

export const AiModelSourceEnum = {
Expand Down Expand Up @@ -312,5 +314,7 @@ interface AiModelForSelect {
export interface EnabledProviderWithModels {
children: AiModelForSelect[];
id: string;
logo?: string;
name: string;
source: AiProviderSourceType;
}
6 changes: 4 additions & 2 deletions src/types/aiProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

import { AiModelConfig, AiModelSourceType, AiModelType, ModelAbilities } from '@/types/aiModel';
import { AiModelConfig, AiModelType, ModelAbilities } from '@/types/aiModel';
import { SmoothingParams } from '@/types/llm';

export const AiProviderSourceEnum = {
Expand Down Expand Up @@ -182,8 +182,9 @@ export interface AiProviderSortMap {

export interface EnabledProvider {
id: string;
logo?: string;
name?: string;
source: AiModelSourceType;
source: AiProviderSourceType;
}

export interface EnabledAiModel {
Expand All @@ -193,6 +194,7 @@ export interface EnabledAiModel {
displayName?: string;
id: string;
providerId: string;
sort?: number;
type: AiModelType;
}

Expand Down

0 comments on commit b7a325d

Please sign in to comment.