From 14f4ce2ffedcd140f6399219e70175a2eb5e565d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Wed, 8 Nov 2023 15:49:29 +0800 Subject: [PATCH] support extra userMeta and params --- .../components/InputArea/AutoCompleteTextArea.tsx | 14 ++++++++++++-- src/ProChat/demos/default.tsx | 12 +++++++++++- src/ProChat/store/selectors/chat.ts | 8 +++++--- src/ProChat/types/config.ts | 2 ++ src/ProChat/types/meta.ts | 6 ++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/ProChat/components/InputArea/AutoCompleteTextArea.tsx b/src/ProChat/components/InputArea/AutoCompleteTextArea.tsx index 142cf18d..cda7b281 100644 --- a/src/ProChat/components/InputArea/AutoCompleteTextArea.tsx +++ b/src/ProChat/components/InputArea/AutoCompleteTextArea.tsx @@ -7,7 +7,7 @@ export const AutoCompleteTextArea: React.FC = (props) => { const [autocompleteRequest] = useStore((s) => [s.autocompleteRequest]); const [options, setOptions] = useState<{ value: string; label: string }[]>([]); - + const [open, setOpen] = useState(false); return ( = (props) => { style={{ height: 'max-content', }} + open={open} + onDropdownVisibleChange={(open) => { + setOpen(open); + }} value={props.value} onSelect={(value) => { props.onChange?.({ target: { value } } as any); @@ -26,7 +30,13 @@ export const AutoCompleteTextArea: React.FC = (props) => { setOptions((result as any[]) || []); }} > - + { + if (open) return; + props.onPressEnter?.(e); + }} + /> ); }; diff --git a/src/ProChat/demos/default.tsx b/src/ProChat/demos/default.tsx index f849e8b5..a71df2f5 100644 --- a/src/ProChat/demos/default.tsx +++ b/src/ProChat/demos/default.tsx @@ -12,13 +12,23 @@ export default () => {
{ if (value === '/') { return [{ value: '你可以帮助我列出问题吗?', label: '你可以帮助我列出问题吗?' }]; } return []; }} + userMeta={{ + extra: 'extra', + }} messageItemExtraRender={(_, type) => { if (type === 'user') return 🦐; return 👍; diff --git a/src/ProChat/store/selectors/chat.ts b/src/ProChat/store/selectors/chat.ts index 8b6bd9b1..2fab0aa5 100644 --- a/src/ProChat/store/selectors/chat.ts +++ b/src/ProChat/store/selectors/chat.ts @@ -9,13 +9,15 @@ export const currentChats = (s: ChatStore): ChatMessage[] => { if (Object.keys(s.chats).length === 0) return []; const getMeta = (message: ChatMessage): MetaData => { - const user = s.userMeta; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { avatar, title, backgroundColor, ...rest } = s.userMeta; const assistant = s.assistantMeta; switch (message.role) { case 'user': { return { - avatar: user?.avatar, - title: user?.title, + avatar, + title, + ...rest, }; } diff --git a/src/ProChat/types/config.ts b/src/ProChat/types/config.ts index 1501e2fe..797a6493 100644 --- a/src/ProChat/types/config.ts +++ b/src/ProChat/types/config.ts @@ -24,6 +24,8 @@ export interface ModelParams { * @default 1 */ top_p?: number; + + [key: string]: any; } export type ModelRoleType = 'user' | 'system' | 'assistant' | 'function'; diff --git a/src/ProChat/types/meta.ts b/src/ProChat/types/meta.ts index 065be8cb..572694f9 100644 --- a/src/ProChat/types/meta.ts +++ b/src/ProChat/types/meta.ts @@ -14,4 +14,10 @@ export interface MetaData { * @description 可选参数,如果不传则使用默认名称 */ title?: string; + + /** + * 附加数据 + * @description 可选参数,如果不传则使用默认名称 + */ + [key: string]: any; }