mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(core): cite source documents in the AI answer (#9863)
Support issue [BS-2424](https://linear.app/affine-design/issue/BS-2424). ### What changed? - Add relevant document prompt templates. - Add citation rules in system prompts. - Change message `params` type to `Record<string, any>` - Add unit test. <div class='graphite__hidden'> <div>🎥 Video uploaded on Graphite:</div> <a href="https://app.graphite.dev/media/video/sJGviKxfE3Ap685cl5bj/ec24e664-039e-4fab-bd26-b3312f011daf.mov"> <img src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/sJGviKxfE3Ap685cl5bj/ec24e664-039e-4fab-bd26-b3312f011daf.mov"> </a> </div> <video src="https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sJGviKxfE3Ap685cl5bj/ec24e664-039e-4fab-bd26-b3312f011daf.mov">录屏2025-01-23 10.40.38.mov</video>
This commit is contained in:
@@ -17,7 +17,7 @@ export type TextToTextOptions = {
|
||||
sessionId?: string | Promise<string>;
|
||||
content?: string;
|
||||
attachments?: (string | Blob | File)[];
|
||||
params?: Record<string, string>;
|
||||
params?: Record<string, any>;
|
||||
timeout?: number;
|
||||
stream?: boolean;
|
||||
signal?: AbortSignal;
|
||||
|
||||
@@ -117,11 +117,22 @@ export function setupAIProvider(
|
||||
const sessionId =
|
||||
options.sessionId ??
|
||||
getChatSessionId(options.workspaceId, options.docId, options.attachments);
|
||||
const { input, docs, ...rest } = options;
|
||||
const params = docs?.length
|
||||
? {
|
||||
docs: docs.map((doc, i) => ({
|
||||
docId: doc.docId,
|
||||
markdown: doc.markdown,
|
||||
index: i + 1,
|
||||
})),
|
||||
}
|
||||
: undefined;
|
||||
return textToText({
|
||||
...options,
|
||||
...rest,
|
||||
client,
|
||||
content: options.input,
|
||||
content: input,
|
||||
sessionId,
|
||||
params,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user