import { type FC, type ReactNode, useState, useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Col, Row, App, Skeleton, Space, Select } from 'antd' import clsx from 'clsx' import ConversationEmptyIcon from '@/assets/images/conversation/conversationEmpty.svg' import AnalysisEmptyIcon from '@/assets/images/conversation/analysisEmpty.png' import Card from './components/Card' import Chat from './components/Chat' import { readService, getUserMemoryList } from '@/api/memory' import Empty from '@/components/Empty' import Markdown from '@/components/Markdown' import type { Data } from '@/views/UserMemory/types' export interface TestParams { group_id: string; message: string; search_switch: string; history: { role: string; content: string }[]; web_search?: boolean; memory?: boolean; conversation_id?: string; } interface DataItem { id: string; question: string; type: string; reason: string; } export interface LogItem { type: string; title: string; data?: DataItem[] | Record; raw_results?: string; summary?: string; query?: string; reason?: string; result?: string; original_query: string; index?: number; } const ContentWrapper: FC<{ children: ReactNode }> = ({ children }) => (
{children}
) const MemoryConversation: FC = () => { const { t } = useTranslation() const { message } = App.useApp(); const [query, setQuery] = useState({ group_id: '', message: '', search_switch: '0', history: [], }) const [userId, setUserId] = useState() const [loading, setLoading] = useState(false) const [chatData, setChatData] = useState<{ content: string; created_at: string | number; role: string }[]>([]) const [logs, setLogs] = useState([]) const [userList, setUserList] = useState([]) useEffect(() => { getUserMemoryList().then(res => { setUserList((res as Data[] || []).map(item => ({ ...item, name: item.end_user?.other_name && item.end_user?.other_name !== '' ? item.end_user?.other_name : item.end_user?.id }))) }) }, []) const handleSend = () => { if(!userId) { message.warning(t('common.inputPlaceholder', { title: t('memoryConversation.userID') })) return } setChatData(prev => [...prev, { content: query.message || '', created_at: new Date().getTime(), role: 'user' }]) setLoading(true) readService({ ...query, group_id: userId, history: [], }) .then(res => { const response = res as { answer: string; intermediate_outputs: LogItem[] } setChatData(prev => [...prev, { content: response.answer || '-', created_at: new Date().getTime(), role: 'assistant' }]) setLogs(response.intermediate_outputs) }) .finally(() => { setLoading(false) }) } return ( <>