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: chat sse message show reference #178

Merged
merged 2 commits into from
Jan 23, 2024
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
1 change: 0 additions & 1 deletion config/config.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/**
* local config
*/

import { defineConfig } from '@umijs/max';

export default defineConfig({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Chat/Chat/References/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const RenderReferences: FC<IRenderReferences> = props => {
loading={loading}
onMouseLeaveCallback={onRefContentMouseLeave}
open={Boolean(clear)}
reference={_item?.item || {}}
reference={_item?.item || ({} as Reference)}
>
<Space
direction="horizontal"
Expand Down
46 changes: 25 additions & 21 deletions src/pages/Chat/Chat/References/renderContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,31 @@ const RefContent: FC<IRefContent> = props => {
'-'
)}
<Divider className="divider" />
<Typography.Title level={5}>ηŸ₯θ―†εΊ“</Typography.Title>
<Space>
<FileTextOutlined />
<Typography.Text code ellipsis strong>
{reference.qa_file_path}
</Typography.Text>
</Space>
<Space className="relLine">
<FieldNumberOutlined />
<Tag color={getRelColor(reference.score)}>
η›ΈδΌΌεΊ¦: {(reference.score * 100).toFixed(2)}%
</Tag>
</Space>
<div>
<Typography.Text className="q" strong>
{reference.question}
</Typography.Text>
<Button icon={<EditOutlined />} type="text" />
</div>
<Typography.Paragraph italic>{reference.answer}</Typography.Paragraph>
<Divider className="divider" dashed />
{Boolean(debug) && (
<>
<Typography.Title level={5}>ηŸ₯θ―†εΊ“</Typography.Title>
<Space>
<FileTextOutlined />
<Typography.Text code ellipsis strong>
{reference.qa_file_path}
</Typography.Text>
</Space>
<Space className="relLine">
<FieldNumberOutlined />
<Tag color={getRelColor(reference.score)}>
η›ΈδΌΌεΊ¦: {(reference.score * 100).toFixed(2)}%
</Tag>
</Space>
<div>
<Typography.Text className="q" strong>
{reference.question}
</Typography.Text>
<Button icon={<EditOutlined />} type="text" />
</div>
<Typography.Paragraph italic>{reference.answer}</Typography.Paragraph>
<Divider className="divider" dashed />
</>
)}
<Typography.Title level={5}>εŽŸζ–‡</Typography.Title>
<Typography.Paragraph italic>{reference.content}</Typography.Paragraph>
<Space>
Expand Down
42 changes: 42 additions & 0 deletions src/pages/Chat/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import useGetCommonData from '@/components/hooks/useGetCommonData';
import RenderReferences, { Reference } from '@/pages/Chat/Chat/References';
import { formatJson, getCvsMeta } from '@/pages/Chat/Chat/helper';
import Retry from '@/pages/Chat/Chat/retry';
import request from '@/utils/request';

import './index.less';

Expand Down Expand Up @@ -88,6 +89,41 @@ const Chat: React.FC<IChat> = props => {
resStr: 'messages',
notFetch: !props.conversationId,
});
const fetchLastReference = useCallback(async (cId, mId) => {
if (!mId || !cId) return;
const res = await request
.post({
url: `${window.location.origin}/kubeagi-apis/chat/messages/${mId}/references`,
options: {
body: {
app_name: props.appName,
app_namespace: props.appNamespace,
conversation_id: cId,
message_id: mId,
},
},
})
.catch(error => {
//
});
res?.length &&
setConversation(_conversation => {
const [first, ...rest] = _conversation.data.reverse();
return {
..._conversation,
loadingMsgId: undefined,
data: [
...rest.reverse(),
{
...first,
extra: {
references: res,
},
},
],
};
});
}, []);
useEffect(() => {
if (conversation.data?.length) return;
const app = application?.data?.Application?.getApplication;
Expand Down Expand Up @@ -201,6 +237,7 @@ const Chat: React.FC<IChat> = props => {
const last = _conversation.data.at(-1);
return {
...last,
id: parsedData.message_id || last.id,
content: last.content + (parsedData?.message || ''),
};
}),
Expand All @@ -223,6 +260,11 @@ const Chat: React.FC<IChat> = props => {
shouldUpdateConversationId = false;
props.onNewChat?.(_conversation.id);
}
fetchLastReference(
_conversation.id,
// "791d25a6-7102-4f7c-afcd-29eee3624250" ||
_conversation.data.at(-1)?.id
);
return {
..._conversation,
loadingMsgId: undefined,
Expand Down
Loading