Skip to content

Commit a70d2aa

Browse files
authored
fix: input modal (#5108)
* fix: input modal * fix: input modal * fix: chat logs count
1 parent 8e18562 commit a70d2aa

File tree

4 files changed

+73
-57
lines changed

4 files changed

+73
-57
lines changed

docSite/content/zh-cn/docs/development/upgrading/4914.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ weight: 786
3737
## 🐛 修复
3838

3939
1. 知识库数据输入,识别 QA 模式错误。
40-
2. 知识库标签条件冲突。
40+
2. 知识库标签条件冲突。
41+
3. 对话日志点赞点踩统计。

packages/service/core/chat/chatItemSchema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ const ChatItemSchema = new Schema({
6464
memories: Object,
6565
errorMsg: String,
6666
userGoodFeedback: String,
67-
userBadFeedback: {
68-
type: String
69-
},
67+
userBadFeedback: String,
7068
customFeedbacks: [String],
7169
adminFeedback: {
7270
type: {

projects/app/src/pageComponents/dataset/detail/InputDataModal.tsx

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -76,58 +76,47 @@ const InputDataModal = ({
7676
});
7777
const imagePreivewUrl = watch('imagePreivewUrl');
7878

79-
const { data: collection = defaultCollectionDetail } = useRequest2(
80-
() => getDatasetCollectionById(collectionId),
81-
{
82-
manual: false,
83-
refreshDeps: [collectionId],
84-
onSuccess(res) {
85-
if (res.type === DatasetCollectionTypeEnum.images) {
86-
setCurrentTab(TabEnum.image);
87-
}
79+
const { data: collection = defaultCollectionDetail, loading: initLoading } = useRequest2(
80+
async () => {
81+
const [collection, dataItem] = await Promise.all([
82+
getDatasetCollectionById(collectionId),
83+
...(dataId ? [getDatasetDataItemById(dataId)] : [])
84+
]);
85+
86+
if (dataItem) {
87+
setCurrentTab(dataItem?.a ? TabEnum.qa : TabEnum.chunk);
88+
reset({
89+
q: dataItem.q || '',
90+
a: dataItem.a || '',
91+
imagePreivewUrl: dataItem.imagePreivewUrl,
92+
indexes: dataItem.indexes.map((item) => ({
93+
...item,
94+
fold: true
95+
}))
96+
});
97+
} else if (defaultValue) {
98+
setCurrentTab(defaultValue?.a ? TabEnum.qa : TabEnum.chunk);
99+
reset({
100+
q: defaultValue.q || '',
101+
a: defaultValue.a || '',
102+
imagePreivewUrl: defaultValue.imagePreivewUrl
103+
});
104+
} else {
105+
setCurrentTab(TabEnum.chunk);
88106
}
89-
}
90-
);
91107

92-
// Get data
93-
const { data: dataItem, loading: isFetchingData } = useRequest2(
94-
async () => {
95-
if (dataId) return getDatasetDataItemById(dataId);
96-
return null;
108+
// Forcus reset to image tab
109+
if (collection.type === DatasetCollectionTypeEnum.images) {
110+
setCurrentTab(TabEnum.image);
111+
}
112+
return collection;
97113
},
98114
{
99115
manual: false,
100-
refreshDeps: [dataId],
101-
onSuccess(res) {
102-
if (res) {
103-
reset({
104-
q: res.q || '',
105-
a: res.a || '',
106-
imagePreivewUrl: res.imagePreivewUrl,
107-
indexes: res.indexes.map((item) => ({
108-
...item,
109-
fold: true
110-
}))
111-
});
112-
} else if (defaultValue) {
113-
reset({
114-
q: defaultValue.q || '',
115-
a: defaultValue.a || '',
116-
imagePreivewUrl: defaultValue.imagePreivewUrl
117-
});
118-
}
119-
},
120-
onError(err) {
121-
onClose();
122-
}
116+
refreshDeps: [collectionId, dataId, defaultValue]
123117
}
124118
);
125119

126-
useEffect(() => {
127-
if (currentTab || !dataItem) return;
128-
setCurrentTab(dataItem.a ? TabEnum.qa : TabEnum.chunk);
129-
}, [collection, dataItem, currentTab]);
130-
131120
// Import new data
132121
const { runAsync: sureImportData, loading: isImporting } = useRequest2(
133122
async (e: InputDataType) => {
@@ -138,7 +127,7 @@ const InputDataModal = ({
138127
q: e.q,
139128
a: currentTab === TabEnum.qa ? e.a : '',
140129
// Contains no default index
141-
indexes: e.indexes.filter((item) => !!item.text?.trim())
130+
indexes: e.indexes?.filter((item) => !!item.text?.trim()) || []
142131
};
143132

144133
const dataId = await postInsertData2Dataset(postData);
@@ -194,8 +183,6 @@ const InputDataModal = ({
194183
}
195184
);
196185

197-
const isLoading = isFetchingData;
198-
199186
const icon = useMemo(
200187
() => getCollectionIcon({ type: collection.type, name: collection.sourceName }),
201188
[collection]
@@ -240,7 +227,7 @@ const InputDataModal = ({
240227
<MyBox
241228
display={'flex'}
242229
flexDir={'column'}
243-
isLoading={isLoading}
230+
isLoading={initLoading}
244231
h={'100%'}
245232
py={[6, '1.5rem']}
246233
>

projects/app/src/pages/api/core/app/getChatLogs.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,44 @@ async function handler(
8686
$group: {
8787
_id: null,
8888
messageCount: { $sum: 1 },
89-
goodFeedback: { $sum: { $cond: [{ $eq: ['$userGoodFeedback', true] }, 1, 0] } },
90-
badFeedback: { $sum: { $cond: [{ $eq: ['$userBadFeedback', true] }, 1, 0] } },
89+
goodFeedback: {
90+
$sum: {
91+
$cond: [
92+
{
93+
$ifNull: ['$userGoodFeedback', false]
94+
},
95+
1,
96+
0
97+
]
98+
}
99+
},
100+
badFeedback: {
101+
$sum: {
102+
$cond: [
103+
{
104+
$ifNull: ['$userBadFeedback', false]
105+
},
106+
1,
107+
0
108+
]
109+
}
110+
},
91111
customFeedback: {
92112
$sum: {
93113
$cond: [{ $gt: [{ $size: { $ifNull: ['$customFeedbacks', []] } }, 0] }, 1, 0]
94114
}
95115
},
96-
adminMark: { $sum: { $cond: [{ $eq: ['$adminFeedback', true] }, 1, 0] } }
116+
adminMark: {
117+
$sum: {
118+
$cond: [
119+
{
120+
$ifNull: ['$adminFeedback', false]
121+
},
122+
1,
123+
0
124+
]
125+
}
126+
}
97127
}
98128
}
99129
],
@@ -140,9 +170,9 @@ async function handler(
140170
),
141171
MongoChat.countDocuments(where, { ...readFromSecondary })
142172
]);
143-
173+
console.log(list);
144174
const listWithSourceMember = await addSourceMember({
145-
list: list
175+
list
146176
});
147177

148178
const listWithoutTmbId = list.filter((item) => !item.tmbId);

0 commit comments

Comments
 (0)