Skip to content

Commit

Permalink
✨ feat: support onResetMessage funtion (#2)
Browse files Browse the repository at this point in the history
* feat: support onResetMessage funtion

* fix tets
  • Loading branch information
chenshuai2144 authored Oct 25, 2023
1 parent fa40838 commit 418230a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/ProChat/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ProChat = memo<ProChatProps>(
assistantMeta,
showTitle,
request,
onResetMessage,
style,
className,
...props
Expand All @@ -42,6 +43,7 @@ export const ProChat = memo<ProChatProps>(
userMeta={userMeta}
assistantMeta={assistantMeta}
request={request}
onResetMessage={onResetMessage}
{...props}
devtoolOptions={__PRO_CHAT_STORE_DEVTOOLS__}
>
Expand Down
5 changes: 4 additions & 1 deletion src/ProChat/demos/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export default () => {
<div style={{ background: theme.colorBgLayout }}>
<ProChat
showTitle
userMeta={{ avatar: '🧔', title: '罗辑' }}
userMeta={{
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
title: 'Ant Design',
}}
assistantMeta={{ avatar: '🛸', title: '三体世界', backgroundColor: 'blue' }}
initialChats={chats.chats}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/ProChat/mocks/threebody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const chats = {
updateAt: 1697862243540,
},
Sb5pAzLL: {
content: '闭嘴',
content: '保持静默,不要回答,不要回答。',
createAt: 1697862247302,
id: 'Sb5pAzLL',
parentId: 'ZGxiX2p4',
Expand Down
7 changes: 5 additions & 2 deletions src/ProChat/store/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ export const chatAction: StateCreator<ChatStore, [['zustand/devtools', never]],
set,
get,
) => ({
clearMessage: () => {
const { dispatchMessage } = get();
clearMessage: async () => {
const { dispatchMessage, onResetMessage } = get();

// 重置消息,清空聊天记录,等待 onResetMessage 完成后再清空
if (onResetMessage) await onResetMessage();

dispatchMessage({ type: 'resetMessages' });

Expand Down
6 changes: 6 additions & 0 deletions src/ProChat/store/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface ChatPropsState {
*/
helloMessage?: string;
request?: string | ChatRequest;

/**
* 重置消息
* @returns
*/
onResetMessage?: () => Promise<void>;
// /**
// * 控制是否流式输出
// * @default true
Expand Down
6 changes: 3 additions & 3 deletions src/ProChat/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export interface ModelConfig {
/**
* 角色所使用的语言模型
*/
model: string;
model?: string;
/**
* 语言模型参数
*/
params: ModelParams;
params?: ModelParams;
/**
* 系统角色
*/
systemRole: string;
systemRole?: string;
}
7 changes: 6 additions & 1 deletion src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Avatar = memo<AvatarProps>(
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 });
Expand All @@ -60,7 +61,11 @@ const Avatar = memo<AvatarProps>(
};

return isImage ? (
<AntAvatar src={avatar} {...avatarProps} {...props} />
<AntAvatar
src={isBase64 ? avatar : <img src={avatar} alt="avatar" />}
{...avatarProps}
{...props}
/>
) : (
<AntAvatar {...avatarProps} {...props}>
{emoji ? <Emoji emoji={emoji} size={size * 0.8} /> : text?.toUpperCase().slice(0, 2)}
Expand Down

0 comments on commit 418230a

Please sign in to comment.