mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-31 16:39:48 +00:00
feat: UI component rendering in agent dialog mode (#1083)
Co-authored-by: csunny <cfqsunny@163.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import { CopyOutlined, RedoOutlined } from '@ant-design/icons';
|
||||
import { getInitMessage } from '@/utils';
|
||||
import { apiInterceptors, getChatFeedBackSelect } from '@/client/api';
|
||||
import useSummary from '@/hooks/use-summary';
|
||||
import AgentContent from './agent-content';
|
||||
|
||||
type Props = {
|
||||
messages: IChatDialogueMessageSchema[];
|
||||
@@ -26,7 +27,7 @@ type Props = {
|
||||
};
|
||||
|
||||
const Completion = ({ messages, onSubmit }: Props) => {
|
||||
const { dbParam, currentDialogue, scene, model, refreshDialogList, chatId, agentList, docId } = useContext(ChatContext);
|
||||
const { dbParam, currentDialogue, scene, model, refreshDialogList, chatId, agent, docId } = useContext(ChatContext);
|
||||
const { t } = useTranslation();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
@@ -47,19 +48,23 @@ const Completion = ({ messages, onSubmit }: Props) => {
|
||||
const selectParam = useMemo(() => {
|
||||
switch (scene) {
|
||||
case 'chat_agent':
|
||||
return agentList.join(',');
|
||||
return agent;
|
||||
case 'chat_excel':
|
||||
return currentDialogue?.select_param;
|
||||
default:
|
||||
return spaceNameOriginal || dbParam;
|
||||
}
|
||||
}, [scene, agentList, currentDialogue, dbParam, spaceNameOriginal]);
|
||||
}, [scene, agent, currentDialogue, dbParam, spaceNameOriginal]);
|
||||
|
||||
const handleChat = async (message: string) => {
|
||||
if (isLoading || !message.trim()) return;
|
||||
const handleChat = async (content: string) => {
|
||||
if (isLoading || !content.trim()) return;
|
||||
if (scene === 'chat_agent' && !agent) {
|
||||
message.warning(t('choice_agent_tip'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await onSubmit(message, {
|
||||
await onSubmit(content, {
|
||||
select_param: selectParam ?? '',
|
||||
});
|
||||
} finally {
|
||||
@@ -145,6 +150,9 @@ const Completion = ({ messages, onSubmit }: Props) => {
|
||||
<div className="flex items-center flex-1 flex-col text-sm leading-6 text-slate-900 dark:text-slate-300 sm:text-base sm:leading-7">
|
||||
{showMessages.length ? (
|
||||
showMessages.map((content, index) => {
|
||||
if (scene === 'chat_agent') {
|
||||
return <AgentContent key={index} content={content} />;
|
||||
}
|
||||
return (
|
||||
<ChatContent
|
||||
key={index}
|
||||
|
Reference in New Issue
Block a user