mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
feat(core): move context docs to user prompt (#10162)
Fix issue [BS-2522](https://linear.app/affine-design/issue/BS-2522). ### Why make this change? If the user data contains illegal content, carrying the user data in the system prompt will run the risk of having the account banned. ### What Changed? - Move the `Context Documents` to the user prompt. - Add `withPrompt` in `QueryChatHistoriesInput` options. - Get chat histories without prompt messages. - Omit document context when saving messages to the `aiSessionMessage` db.
This commit is contained in:
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { AiPromptRole, Prisma, PrismaClient } from '@prisma/client';
|
||||
import { omit } from 'lodash-es';
|
||||
|
||||
import {
|
||||
CopilotActionTaken,
|
||||
@@ -255,7 +256,7 @@ export class ChatSessionService {
|
||||
data: state.messages.map(m => ({
|
||||
...m,
|
||||
attachments: m.attachments || undefined,
|
||||
params: m.params || undefined,
|
||||
params: omit(m.params, ['docs']) || undefined,
|
||||
sessionId,
|
||||
})),
|
||||
});
|
||||
@@ -415,8 +416,7 @@ export class ChatSessionService {
|
||||
userId: string,
|
||||
workspaceId?: string,
|
||||
docId?: string,
|
||||
options?: ListHistoriesOptions,
|
||||
withPrompt = false
|
||||
options?: ListHistoriesOptions
|
||||
): Promise<ChatHistory[]> {
|
||||
const extraCondition = [];
|
||||
|
||||
@@ -505,7 +505,7 @@ export class ChatSessionService {
|
||||
const ret = ChatMessageSchema.array().safeParse(messages);
|
||||
if (ret.success) {
|
||||
// render system prompt
|
||||
const preload = withPrompt
|
||||
const preload = options?.withPrompt
|
||||
? prompt
|
||||
.finish(ret.data[0]?.params || {}, id)
|
||||
.filter(({ role }) => role !== 'system')
|
||||
|
||||
Reference in New Issue
Block a user