From 418230ad87149f435d701fe401996b01201c23d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Wed, 25 Oct 2023 01:08:07 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20support=20onResetMessage=20?= =?UTF-8?q?funtion=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: support onResetMessage funtion * fix tets --- src/ProChat/container/index.tsx | 2 ++ src/ProChat/demos/meta.tsx | 5 ++++- src/ProChat/mocks/threebody.ts | 2 +- src/ProChat/store/action.ts | 7 +++++-- src/ProChat/store/initialState.ts | 6 ++++++ src/ProChat/types/config.ts | 6 +++--- src/components/Avatar/index.tsx | 7 ++++++- 7 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ProChat/container/index.tsx b/src/ProChat/container/index.tsx index 54ced77a..24008d50 100644 --- a/src/ProChat/container/index.tsx +++ b/src/ProChat/container/index.tsx @@ -29,6 +29,7 @@ export const ProChat = memo( assistantMeta, showTitle, request, + onResetMessage, style, className, ...props @@ -42,6 +43,7 @@ export const ProChat = memo( userMeta={userMeta} assistantMeta={assistantMeta} request={request} + onResetMessage={onResetMessage} {...props} devtoolOptions={__PRO_CHAT_STORE_DEVTOOLS__} > diff --git a/src/ProChat/demos/meta.tsx b/src/ProChat/demos/meta.tsx index 2f55d838..1744dd63 100644 --- a/src/ProChat/demos/meta.tsx +++ b/src/ProChat/demos/meta.tsx @@ -9,7 +9,10 @@ export default () => {
diff --git a/src/ProChat/mocks/threebody.ts b/src/ProChat/mocks/threebody.ts index b7883bd4..2c8b8c61 100644 --- a/src/ProChat/mocks/threebody.ts +++ b/src/ProChat/mocks/threebody.ts @@ -8,7 +8,7 @@ export const chats = { updateAt: 1697862243540, }, Sb5pAzLL: { - content: '闭嘴', + content: '保持静默,不要回答,不要回答。', createAt: 1697862247302, id: 'Sb5pAzLL', parentId: 'ZGxiX2p4', diff --git a/src/ProChat/store/action.ts b/src/ProChat/store/action.ts index dbba42aa..ee1937dc 100644 --- a/src/ProChat/store/action.ts +++ b/src/ProChat/store/action.ts @@ -83,8 +83,11 @@ export const chatAction: StateCreator ({ - clearMessage: () => { - const { dispatchMessage } = get(); + clearMessage: async () => { + const { dispatchMessage, onResetMessage } = get(); + + // 重置消息,清空聊天记录,等待 onResetMessage 完成后再清空 + if (onResetMessage) await onResetMessage(); dispatchMessage({ type: 'resetMessages' }); diff --git a/src/ProChat/store/initialState.ts b/src/ProChat/store/initialState.ts index 5cce7f20..253658e1 100644 --- a/src/ProChat/store/initialState.ts +++ b/src/ProChat/store/initialState.ts @@ -23,6 +23,12 @@ export interface ChatPropsState { */ helloMessage?: string; request?: string | ChatRequest; + + /** + * 重置消息 + * @returns + */ + onResetMessage?: () => Promise; // /** // * 控制是否流式输出 // * @default true diff --git a/src/ProChat/types/config.ts b/src/ProChat/types/config.ts index 6563c525..1501e2fe 100644 --- a/src/ProChat/types/config.ts +++ b/src/ProChat/types/config.ts @@ -58,13 +58,13 @@ export interface ModelConfig { /** * 角色所使用的语言模型 */ - model: string; + model?: string; /** * 语言模型参数 */ - params: ModelParams; + params?: ModelParams; /** * 系统角色 */ - systemRole: string; + systemRole?: string; } diff --git a/src/components/Avatar/index.tsx b/src/components/Avatar/index.tsx index 56d46c39..ad74c0b3 100644 --- a/src/components/Avatar/index.tsx +++ b/src/components/Avatar/index.tsx @@ -46,6 +46,7 @@ const Avatar = memo( const isImage = Boolean( avatar && ['/', 'http', 'data:'].some((index) => avatar.startsWith(index)), ); + const isBase64 = Boolean(avatar?.startsWith('data')); const emoji = useMemo(() => avatar && !isImage && getEmoji(avatar), [avatar]); const { styles, cx } = useStyles({ background, isEmoji: Boolean(emoji), size }); @@ -60,7 +61,11 @@ const Avatar = memo( }; return isImage ? ( - + } + {...avatarProps} + {...props} + /> ) : ( {emoji ? : text?.toUpperCase().slice(0, 2)}