Skip to content

Commit

Permalink
🐛 fix: fix ai model abilities issue (lobehub#6060)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Feb 12, 2025
1 parent 10c2af1 commit 718f477
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 31 deletions.
21 changes: 16 additions & 5 deletions src/database/repositories/aiInfra/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEmpty } from 'lodash-es';
import pMap from 'p-map';

import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
Expand Down Expand Up @@ -88,15 +89,25 @@ export class AiInfraRepos {
.map<EnabledAiModel & { enabled?: boolean | null }>((item) => {
const user = allModels.find((m) => m.id === item.id && m.providerId === provider.id);

if (!user)
return {
...item,
abilities: item.abilities || {},
providerId: provider.id,
};

return {
abilities: !!user ? user.abilities : item.abilities || {},
config: !!user ? user.config : item.config,
contextWindowTokens: !!user ? user.contextWindowTokens : item.contextWindowTokens,
abilities: !isEmpty(user.abilities) ? user.abilities : item.abilities || {},
config: !isEmpty(user.config) ? user.config : item.config,
contextWindowTokens:
typeof user.contextWindowTokens === 'number'
? user.contextWindowTokens
: item.contextWindowTokens,
displayName: user?.displayName || item.displayName,
enabled: !!user ? user.enabled : item.enabled,
enabled: user.enabled || item.enabled,
id: item.id,
providerId: provider.id,
sort: !!user ? user.sort : undefined,
sort: user.sort || undefined,
type: item.type,
};
})
Expand Down
11 changes: 11 additions & 0 deletions src/features/DevPanel/SystemInspector/AiProviderRuntimeConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useAiInfraStore } from '@/store/aiInfra';

import JsonViewer from './JsonViewer';

const AiProviderRuntimeConfig = () => {
const aiProviderRuntimeConfig = useAiInfraStore((s) => s.aiProviderRuntimeConfig);

return <JsonViewer data={aiProviderRuntimeConfig} />;
};

export default AiProviderRuntimeConfig;
17 changes: 17 additions & 0 deletions src/features/DevPanel/SystemInspector/JsonViewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Highlighter } from '@lobehub/ui';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';

interface JsonViewerProps {
data: object;
}

const JsonViewer = memo<JsonViewerProps>(({ data }) => {
return (
<Flexbox style={{ overflow: 'scroll' }}>
<Highlighter language={'json'}>{JSON.stringify(data, null, 2)}</Highlighter>
</Flexbox>
);
});

export default JsonViewer;
11 changes: 11 additions & 0 deletions src/features/DevPanel/SystemInspector/ServerConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useServerConfigStore } from '@/store/serverConfig';

import JsonViewer from './JsonViewer';

const ServerConfig = () => {
const serverConfig = useServerConfigStore((s) => s.serverConfig);

return <JsonViewer data={serverConfig} />;
};

export default ServerConfig;
42 changes: 42 additions & 0 deletions src/features/DevPanel/SystemInspector/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use client';

import { TabsNav } from '@lobehub/ui';
import { useState } from 'react';
import { Flexbox } from 'react-layout-kit';

import AiProviderRuntimeConfig from './AiProviderRuntimeConfig';
import ServerConfig from './ServerConfig';

enum TabKey {
AiProviderRuntimeConfig = 'aiProviderRuntimeConfig',
ServerConfig = 'serverConfig',
}

const SystemInspector = () => {
const [activeTab, setActiveTab] = useState<TabKey>(TabKey.ServerConfig);

return (
<Flexbox gap={4} height={'100%'}>
<TabsNav
activeKey={activeTab}
items={[
{
key: TabKey.ServerConfig,
label: 'Server Config',
},
{
key: TabKey.AiProviderRuntimeConfig,
label: 'Ai Provider Runtime Config',
},
]}
onChange={(activeTab) => setActiveTab(activeTab as TabKey)}
variant={'compact'}
/>

{activeTab === TabKey.ServerConfig && <ServerConfig />}
{activeTab === TabKey.AiProviderRuntimeConfig && <AiProviderRuntimeConfig />}
</Flexbox>
);
};

export default SystemInspector;
32 changes: 7 additions & 25 deletions src/features/DevPanel/features/FloatPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { ActionIcon, FluentEmoji, Icon, SideNav } from '@lobehub/ui';
import { Dropdown, FloatButton } from 'antd';
import { FloatButton } from 'antd';
import { createStyles } from 'antd-style';
import { BugIcon, BugOff, XIcon } from 'lucide-react';
import { ReactNode, memo, useEffect, useState } from 'react';
Expand Down Expand Up @@ -81,7 +81,7 @@ interface CollapsibleFloatPanelProps {
const CollapsibleFloatPanel = memo<CollapsibleFloatPanelProps>(({ items }) => {
const { styles, theme } = useStyles();
const [tab, setTab] = useState<string>(items[0].key);
const [isHide, setIsHide] = useState(false);

const [isExpanded, setIsExpanded] = useState(false);
const [position, setPosition] = useState({ x: 100, y: 100 });
const [size, setSize] = useState({ height: minHeight, width: minWidth });
Expand All @@ -108,29 +108,11 @@ const CollapsibleFloatPanel = memo<CollapsibleFloatPanelProps>(({ items }) => {

return (
<>
{!isHide && (
<Dropdown
menu={{
items: [
{
icon: (
<Icon color={theme.colorTextSecondary} icon={BugOff} size={{ fontSize: 16 }} />
),
key: 'hide',
label: 'Hide Toolbar',
onClick: () => setIsHide(true),
},
],
}}
trigger={['hover']}
>
<FloatButton
className={styles.floatButton}
icon={<Icon icon={isExpanded ? BugOff : BugIcon} />}
onClick={() => setIsExpanded(!isExpanded)}
/>
</Dropdown>
)}
<FloatButton
className={styles.floatButton}
icon={<Icon icon={isExpanded ? BugOff : BugIcon} />}
onClick={() => setIsExpanded(!isExpanded)}
/>
{isExpanded && (
<Rnd
bounds="window"
Expand Down
8 changes: 7 additions & 1 deletion src/features/DevPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { BookText, DatabaseIcon, FlagIcon, GlobeLockIcon } from 'lucide-react';
import { BookText, Cog, DatabaseIcon, FlagIcon, GlobeLockIcon } from 'lucide-react';

import CacheViewer from './CacheViewer';
import FeatureFlagViewer from './FeatureFlagViewer';
import MetadataViewer from './MetadataViewer';
import PostgresViewer from './PostgresViewer';
import SystemInspector from './SystemInspector';
import FloatPanel from './features/FloatPanel';

const DevPanel = () => (
Expand All @@ -29,6 +30,11 @@ const DevPanel = () => (
icon: <FlagIcon size={16} />,
key: 'Feature Flags',
},
{
children: <SystemInspector />,
icon: <Cog size={16} />,
key: 'System Status',
},
]}
/>
);
Expand Down

0 comments on commit 718f477

Please sign in to comment.