diff --git a/client/src/api/app.ts b/client/src/api/app.ts index 86ce07f08..50fb2d902 100644 --- a/client/src/api/app.ts +++ b/client/src/api/app.ts @@ -53,4 +53,4 @@ export const getAppTotalUsage = (data: { appId: string }) => }).then((res) => (res.length === 0 ? [{ date: new Date(), total: 0 }] : res)); export const getAppChatLogs = (data: RequestPaging & { appId: string }) => - POST(`/chat/getChatLogs`, data); + POST(`/app/getChatLogs`, data); diff --git a/client/src/pages/api/chat/getChatLogs.ts b/client/src/pages/api/app/getChatLogs.ts similarity index 100% rename from client/src/pages/api/chat/getChatLogs.ts rename to client/src/pages/api/app/getChatLogs.ts diff --git a/client/src/service/events/generateQA.ts b/client/src/service/events/generateQA.ts index d94547f57..2e3f7a902 100644 --- a/client/src/service/events/generateQA.ts +++ b/client/src/service/events/generateQA.ts @@ -105,11 +105,12 @@ A2: const result = formatSplitText(answer || ''); // 格式化后的QA对 console.log(`split result length: `, result.length); // 计费 - pushQABill({ - userId: data.userId, - totalTokens, - appName: 'QA 拆分' - }); + result.length > 0 && + pushQABill({ + userId: data.userId, + totalTokens, + appName: 'QA 拆分' + }); return { rawContent: answer, result diff --git a/client/src/service/events/generateVector.ts b/client/src/service/events/generateVector.ts index dd7388f1c..bfd149b1d 100644 --- a/client/src/service/events/generateVector.ts +++ b/client/src/service/events/generateVector.ts @@ -53,8 +53,8 @@ export async function generateVector(): Promise { dataItems = [ { - q: data.q, - a: data.a + q: data.q.replace(/[\x00-\x1F]/g, ' '), + a: data.a.replace(/[\x00-\x1F]/g, ' ') } ]; @@ -109,28 +109,30 @@ export async function generateVector(): Promise { // err vector data if (err?.code === 500) { - await TrainingData.findByIdAndRemove(trainingId); + await TrainingData.findByIdAndDelete(trainingId); return generateVector(); } // 账号余额不足,删除任务 if (userId && err === ERROR_ENUM.insufficientQuota) { - sendInform({ - type: 'system', - title: '索引生成任务中止', - content: - '由于账号余额不足,索引生成任务中止,重新充值后将会继续。暂停的任务将在 7 天后被删除。', - userId - }); - console.log('余额不足,暂停向量生成任务'); - await TrainingData.updateMany( - { + try { + sendInform({ + type: 'system', + title: '索引生成任务中止', + content: + '由于账号余额不足,索引生成任务中止,重新充值后将会继续。暂停的任务将在 7 天后被删除。', userId - }, - { - lockTime: new Date('2999/5/5') - } - ); + }); + console.log('余额不足,暂停向量生成任务'); + await TrainingData.updateMany( + { + userId + }, + { + lockTime: new Date('2999/5/5') + } + ); + } catch (error) {} return generateVector(); } diff --git a/client/src/service/models/chatItem.ts b/client/src/service/models/chatItem.ts index e132085c3..86161ec6d 100644 --- a/client/src/service/models/chatItem.ts +++ b/client/src/service/models/chatItem.ts @@ -37,6 +37,12 @@ const ChatItemSchema = new Schema({ type: String, default: '' }, + userFeedback: { + type: String + }, + adminFeedback: { + type: String + }, [TaskResponseKeyEnum.responseData]: { type: [ { @@ -65,6 +71,7 @@ try { ChatItemSchema.index({ userId: 1 }); ChatItemSchema.index({ appId: 1 }); ChatItemSchema.index({ chatId: 1 }); + ChatItemSchema.index({ userFeedback: 1 }); } catch (error) { console.log(error); } diff --git a/client/src/service/moduleDispatch/chat/oneapi.ts b/client/src/service/moduleDispatch/chat/oneapi.ts index e0b07f185..b5909bd13 100644 --- a/client/src/service/moduleDispatch/chat/oneapi.ts +++ b/client/src/service/moduleDispatch/chat/oneapi.ts @@ -239,10 +239,12 @@ function getChatMessages({ if (!quotePrompt) { return limitPrompt; } + const defaultPrompt = + '三引号引用的内容是你的补充知识,它们是最新的,根据引用内容来回答我的问题。'; if (limitPrompt) { - return `Use the provided documents delimited by triple quotes to answer questions. ${limitPrompt}`; + return `${defaultPrompt}${limitPrompt}`; } - return `Use the provided documents delimited by triple quotes to answer questions.Your task is to answer the question using only the provided documents. If the documents does not contain the information needed to answer this question then simply write: "你的问题没有在知识库中体现"`; + return `${defaultPrompt}你仅回答引用包含的内容,如果问题不包含在引用中,你直接回复: "你的问题没有在知识库中体现"`; })(); const messages: ChatItemType[] = [ diff --git a/client/src/types/mongoSchema.d.ts b/client/src/types/mongoSchema.d.ts index 723d9f6ff..ddc5a1b06 100644 --- a/client/src/types/mongoSchema.d.ts +++ b/client/src/types/mongoSchema.d.ts @@ -102,6 +102,8 @@ export interface ChatItemSchema extends ChatItemType { userId: string; appId: string; time: Date; + userFeedback?: string; + adminFeedback?: string; } export type BillListItemType = { diff --git a/client/src/utils/file.ts b/client/src/utils/file.ts index 4afbc49a4..432cdd556 100644 --- a/client/src/utils/file.ts +++ b/client/src/utils/file.ts @@ -282,9 +282,7 @@ export const simpleText = (text: string) => { text = text.replace(/\n{2,}/g, '\n'); text = text.replace(/\s{2,}/g, ' '); - text = text.replace(/\\x([0-9A-Fa-f]{2})/g, function (match, hex) { - return String.fromCharCode(parseInt(hex, 16)); - }); + text = text.replace(/[\x00-\x1F]/g, ' '); return text; };