Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: refresh prompts (#6568)

darkskygit3d15e8353b32
diff --git a/packages/backend/server/src/data/migrations/1712068777394-prompts.ts b/packages/backend/server/src/data/migrations/1712068777394-prompts.ts
index 125bcb60e3..e6b5ecc71f 100644
--- a/packages/backend/server/src/data/migrations/1712068777394-prompts.ts
+++ b/packages/backend/server/src/data/migrations/1712068777394-prompts.ts
@@ -1,31 +1,11 @@
import { PrismaClient } from '@prisma/client';
-import { prompts } from './utils/prompts';
+import { refreshPrompts } from './utils/prompts';
export class Prompts1712068777394 {
// do the migration
static async up(db: PrismaClient) {
- await db.$transaction(async tx => {
- await Promise.all(
- prompts.map(prompt =>
- tx.aiPrompt.create({
- data: {
- name: prompt.name,
- action: prompt.action,
- model: prompt.model,
- messages: {
- create: prompt.messages.map((message, idx) => ({
- idx,
- role: message.role,
- content: message.content,
- params: message.params,
- })),
- },
- },
- })
- )
- );
- });
+ await refreshPrompts(db);
}
// revert the migration
diff --git a/packages/backend/server/src/data/migrations/1713185798895-refresh-prompt.ts b/packages/backend/server/src/data/migrations/1713185798895-refresh-prompt.ts
new file mode 100644
index 0000000000..82b3525b14
--- /dev/null
+++ b/packages/backend/server/src/data/migrations/1713185798895-refresh-prompt.ts
@@ -0,0 +1,13 @@
+import { PrismaClient } from '@prisma/client';
+
+import { refreshPrompts } from './utils/prompts';
+
+export class RefreshPrompt1713185798895 {
+ // 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 75f0365883..509c191dbd 100644
--- a/packages/backend/server/src/data/migrations/utils/prompts.ts
+++ b/packages/backend/server/src/data/migrations/utils/prompts.ts
@@ -1,4 +1,4 @@
-import { AiPromptRole } from '@prisma/client';
+import { AiPromptRole, PrismaClient } from '@prisma/client';
type PromptMessage = {
role: AiPromptRole;
@@ -40,7 +40,7 @@ export const prompts: Prompt[] = [
{
name: 'debug:action:fal-sd15',
action: 'image',
- model: '110602490-lcm-sd15-i2i',
+ model: 'lcm-sd15-i2i',
messages: [],
},
{
@@ -359,8 +359,6 @@ export const prompts: Prompt[] = [
You love your designers and want them to be happy. Incorporating their feedback and notes and producing working websites makes them happy.
When sent new wireframes, respond ONLY with the contents of the html file.
-
- {{image}}
`,
},
],
@@ -388,3 +386,39 @@ export const prompts: Prompt[] = [
],
},
];
+
+export async function refreshPrompts(db: PrismaClient) {
+ await db.$transaction(async tx => {
+ for (const prompt of prompts) {
+ await tx.aiPrompt.upsert({
+ create: {
+ name: prompt.name,
+ action: prompt.action,
+ model: prompt.model,
+ messages: {
+ create: prompt.messages.map((message, idx) => ({
+ idx,
+ role: message.role,
+ content: message.content,
+ params: message.params,
+ })),
+ },
+ },
+ where: { name: prompt.name },
+ update: {
+ action: prompt.action,
+ model: prompt.model,
+ messages: {
+ deleteMany: {},
+ create: prompt.messages.map((message, idx) => ({
+ idx,
+ role: message.role,
+ content: message.content,
+ params: message.params,
+ })),
+ },
+ },
+ });
+ }
+ });
+}