mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
@@ -117,6 +117,13 @@ export class ChatPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
private preDefinedParams(params: PromptParams) {
|
||||
return {
|
||||
'affine::date': new Date().toLocaleDateString(),
|
||||
'affine::language': params.language || 'English',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* render prompt messages with params
|
||||
* @param params record of params, e.g. { name: 'Alice' }
|
||||
@@ -125,7 +132,9 @@ export class ChatPrompt {
|
||||
finish(params: PromptParams, sessionId?: string): PromptMessage[] {
|
||||
this.checkParams(params, sessionId);
|
||||
|
||||
const { attachments: attach, ...restParams } = params;
|
||||
const { attachments: attach, ...restParams } = Object.fromEntries(
|
||||
Object.entries(params).filter(([k]) => !k.startsWith('affine::'))
|
||||
);
|
||||
const paramsAttach = Array.isArray(attach) ? attach : [];
|
||||
|
||||
return this.messages.map(
|
||||
@@ -133,7 +142,10 @@ export class ChatPrompt {
|
||||
const result: PromptMessage = {
|
||||
...rest,
|
||||
params,
|
||||
content: Mustache.render(content, restParams),
|
||||
content: Mustache.render(
|
||||
content,
|
||||
Object.assign({}, restParams, this.preDefinedParams(restParams))
|
||||
),
|
||||
};
|
||||
|
||||
const attachments = [
|
||||
|
||||
Reference in New Issue
Block a user