import IconFont from '@/components/icon-font'; import breakpoints from '@/config/breakpoints'; import HotKeys from '@/config/hotkeys'; import useWindowResize from '@/hooks/use-window-resize'; import { modelCategoriesMap } from '@/pages/llmodels/config'; import { MessageOutlined, OneToOneOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; import { useIntl } from '@umijs/max'; import { Button, Segmented, Space, Tabs, TabsProps } from 'antd'; import classNames from 'classnames'; import _ from 'lodash'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import { queryModelsList } from './apis'; import GroundLeft from './components/ground-left'; import MultipleChat from './components/multiple-chat'; import './style/play-ground.less'; const Playground: React.FC = () => { const intl = useIntl(); const { size } = useWindowResize(); const [activeKey, setActiveKey] = useState('chat'); const groundLeftRef = useRef(null); const groundRerankerRef = useRef(null); const [modelList, setModelList] = useState[]>([]); const [loaded, setLoaded] = useState(false); const optionsList = useMemo(() => { return [ { label: intl.formatMessage({ id: 'menu.playground.chat' }), value: 'chat', icon: }, { label: intl.formatMessage({ id: 'menu.compare' }), value: 'compare', icon: } ]; }, [intl]); const handleViewCode = useCallback(() => { if (activeKey === 'reranker') { groundRerankerRef.current?.viewCode?.(); } else if (activeKey === 'chat') { groundLeftRef.current?.viewCode?.(); } }, [activeKey]); const handleToggleCollapse = useCallback(() => { if (activeKey === 'reranker') { groundRerankerRef.current?.setCollapse?.(); return; } groundLeftRef.current?.setCollapse?.(); }, [activeKey]); const items: TabsProps['items'] = useMemo(() => { return [ { key: 'chat', label: 'Chat', children: ( ) }, { key: 'compare', label: 'Compare', children: } ]; }, [modelList, loaded]); useEffect(() => { if (size.width < breakpoints.lg && !groundLeftRef.current?.collapse) { groundLeftRef.current?.setCollapse?.(); } }, [size.width]); useEffect(() => { const fetchData = async () => { try { const params = { categories: modelCategoriesMap.llm, with_meta: true }; const res = await queryModelsList(params); const list = _.map(res.data || [], (item: any) => { return { value: item.id, label: item.id, meta: item.meta }; }) as Global.BaseOption[]; setModelList(list); } catch (error) { console.error(error); } finally { setLoaded(true); } }; fetchData(); }, []); const renderExtra = useMemo(() => { if (activeKey === 'compare') { return false; } return ( ); }, [activeKey, intl, handleViewCode, handleToggleCollapse]); const header = useMemo(() => { return { title: (
{intl.formatMessage({ id: 'menu.playground.chat' })} { setActiveKey(key)} > }
), style: { paddingInline: 'var(--layout-content-header-inlinepadding)' }, breadcrumb: {} }; }, [optionsList]); useHotkeys( HotKeys.RIGHT.join(','), () => { if (activeKey === 'chat') { groundLeftRef.current?.setCollapse?.(); } }, { preventDefault: true } ); return (
); }; export default Playground;