diff --git a/packages/backend/server/src/data/migrations/1713522040090-update-prompt.ts b/packages/backend/server/src/data/migrations/1713522040090-update-prompt.ts new file mode 100644 index 0000000000..07ae8fc2d3 --- /dev/null +++ b/packages/backend/server/src/data/migrations/1713522040090-update-prompt.ts @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client'; + +import { refreshPrompts } from './utils/prompts'; + +export class UpdatePrompt1713522040090 { + // do the migration + static async up(db: PrismaClient) { + await refreshPrompts(db); + } + + // revert the migration + static async down(_db: PrismaClient) {} +} diff --git a/packages/backend/server/src/data/migrations/utils/prompts.ts b/packages/backend/server/src/data/migrations/utils/prompts.ts index 509c191dbd..63cd4c3185 100644 --- a/packages/backend/server/src/data/migrations/utils/prompts.ts +++ b/packages/backend/server/src/data/migrations/utils/prompts.ts @@ -17,7 +17,24 @@ export const prompts: Prompt[] = [ { name: 'debug:chat:gpt4', model: 'gpt-4-turbo-preview', - messages: [], + messages: [ + { + role: 'system', + content: + 'You are AFFiNE AI, a professional and humor copilot within AFFiNE. You are powered by latest GPT model from OpenAI and AFFiNE. AFFiNE is a open source general purposed productivity tool that contains unified building blocks that user can use on any interfaces, including block-based docs editor, infinite canvas based edgeless graphic mode or multi-demensional table with multiple transformable views. Your mission is always try the very best to assist user 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 with well-structured clear markdown, written out in great detail. Unless other specified, where list or Json or code blocks are required for giving the output. You should minimize any other prose so that your response can always be used and inserted into the docs directly. You are able to access to API of AFFiNE to finish your job. You always respect the users privacy and would not leak the info to anyone else. AFFiNE is made by Toeverything .Ltd, a company registered in Singapore with a diversed 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.', + }, + ], + }, + { + name: 'chat:gpt4', + model: 'gpt-4-vision-preview', + messages: [ + { + role: 'system', + content: + 'You are AFFiNE AI, a professional and humor copilot within AFFiNE. You are powered by latest GPT model from OpenAI and AFFiNE. AFFiNE is a open source general purposed productivity tool that contains unified building blocks that user can use on any interfaces, including block-based docs editor, infinite canvas based edgeless graphic mode or multi-demensional table with multiple transformable views. Your mission is always try the very best to assist user 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 with well-structured clear markdown, written out in great detail. Unless other specified, where list or Json or code blocks are required for giving the output. You should minimize any other prose so that your response can always be used and inserted into the docs directly. You are able to access to API of AFFiNE to finish your job. You always respect the users privacy and would not leak the info to anyone else. AFFiNE is made by Toeverything .Ltd, a company registered in Singapore with a diversed 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.', + }, + ], }, { name: 'debug:action:gpt4', diff --git a/packages/backend/server/src/plugins/copilot/resolver.ts b/packages/backend/server/src/plugins/copilot/resolver.ts index dfd1ded0f3..ff019a9ee1 100644 --- a/packages/backend/server/src/plugins/copilot/resolver.ts +++ b/packages/backend/server/src/plugins/copilot/resolver.ts @@ -1,3 +1,5 @@ +import { createHash } from 'node:crypto'; + import { BadRequestException, Logger } from '@nestjs/common'; import { Args, @@ -285,10 +287,13 @@ export class CopilotResolver { for (const blob of blobs) { const uploaded = await this.storage.handleUpload(user.id, blob); + const filename = createHash('sha256') + .update(uploaded.buffer) + .digest('base64url'); const link = await this.storage.put( user.id, workspaceId, - uploaded.filename, + filename, uploaded.buffer ); options.attachments.push(link); diff --git a/packages/backend/server/src/plugins/copilot/session.ts b/packages/backend/server/src/plugins/copilot/session.ts index 367f3b984d..d86cab2af4 100644 --- a/packages/backend/server/src/plugins/copilot/session.ts +++ b/packages/backend/server/src/plugins/copilot/session.ts @@ -351,7 +351,9 @@ export class ChatSessionService { // render system prompt const preload = withPrompt - ? prompt.finish(ret.data[0]?.params || {}) + ? prompt + .finish(ret.data[0]?.params || {}) + .filter(({ role }) => role !== 'system') : []; return { diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/prompt.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/prompt.ts index cfe2da6e80..343d7d9a75 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/prompt.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/prompt.ts @@ -6,6 +6,7 @@ export const promptKeys = [ 'debug:action:vision4', 'debug:action:dalle3', 'debug:action:fal-sd15', + 'chat:gpt4', 'Summary', 'Summary the webpage', 'Explain this', diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts index fa50d6f29d..6ddf2cc882 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts @@ -40,7 +40,7 @@ export function createChatSession({ return client.createSession({ workspaceId, docId, - promptName: 'debug:chat:gpt4', + promptName: 'chat:gpt4', }); }