mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
feat: refresh prompts (#6568)
This commit is contained in:
@@ -1,31 +1,11 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
import { prompts } from './utils/prompts';
|
import { refreshPrompts } from './utils/prompts';
|
||||||
|
|
||||||
export class Prompts1712068777394 {
|
export class Prompts1712068777394 {
|
||||||
// do the migration
|
// do the migration
|
||||||
static async up(db: PrismaClient) {
|
static async up(db: PrismaClient) {
|
||||||
await db.$transaction(async tx => {
|
await refreshPrompts(db);
|
||||||
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,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// revert the migration
|
// revert the migration
|
||||||
|
|||||||
@@ -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) {}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AiPromptRole } from '@prisma/client';
|
import { AiPromptRole, PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
type PromptMessage = {
|
type PromptMessage = {
|
||||||
role: AiPromptRole;
|
role: AiPromptRole;
|
||||||
@@ -40,7 +40,7 @@ export const prompts: Prompt[] = [
|
|||||||
{
|
{
|
||||||
name: 'debug:action:fal-sd15',
|
name: 'debug:action:fal-sd15',
|
||||||
action: 'image',
|
action: 'image',
|
||||||
model: '110602490-lcm-sd15-i2i',
|
model: 'lcm-sd15-i2i',
|
||||||
messages: [],
|
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.
|
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.
|
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,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user