import IconFont from '@/components/icon-font'; import { ClearOutlined, CloseOutlined, MoreOutlined, SettingOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Checkbox, Dropdown, Popover, Select } from 'antd'; import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react'; import SimpleBar from 'simplebar-react'; import 'simplebar-react/dist/simplebar.min.css'; import useChatCompletion from '../../hooks/use-chat-completion'; import '../../style/model-item.less'; import ParamsSettings from '../params-settings'; import MessageContent from './message-content'; interface ModelItemProps { model?: string; globalParams: Record; setGlobalParams: (value: Record) => void; modelList: Global.BaseOption[]; systemMessage: string; ref: any; } const ModelItem: React.FC = forwardRef( ({ model, systemMessage, modelList, globalParams, setGlobalParams }, ref) => { const intl = useIntl(); const isApplyToAllModels = useRef(false); const [params, setParams] = useState>({}); // const [messageList, setMessageList] = useState< // { // role: 'user' | 'assistant'; // content: string; // }[] // >([]); const { messageList, submitMessage, abortFetch, setMessageList, loading } = useChatCompletion(systemMessage, params); useImperativeHandle(ref, () => { return { submit: submitMessage, abortFetch, setMessageList, loading }; }); const actions = [ { label: intl.formatMessage({ id: 'common.button.clear' }), key: 'clear', icon: }, { label: intl.formatMessage({ id: 'playground.viewcode' }), key: 'viewcode', icon: } ]; const handleModelChange = (value: string) => { setParams({ ...params, model: value }); }; const handleApplyToAllModels = (e: any) => { console.log('checkbox change:', e.target.checked); isApplyToAllModels.current = e.target.checked; if (e.target.checked) { setGlobalParams({ ...params }); } }; const handleOnValuesChange = ( changeValues: any, allValues: Record ) => { console.log('value:', allValues, isApplyToAllModels.current); if (isApplyToAllModels.current) { setParams({ ...params, ...allValues }); setGlobalParams({ ...allValues }); } else { setParams({ ...params, ...changeValues }); } }; const handleDropdownAction = ({ key }: { key: string }) => { console.log('key:', key); }; useEffect(() => { console.log('globalParams:', globalParams.model, globalParams); setParams({ ...params, ...globalParams }); }, [globalParams]); useEffect(() => { return () => { abortFetch(); }; }, []); return (
} trigger={['click']} arrow={false} fresh={true} title={
Apply to all models
} >
); } ); export default React.memo(ModelItem);