Skip to content

Commit e061e80

Browse files
newfish-cmykc121914yu
authored andcommitted
chat quote reader (#3912)
* init chat quote full text reader * linked structure * dataset data linked * optimize code * fix ts build * test finish * delete log * fix * fix ts * fix ts * remove nextId * initial scroll * fix * fix
1 parent 4655c27 commit e061e80

File tree

64 files changed

+2676
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2676
-369
lines changed

packages/global/core/chat/type.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export type ChatItemType = (UserChatItemType | SystemChatItemType | AIChatItemTy
134134

135135
// Frontend type
136136
export type ChatSiteItemType = (UserChatItemType | SystemChatItemType | AIChatItemType) & {
137+
_id?: string;
137138
dataId: string;
138139
status: `${ChatStatusEnum}`;
139140
moduleName?: string;

packages/global/core/dataset/type.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@ export type DatasetDataSchemaType = {
112112
tmbId: string;
113113
datasetId: string;
114114
collectionId: string;
115-
datasetId: string;
116-
collectionId: string;
117115
chunkIndex: number;
118116
updateTime: Date;
119117
q: string; // large chunks or question
120118
a: string; // answer or custom content
119+
history?: {
120+
q: string;
121+
a: string;
122+
updateTime: Date;
123+
}[];
121124
forbid?: boolean;
122125
fullTextToken: string;
123126
indexes: DatasetDataIndexItemType[];

packages/global/support/outLink/type.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export type OutLinkSchema<T extends OutlinkAppType = undefined> = {
6363
responseDetail: boolean;
6464
// whether to hide the node status
6565
showNodeStatus?: boolean;
66+
// wheter to show the full text reader
67+
// showFullText?: boolean;
6668
// whether to show the complete quote
6769
showRawSource?: boolean;
6870

@@ -89,6 +91,7 @@ export type OutLinkEditType<T = undefined> = {
8991
name: string;
9092
responseDetail?: OutLinkSchema<T>['responseDetail'];
9193
showNodeStatus?: OutLinkSchema<T>['showNodeStatus'];
94+
// showFullText?: OutLinkSchema<T>['showFullText'];
9295
showRawSource?: OutLinkSchema<T>['showRawSource'];
9396
// response when request
9497
immediateResponse?: string;

packages/service/core/chat/saveChat.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { AppChatConfigType } from '@fastgpt/global/core/app/type';
1515
import { mergeChatResponseData } from '@fastgpt/global/core/chat/utils';
1616
import { pushChatLog } from './pushChatLog';
1717
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
18+
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
1819

1920
type Props = {
2021
chatId: string;
@@ -74,8 +75,42 @@ export async function saveChat({
7475
)?.inputs;
7576

7677
await mongoSessionRun(async (session) => {
78+
const processedContent = content.map((item) => {
79+
if (item.obj === ChatRoleEnum.AI) {
80+
const nodeResponse = item[DispatchNodeResponseKeyEnum.nodeResponse];
81+
82+
if (nodeResponse) {
83+
return {
84+
...item,
85+
[DispatchNodeResponseKeyEnum.nodeResponse]: nodeResponse.map((responseItem) => {
86+
if (
87+
responseItem.moduleType === FlowNodeTypeEnum.datasetSearchNode &&
88+
responseItem.quoteList
89+
) {
90+
return {
91+
...item,
92+
quoteList: responseItem.quoteList.map((quote: any) => ({
93+
id: quote.id,
94+
chunkIndex: quote.chunkIndex,
95+
datasetId: quote.datasetId,
96+
collectionId: quote.collectionId,
97+
sourceId: quote.sourceId,
98+
sourceName: quote.sourceName,
99+
score: quote.score,
100+
tokens: quote.tokens
101+
}))
102+
};
103+
}
104+
return item;
105+
})
106+
};
107+
}
108+
}
109+
return item;
110+
});
111+
77112
const [{ _id: chatItemIdHuman }, { _id: chatItemIdAi }] = await MongoChatItem.insertMany(
78-
content.map((item) => ({
113+
processedContent.map((item) => ({
79114
chatId,
80115
teamId,
81116
tmbId,

packages/service/core/dataset/data/schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ const DatasetDataSchema = new Schema({
4040
type: String,
4141
default: ''
4242
},
43+
history: {
44+
type: [
45+
{
46+
q: String,
47+
a: String,
48+
updateTime: Date
49+
}
50+
]
51+
},
4352
indexes: {
4453
type: [
4554
{

packages/service/support/outLink/schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const OutLinkSchema = new Schema({
5151
type: Boolean,
5252
default: true
5353
},
54+
// showFullText: {
55+
// type: Boolean
56+
// },
5457
showRawSource: {
5558
type: Boolean
5659
},

packages/web/common/fetch/type.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,22 @@ type PaginationResponse<T = {}> = {
1111
total: number;
1212
list: T[];
1313
};
14+
15+
type LinkedPaginationProps<T = {}> = T & {
16+
pageSize: number;
17+
} & RequireOnlyOne<{
18+
initialId: string;
19+
nextId: string;
20+
prevId: string;
21+
}> &
22+
RequireOnlyOne<{
23+
initialIndex: number;
24+
nextIndex: number;
25+
prevIndex: number;
26+
}>;
27+
28+
type LinkedListResponse<T = {}> = {
29+
list: Array<T & { _id: string; index: number }>;
30+
hasMorePrev: boolean;
31+
hasMoreNext: boolean;
32+
};

packages/web/components/common/Icon/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ export const iconPaths = {
3535
'common/dingtalkFill': () => import('./icons/common/dingtalkFill.svg'),
3636
'common/disable': () => import('./icons/common/disable.svg'),
3737
'common/downArrowFill': () => import('./icons/common/downArrowFill.svg'),
38+
'common/download': () => import('./icons/common/download.svg'),
39+
'common/edit': () => import('./icons/common/edit.svg'),
3840
'common/editor/resizer': () => import('./icons/common/editor/resizer.svg'),
3941
'common/enable': () => import('./icons/common/enable.svg'),
4042
'common/errorFill': () => import('./icons/common/errorFill.svg'),
4143
'common/file/move': () => import('./icons/common/file/move.svg'),
44+
'common/fileNotFound': () => import('./icons/common/fileNotFound.svg'),
4245
'common/folderFill': () => import('./icons/common/folderFill.svg'),
4346
'common/folderImport': () => import('./icons/common/folderImport.svg'),
4447
'common/fullScreenLight': () => import('./icons/common/fullScreenLight.svg'),
@@ -86,7 +89,9 @@ export const iconPaths = {
8689
'common/selectLight': () => import('./icons/common/selectLight.svg'),
8790
'common/setting': () => import('./icons/common/setting.svg'),
8891
'common/settingLight': () => import('./icons/common/settingLight.svg'),
92+
'common/solidChevronDown': () => import('./icons/common/solidChevronDown.svg'),
8993
'common/solidChevronRight': () => import('./icons/common/solidChevronRight.svg'),
94+
'common/solidChevronUp': () => import('./icons/common/solidChevronUp.svg'),
9095
'common/subtract': () => import('./icons/common/subtract.svg'),
9196
'common/templateMarket': () => import('./icons/common/templateMarket.svg'),
9297
'common/text/t': () => import('./icons/common/text/t.svg'),
@@ -96,6 +101,7 @@ export const iconPaths = {
96101
'common/trash': () => import('./icons/common/trash.svg'),
97102
'common/upRightArrowLight': () => import('./icons/common/upRightArrowLight.svg'),
98103
'common/uploadFileFill': () => import('./icons/common/uploadFileFill.svg'),
104+
'common/upperRight': () => import('./icons/common/upperRight.svg'),
99105
'common/userInfo': () => import('./icons/common/userInfo.svg'),
100106
'common/variable': () => import('./icons/common/variable.svg'),
101107
'common/viewLight': () => import('./icons/common/viewLight.svg'),
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)