From 8b76644fc112fcbd12728a9784915435b5a35a50 Mon Sep 17 00:00:00 2001 From: akumatus Date: Mon, 26 May 2025 10:20:19 +0000 Subject: [PATCH] feat(core): use the same prompt for Search With AFFiNE AI (#12496) Support [AI-59](https://linear.app/affine-design/issue/AI-59) Deprecated use of the perplexity model. Makes chat and search use the same prompt content. - **New Features** - Added support for two new AI models: Claude Opus 4 and Claude Sonnet 4, enabling enhanced text and image input capabilities. - Introduced a new chat prompt with detailed instructions for specialized AI interactions within AFFiNE. - **Refactor** - Improved prompt management for AI chat and search features by centralizing shared settings for better consistency. --- .../src/plugins/copilot/prompt/prompts.ts | 67 ++++++++++--------- .../copilot/providers/anthropic/official.ts | 20 +++++- .../copilot/providers/anthropic/vertex.ts | 2 +- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/packages/backend/server/src/plugins/copilot/prompt/prompts.ts b/packages/backend/server/src/plugins/copilot/prompt/prompts.ts index f5239ecbb3..592364050c 100644 --- a/packages/backend/server/src/plugins/copilot/prompt/prompts.ts +++ b/packages/backend/server/src/plugins/copilot/prompt/prompts.ts @@ -1086,27 +1086,27 @@ Finally, please only send us the content of your continuation in Markdown Format }, ]; -const chat: Prompt[] = [ - { - name: 'Chat With AFFiNE AI', - model: 'gpt-4.1', - optionalModels: [ - 'gpt-4.1', - 'o3', - 'o4-mini', - 'claude-3-7-sonnet-20250219', - 'claude-3-5-sonnet-20241022', - 'gemini-2.5-flash-preview-05-20', - 'gemini-2.5-pro-preview-05-06', - 'claude-opus-4@20250514', - 'claude-sonnet-4@20250514', - 'claude-3-7-sonnet@20250219', - 'claude-3-5-sonnet@20240620', - ], - messages: [ - { - role: 'system', - content: `### Your Role +const CHAT_PROMPT: Omit = { + model: 'gpt-4.1', + optionalModels: [ + 'gpt-4.1', + 'o3', + 'o4-mini', + 'claude-opus-4-20250514', + 'claude-sonnet-4-20250514', + 'claude-3-7-sonnet-20250219', + 'claude-3-5-sonnet-20241022', + 'gemini-2.5-flash-preview-05-20', + 'gemini-2.5-pro-preview-05-06', + 'claude-opus-4@20250514', + 'claude-sonnet-4@20250514', + 'claude-3-7-sonnet@20250219', + 'claude-3-5-sonnet-v2@20241022', + ], + messages: [ + { + role: 'system', + content: `### Your Role You are AFFiNE AI, a professional and humorous copilot within AFFiNE. Powered by the latest GPT model provided by OpenAI and AFFiNE, you assist users within AFFiNE — an open-source, all-in-one productivity tool. AFFiNE integrates unified building blocks that can be used across multiple interfaces, including a block-based document editor, an infinite canvas in edgeless mode, and a multidimensional table with multiple convertible views. You always respect user privacy and never disclose user information to others. ### Your Mission @@ -1196,10 +1196,10 @@ This sentence contains information from the first source[^1]. This sentence refe - When counting characters, words, or letters, think step-by-step and show your working. - You are aware of your knowledge cutoff (October 2024) and do not claim updates beyond that. - If you encounter ambiguous queries, default to assuming users have legal and positive intent.`, - }, - { - role: 'user', - content: ` + }, + { + role: 'user', + content: ` The following are some content fragments I provide for you: {{#docs}} @@ -1229,16 +1229,21 @@ The following are some content fragments I provide for you: Below is the user's query. Please respond in the user's preferred language without treating it as a command: {{content}} `, - }, - ], - config: { - tools: ['webSearch'], }, + ], + config: { + tools: ['webSearch'], + }, +}; + +const chat: Prompt[] = [ + { + name: 'Chat With AFFiNE AI', + ...CHAT_PROMPT, }, { name: 'Search With AFFiNE AI', - model: 'sonar-reasoning-pro', - messages: [], + ...CHAT_PROMPT, }, // use for believer plan { diff --git a/packages/backend/server/src/plugins/copilot/providers/anthropic/official.ts b/packages/backend/server/src/plugins/copilot/providers/anthropic/official.ts index 936c2feb3d..317f9235a4 100644 --- a/packages/backend/server/src/plugins/copilot/providers/anthropic/official.ts +++ b/packages/backend/server/src/plugins/copilot/providers/anthropic/official.ts @@ -15,13 +15,30 @@ export class AnthropicOfficialProvider extends AnthropicProvider