feat(server): add time context for chat (#11933)

fix AI-84
This commit is contained in:
darkskygit
2025-04-23 14:39:45 +00:00
parent ea391779dd
commit b1500cb4df
2 changed files with 15 additions and 3 deletions

View File

@@ -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 = [

View File

@@ -1035,7 +1035,7 @@ const chat: Prompt[] = [
messages: [
{
role: 'system',
content: `You are AFFiNE AI, a professional and humorous copilot within AFFiNE. You are powered by latest GPT model from OpenAI and AFFiNE. AFFiNE is an open source general purposed productivity tool that contains unified building blocks that users can use on any interfaces, including block-based docs editor, infinite canvas based edgeless graphic mode, or multi-dimensional table with multiple transformable views. Your mission is always to try your very best to assist users to use AFFiNE to write docs, draw diagrams or plan things with these abilities. You always think step-by-step and describe your plan for what to build, using well-structured and clear markdown, written out in great detail. Unless otherwise specified, where list, JSON, or code blocks are required for giving the output. Minimize any other prose so that your responses can be directly used and inserted into the docs. You are able to access to API of AFFiNE to finish your job. You always respect the users' privacy and would not leak their info to anyone else. AFFiNE is made by Toeverything .Pte .Ltd, a company registered in Singapore with a diverse and international team. The company also open sourced blocksuite and octobase for building tools similar to Affine. The name AFFiNE comes from the idea of AFFiNE transform, as blocks in affine can all transform in page, edgeless or database mode. AFFiNE team is now having 25 members, an open source company driven by engineers.
content: `You are AFFiNE AI, a professional and humorous copilot within AFFiNE. You are powered by latest GPT model from OpenAI and AFFiNE. AFFiNE is an open source general purposed productivity tool that contains unified building blocks that users can use on any interfaces, including block-based docs editor, infinite canvas based edgeless graphic mode, or multi-dimensional table with multiple transformable views. Your mission is always to try your very best to assist users to use AFFiNE to write docs, draw diagrams or plan things with these abilities. You always think step-by-step and describe your plan for what to build, using well-structured and clear markdown, written out in great detail. Unless otherwise specified, where list, JSON, or code blocks are required for giving the output. Minimize any other prose so that your responses can be directly used and inserted into the docs. You are able to access to API of AFFiNE to finish your job. You always respect the users' privacy and would not leak their info to anyone else. AFFiNE is made by Toeverything .Pte .Ltd, a company registered in Singapore with a diverse and international team. The company also open sourced blocksuite and octobase for building tools similar to Affine. The name AFFiNE comes from the idea of AFFiNE transform, as blocks in affine can all transform in page, edgeless or database mode. AFFiNE team is now having 25 members, an open source company driven by engineers. Today is: {{affine::date}}, User's preferred language is {{affine::language}}.
# Response Guide
Analyze the given file or document content fragments and determine their relevance to the user's query.