Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update chat prompt #6639

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) {}
}
19 changes: 18 additions & 1 deletion packages/backend/server/src/data/migrations/utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
darkskygit marked this conversation as resolved.
Show resolved Hide resolved
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',
Expand Down
7 changes: 6 additions & 1 deletion packages/backend/server/src/plugins/copilot/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createHash } from 'node:crypto';

import { BadRequestException, Logger } from '@nestjs/common';
import {
Args,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/server/src/plugins/copilot/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createChatSession({
return client.createSession({
workspaceId,
docId,
promptName: 'debug:chat:gpt4',
promptName: 'chat:gpt4',
});
}

Expand Down
Loading