From d8ebdaa5ba1c8e8285bc32752d80df306bdc6909 Mon Sep 17 00:00:00 2001 From: Jandiasnow <88074479@qq.com> Date: Thu, 21 Dec 2023 14:51:06 +0800 Subject: [PATCH] feat: change dialogue params --- .../Body/ConfigKnowledge/index.tsx | 30 ++++---- .../ModelAppDetail/Body/Container/index.tsx | 3 +- .../ModelAppDetail/Body/Dialogue/index.tsx | 22 ++++-- src/pages/ModelAppDetail/Body/Modal/index.tsx | 1 - src/pages/ModelAppDetail/Body/index.tsx | 72 +++++++++++-------- .../ModelAppDetail/Header/Edit/index.tsx | 4 +- src/pages/ModelAppDetail/Header/index.tsx | 10 ++- src/pages/ModelAppDetail/index.tsx | 16 +++-- 8 files changed, 92 insertions(+), 66 deletions(-) diff --git a/src/pages/ModelAppDetail/Body/ConfigKnowledge/index.tsx b/src/pages/ModelAppDetail/Body/ConfigKnowledge/index.tsx index 57140be..db438e8 100644 --- a/src/pages/ModelAppDetail/Body/ConfigKnowledge/index.tsx +++ b/src/pages/ModelAppDetail/Body/ConfigKnowledge/index.tsx @@ -30,51 +30,51 @@ const Knowledge: React.FC = props => { }, [props.checkedIds]); return ( - {(canSelect ? items : checkedIds?.map(id => items?.find(item => item.id === id)))?.map( + {(canSelect ? items : checkedIds?.map(id => items?.find(item => item?.id === id)))?.map( item => { return ( { if (!canSelect) return; if (!multi) { - setCheckedIds([item.id]); - props.setCheckedIds && props.setCheckedIds([item.id]); + setCheckedIds([item?.id]); + props.setCheckedIds && props.setCheckedIds([item?.id]); return; } - if (checkedIds.includes(item.id)) { - setCheckedIds(checkedIds?.filter(id => id !== item.id)); + if (checkedIds.includes(item?.id)) { + setCheckedIds(checkedIds?.filter(id => id !== item?.id)); props.setCheckedIds && - props.setCheckedIds(checkedIds?.filter(id => id !== item.id)); + props.setCheckedIds(checkedIds?.filter(id => id !== item?.id)); return; } - setCheckedIds([...checkedIds, item.id]); - props.setCheckedIds && props.setCheckedIds([...checkedIds, item.id]); + setCheckedIds([...checkedIds, item?.id]); + props.setCheckedIds && props.setCheckedIds([...checkedIds, item?.id]); }} >
- + - {item.name} + {item?.name}
{canDelete && ( { - setCheckedIds && setCheckedIds(checkedIds?.filter(id => item.id !== id)); + setCheckedIds && setCheckedIds(checkedIds?.filter(id => item?.id !== id)); props.setCheckedIds && - props.setCheckedIds(checkedIds?.filter(id => item.id !== id)); + props.setCheckedIds(checkedIds?.filter(id => item?.id !== id)); }} /> )} diff --git a/src/pages/ModelAppDetail/Body/Container/index.tsx b/src/pages/ModelAppDetail/Body/Container/index.tsx index fbcaad9..088c9ba 100644 --- a/src/pages/ModelAppDetail/Body/Container/index.tsx +++ b/src/pages/ModelAppDetail/Body/Container/index.tsx @@ -26,12 +26,11 @@ interface ContainerProps { const Container: React.FC = props => { const { children, icon, title, actions, configKey, changeConfig, renderChildren } = props; - const [form] = Form.useForm(); const [modalOpen, setModalOpen] = useState(false); const [modalType, setModalType] = useState(); const [ignored, forceUpdate] = useReducer(x => x + 1, 0); const [actionData, setActionData] = useState(); - const { initConfigs, configs, setConfigs } = useModalAppDetailContext(); + const { initConfigs, configs, setConfigs, form } = useModalAppDetailContext(); useEffect(() => { form.setFieldsValue(initConfigs?.[configKey] || {}); forceUpdate(); diff --git a/src/pages/ModelAppDetail/Body/Dialogue/index.tsx b/src/pages/ModelAppDetail/Body/Dialogue/index.tsx index 1f99a0a..5bd5630 100644 --- a/src/pages/ModelAppDetail/Body/Dialogue/index.tsx +++ b/src/pages/ModelAppDetail/Body/Dialogue/index.tsx @@ -1,19 +1,22 @@ import Icon from '@/assets/img/model-app-bx.png'; import ChatComponent from '@/pages/Chat/Chat'; import { Typography } from '@tenx-ui/materials'; -import { Card, Space, Tag } from 'antd'; -import React, { useState } from 'react'; +import { Card, Space, Spin, Tag } from 'antd'; +import React, { useEffect, useState } from 'react'; import { useModalAppDetailContext } from '../../index'; import Modal from '../Modal'; -interface DialogueProps {} + +interface DialogueProps { + saveIng: boolean; +} const Dialogue: React.FC = props => { const [modalOpen, setModalOpen] = useState(false); const [modalType, setModalType] = useState('reference'); const [modalData, setModalData] = useState(); - const { data } = useModalAppDetailContext(); + const { data, loading } = useModalAppDetailContext(); return ( - <> + {/*
{ setModalOpen(true); @@ -21,7 +24,12 @@ const Dialogue: React.FC = props => { > 对话引用弹窗
*/} - + = props => { Card content - +
); }; diff --git a/src/pages/ModelAppDetail/Body/Modal/index.tsx b/src/pages/ModelAppDetail/Body/Modal/index.tsx index 0cc7f3c..8568db1 100644 --- a/src/pages/ModelAppDetail/Body/Modal/index.tsx +++ b/src/pages/ModelAppDetail/Body/Modal/index.tsx @@ -125,7 +125,6 @@ const Setting: React.FC = props => { } }); }} - destroyOnClose >
diff --git a/src/pages/ModelAppDetail/Body/index.tsx b/src/pages/ModelAppDetail/Body/index.tsx index ed2f713..3b9ca31 100644 --- a/src/pages/ModelAppDetail/Body/index.tsx +++ b/src/pages/ModelAppDetail/Body/index.tsx @@ -1,5 +1,6 @@ import { Card, notification, Typography } from '@tenx-ui/materials'; -import { Button, Col, Flex, Row } from 'antd'; +import { Button, Col, Flex, Row, Tooltip } from 'antd'; +import { isEqual } from 'lodash'; import React, { useState } from 'react'; import utils from '../../../utils/__utils'; import { useModalAppDetailContext } from '../index'; @@ -14,25 +15,35 @@ import styles from './index.less'; interface BodyProps {} const Body: React.FC = props => { - const { refresh, data, configs } = useModalAppDetailContext(); + const { + refresh, + data, + configs, + initConfigs, + loading: cardLoading, + form, + } = useModalAppDetailContext(); const [loading, setLoading] = useState(false); + const [saveIng, setSaveIng] = useState(false); + return ( - + 应用配置 - + setSaveIng(!saveIng); + } catch (error) { + setLoading(false); + notification.warnings({ + message: '保存应用配置失败', + errors: error?.response?.errors, + }); + } + }} + loading={loading} + > + 保存并预览 + + @@ -67,7 +79,7 @@ const Body: React.FC = props => { - + diff --git a/src/pages/ModelAppDetail/Header/Edit/index.tsx b/src/pages/ModelAppDetail/Header/Edit/index.tsx index fb6c8a2..0fa7208 100644 --- a/src/pages/ModelAppDetail/Header/Edit/index.tsx +++ b/src/pages/ModelAppDetail/Header/Edit/index.tsx @@ -36,11 +36,11 @@ const Edit: React.FC = props => { forceUpdate(); }; useEffect(() => { - if (data && type === 'edit') { + if (open && data && type === 'edit') { form.setFieldsValue(data); setImageUrl(data?.icon); } - }, [data, form, type]); + }, [data, form, type, open]); const handleChange = info => { getBase64(info.file, url => { diff --git a/src/pages/ModelAppDetail/Header/index.tsx b/src/pages/ModelAppDetail/Header/index.tsx index c3bd903..858c6c5 100644 --- a/src/pages/ModelAppDetail/Header/index.tsx +++ b/src/pages/ModelAppDetail/Header/index.tsx @@ -1,16 +1,19 @@ import { Col, Divider, Dropdown, Image, Row, Space, Typography } from '@tenx-ui/materials'; +import { getUnifiedHistory } from '@tenx-ui/utils/es/UnifiedLink/index.prod'; import { Card } from 'antd'; import React, { useState } from 'react'; import { useModalAppDetailContext } from '../index'; import Delete from './Delete'; import Edit from './Edit'; import Publish from './Publish'; + interface HeaderProps {} const Header: React.FC = props => { const { refresh, data, loading } = useModalAppDetailContext(); const [modalOpen, setModalOpen] = useState(false); const [modalType, setModalType] = useState<'publish' | 'edit' | 'delete'>(); + const history = getUnifiedHistory(); const handlePublish = () => { setModalOpen(true); @@ -143,11 +146,14 @@ const Header: React.FC = props => { }, }} onClick={() => { - handlePublish(); + history.push( + `/chat?appNamespace=${data?.metadata?.namespace}&appName=${data?.metadata?.name}` + ); + // handlePublish(); }} destroyPopupOnHide={true} > - 发布 + 对话 diff --git a/src/pages/ModelAppDetail/index.tsx b/src/pages/ModelAppDetail/index.tsx index 1da12f4..381be3f 100644 --- a/src/pages/ModelAppDetail/index.tsx +++ b/src/pages/ModelAppDetail/index.tsx @@ -1,5 +1,6 @@ import { Button, Col, Page, Row, Space } from '@tenx-ui/materials'; import { matchPath, useLocation } from '@umijs/max'; +import { Form } from 'antd'; import React, { createContext, useContext, useEffect, useState } from 'react'; import utils from '../../utils/__utils'; import Body from './Body'; @@ -14,7 +15,7 @@ interface ModelAppDetailDetailProps {} const ModelAppDetailDetail: React.FC = () => { const location = useLocation(); const match = matchPath({ path: '/model-app/detail/:id' }, location.pathname); - + const [form] = Form.useForm(); const { data, loading, mutate } = utils.bff.useGetApplication({ name: match?.params?.id, namespace: utils.getAuthData().project, @@ -27,23 +28,23 @@ const ModelAppDetailDetail: React.FC = () => { const Application = data?.Application?.getApplication; const Config = { ConfigConversationStarter: { - prologue: Application?.prologue, + prologue: Application?.prologue || undefined, }, ConfigModelService: { - llm: Application?.llm, - model: Application?.model, + llm: Application?.llm || undefined, + model: Application?.model || undefined, temperature: Application?.temperature, maxLength: Application?.maxLength, conversionWindowSize: Application?.conversionWindowSize, }, ConfigKnowledge: { - knowledgebase: Application?.knowledgebase, + knowledgebase: Application?.knowledgebase || undefined, scoreThreshold: Application?.scoreThreshold, numDocuments: Application?.numDocuments, - docNullReturn: Application?.docNullReturn, + docNullReturn: Application?.docNullReturn || undefined, }, ConfigPrompt: { - userPrompt: Application?.userPrompt, + userPrompt: Application?.userPrompt || undefined, }, ConfigAudio: {}, ConfigNext: { @@ -66,6 +67,7 @@ const ModelAppDetailDetail: React.FC = () => { configs, setConfigs, initConfigs, + form, }} >