Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: usemeta support extra #10

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/ProChat/components/InputArea/AutoCompleteTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const AutoCompleteTextArea: React.FC<TextAreaProps> = (props) => {
const [autocompleteRequest] = useStore((s) => [s.autocompleteRequest]);

const [options, setOptions] = useState<{ value: string; label: string }[]>([]);

const [open, setOpen] = useState(false);
return (
<AutoComplete
className={props.className}
Expand All @@ -16,6 +16,10 @@ export const AutoCompleteTextArea: React.FC<TextAreaProps> = (props) => {
style={{
height: 'max-content',
}}
open={open}
onDropdownVisibleChange={(open) => {
setOpen(open);
}}
value={props.value}
onSelect={(value) => {
props.onChange?.({ target: { value } } as any);
Expand All @@ -26,7 +30,13 @@ export const AutoCompleteTextArea: React.FC<TextAreaProps> = (props) => {
setOptions((result as any[]) || []);
}}
>
<Input.TextArea {...props} />
<Input.TextArea
{...props}
onPressEnter={(e) => {
if (open) return;
props.onPressEnter?.(e);
}}
/>
</AutoComplete>
);
};
12 changes: 11 additions & 1 deletion src/ProChat/demos/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ export default () => {
<div style={{ background: theme.colorBgLayout }}>
<ProChat
request={'/api/chat'}
config={example.config}
config={{
...example.config,
params: {
...example.config.params,
userId: '123',
extra: 'extra',
},
}}
autocompleteRequest={async (value) => {
if (value === '/') {
return [{ value: '你可以帮助我列出问题吗?', label: '你可以帮助我列出问题吗?' }];
}
return [];
}}
userMeta={{
extra: 'extra',
}}
messageItemExtraRender={(_, type) => {
if (type === 'user') return <span>🦐</span>;
return <span>👍</span>;
Expand Down
8 changes: 5 additions & 3 deletions src/ProChat/store/selectors/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/ProChat/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface ModelParams {
* @default 1
*/
top_p?: number;

[key: string]: any;
}

export type ModelRoleType = 'user' | 'system' | 'assistant' | 'function';
Expand Down
6 changes: 6 additions & 0 deletions src/ProChat/types/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ export interface MetaData {
* @description 可选参数,如果不传则使用默认名称
*/
title?: string;

/**
* 附加数据
* @description 可选参数,如果不传则使用默认名称
*/
[key: string]: any;
}