Skip to content

Commit

Permalink
feat: refresh prompts (#6568)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 16, 2024
1 parent b1eb0d2 commit 3d15e83
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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 RefreshPrompt1713185798895 {
// do the migration
static async up(db: PrismaClient) {
await refreshPrompts(db);
}

// revert the migration
static async down(_db: PrismaClient) {}
}
42 changes: 38 additions & 4 deletions packages/backend/server/src/data/migrations/utils/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AiPromptRole } from '@prisma/client';
import { AiPromptRole, PrismaClient } from '@prisma/client';

type PromptMessage = {
role: AiPromptRole;
Expand Down Expand Up @@ -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: [],
},
{
Expand Down Expand Up @@ -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}}
`,
},
],
Expand Down Expand Up @@ -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,
})),
},
},
});
}
});
}

0 comments on commit 3d15e83

Please sign in to comment.