From 3d15e8353b32269e3e05e71307436cf33d8ca7ef Mon Sep 17 00:00:00 2001 From: darkskygit Date: Tue, 16 Apr 2024 10:26:53 +0000 Subject: [PATCH] feat: refresh prompts (#6568) --- .../data/migrations/1712068777394-prompts.ts | 24 +---------- .../1713185798895-refresh-prompt.ts | 13 ++++++ .../src/data/migrations/utils/prompts.ts | 42 +++++++++++++++++-- 3 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 packages/backend/server/src/data/migrations/1713185798895-refresh-prompt.ts 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, + })), + }, + }, + }); + } + }); +}