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

[pull] main from lobehub:main #154

Merged
merged 3 commits into from
Jan 20, 2025
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
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.47.5](https://github.com/lobehub/lobe-chat/compare/v1.47.4...v1.47.5)

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

#### ♻ Code Refactoring

- **misc**: Improve ai provider code.

<br/>

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

#### Code refactoring

- **misc**: Improve ai provider code, closes [#5514](https://github.com/lobehub/lobe-chat/issues/5514) ([92789cd](https://github.com/lobehub/lobe-chat/commit/92789cd))

</details>

<div align="right">

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

</div>

### [Version 1.47.4](https://github.com/lobehub/lobe-chat/compare/v1.47.3...v1.47.4)

<sup>Released on **2025-01-18**</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": {
"improvements": ["Improve ai provider code."]
},
"date": "2025-01-20",
"version": "1.47.5"
},
{
"children": {},
"date": "2025-01-18",
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.47.4",
"version": "1.47.5",
"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
13 changes: 11 additions & 2 deletions src/app/(main)/settings/provider/ProviderMenu/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createStyles } from 'antd-style';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import { Center, Flexbox } from 'react-layout-kit';

import { AiProviderListItem, AiProviderSourceEnum } from '@/types/aiProvider';

Expand Down Expand Up @@ -62,7 +62,16 @@ const ProviderItem = memo<AiProviderListItem>(({ id, name, source, enabled, logo
)}
{name}
</Flexbox>
{enabled && <Badge status="success" />}
<Flexbox horizontal>
{enabled && (
<Center width={24}>
<Badge status="success" />
</Center>
)}
{/* cloud slot */}

{/* cloud slot */}
</Flexbox>
</Link>
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Skeleton } from 'antd';
import { createStyles } from 'antd-style';
import { FC } from 'react';

import InstantSwitch from '@/components/InstantSwitch';
import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';

const useStyles = createStyles(({ css }) => ({
switchLoading: css`
width: 44px !important;
min-width: 44px !important;
height: 22px !important;
border-radius: 12px !important;
`,
}));

interface SwitchProps {
Component?: FC<{ id: string }>;
id: string;
}

const Switch = ({ id, Component }: SwitchProps) => {
const { styles } = useStyles();

const [toggleProviderEnabled, enabled, isLoading] = useAiInfraStore((s) => [
s.toggleProviderEnabled,
aiProviderSelectors.isProviderEnabled(id)(s),
aiProviderSelectors.isAiProviderConfigLoading(id)(s),
]);

if (isLoading) return <Skeleton.Button active className={styles.switchLoading} />;

// slot for cloud
if (Component) return <Component id={id} />;

return (
<InstantSwitch
enabled={enabled}
onChange={async (enabled) => {
await toggleProviderEnabled(id as any, enabled);
}}
/>
);
};

export default Switch;
15 changes: 2 additions & 13 deletions src/app/(main)/settings/provider/features/ProviderConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Trans, useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';
import urlJoin from 'url-join';

import InstantSwitch from '@/components/InstantSwitch';
import { FORM_STYLE } from '@/const/layoutTokens';
import { AES_GCM_URL, BASE_PROVIDER_DOC_URL } from '@/const/url';
import { isServerMode } from '@/const/version';
Expand All @@ -26,6 +25,7 @@ import {
import { KeyVaultsConfigKey, LLMProviderApiTokenKey, LLMProviderBaseUrlKey } from '../../const';
import Checker from './Checker';
import { SkeletonInput } from './SkeletonInput';
import EnableSwitch from './EnableSwitch';
import UpdateProviderInfo from './UpdateProviderInfo';

const useStyles = createStyles(({ css, prefixCls, responsive, token }) => ({
Expand Down Expand Up @@ -131,7 +131,6 @@ const ProviderConfig = memo<ProviderConfigProps>(
const { cx, styles, theme } = useStyles();

const [
toggleProviderEnabled,
useFetchAiProviderItem,
updateAiProviderConfig,
enabled,
Expand All @@ -141,7 +140,6 @@ const ProviderConfig = memo<ProviderConfigProps>(
isProviderEndpointNotEmpty,
isProviderApiKeyNotEmpty,
] = useAiInfraStore((s) => [
s.toggleProviderEnabled,
s.useFetchAiProviderItem,
s.updateAiProviderConfig,
aiProviderSelectors.isProviderEnabled(id)(s),
Expand Down Expand Up @@ -285,16 +283,7 @@ const ProviderConfig = memo<ProviderConfigProps>(
{extra}

{isCustom && <UpdateProviderInfo />}
{isLoading ? (
<Skeleton.Button active className={styles.switchLoading} />
) : (
<InstantSwitch
enabled={enabled}
onChange={async (enabled) => {
await toggleProviderEnabled(id as any, enabled);
}}
/>
)}
<EnableSwitch id={id} />
</Flexbox>
),
title: (
Expand Down
Loading