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: refresh prompts #6568

Merged
merged 1 commit into from
Apr 16, 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
@@ -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,
})),
},
},
});
}
});
}
Loading