生成事件切换提示词,添加提示词表

This commit is contained in:
小帅 2026-03-27 17:49:03 +08:00
parent d5430d257c
commit 75b73f1c2a
6 changed files with 84 additions and 11 deletions

View File

@ -184,6 +184,18 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
},
initData: async (knex) => {},
},
//提示词表
{
name: "o_prompt",
builder: (table) => {
table.integer("id").notNullable();
table.string("name");
table.text("rompt");
table.primary(["id"]);
table.unique(["id"]);
},
initData: async (knex) => {},
},
//小说原文表
{
name: "o_novel",

View File

@ -37,6 +37,7 @@ export default router.post(
const chapterAllList = await u.db("o_novel").where("projectId", projectId).whereIn("id", totalNovelId);
const novelClass = new u.cleanNovel();
novelClass.emitter.on("item", async (item) => {
console.log("%c Line:40 🍇 item", "background:#6ec1c2", item);
await u
.db("o_novel")
.where("id", item.id)

View File

@ -1,4 +1,4 @@
// @db-hash 0041ea9843a4bb46f03412c516ec323b
// @db-hash 982ecc457e8b79aea4521c60afd06753
//该文件由脚本自动生成,请勿手动修改
export interface memories {
@ -117,6 +117,11 @@ export interface o_project {
'videoModel'?: string | null;
'videoRatio'?: string | null;
}
export interface o_prompt {
'id'?: number;
'name'?: string | null;
'rompt'?: string | null;
}
export interface o_script {
'content'?: string | null;
'createTime'?: number | null;
@ -235,6 +240,7 @@ export interface DB {
"o_outline": o_outline;
"o_outlineNovel": o_outlineNovel;
"o_project": o_project;
"o_prompt": o_prompt;
"o_script": o_script;
"o_scriptAssets": o_scriptAssets;
"o_setting": o_setting;

View File

@ -8,6 +8,7 @@ import getPath from "@/utils/getPath";
import vm from "@/utils/vm";
import task from "@/utils/taskRecord";
import Ai from "@/utils/ai";
import { getPrompts } from "@/utils/getPrompts";
export default {
db,
@ -20,4 +21,5 @@ export default {
getPath,
Ai,
task,
getPrompts,
};

View File

@ -26,21 +26,17 @@ class CleanNovel {
private async processChapter(novel: o_novel, intansce: ReturnType<typeof u.Ai.Text>): Promise<EventType | null> {
try {
const skill = await useSkill("universal_agent.md");
const prompt = await u.getPrompts("event");
const resData = await intansce.invoke({
system: skill.prompt,
system: prompt,
messages: [
{
role: "user",
content: "请根据以下小说章节生成事件摘要:\n" + novel.chapterData!,
},
],
tools: skill.tools,
});
const preData = resData.text;
this.emitter.emit("item", { id: novel.id, event: preData });
return { id: novel.id!, event: preData };
} catch (e) {
@ -71,10 +67,7 @@ class CleanNovel {
};
// 启动最多 concurrency 个并发任务
const workers = Array.from(
{ length: Math.min(this.concurrency, allChapters.length) },
() => runNext()
);
const workers = Array.from({ length: Math.min(this.concurrency, allChapters.length) }, () => runNext());
await Promise.all(workers);

59
src/utils/getPrompts.ts Normal file
View File

@ -0,0 +1,59 @@
export async function getPrompts(type: string) {
if (type == "event") {
return `
#
##
1. **** \`|\` 开头、以 \`|\` 结尾,恰好 7 个字段
2. **** \`|\`**最后一个字符**必须是 \`|\`
3. \`|\` 之前不许有任何字符——没有引导语、没有解释、没有"根据……"、没有"以下是……"
4. \`|\` 之后不许有任何字符——没有总结、没有提取说明、没有改编建议
5. 线Markdown emoji
##
\`\`\`
| X章 {} | {} | {} | {线} | {} | {} | {} |
\`\`\`
###
| | | |
|------|----------|------|
| | \`第X章 {章节标题}\` | \`第1章 职业危机与许愿\` |
| | | \`林逸、白有容\` |
| | 30-60+ | \`林逸因解密风潮事业崩塌,颓废中许愿触发魔法系统绑定\` |
| 线 | **** \`强/中/弱3-8字理由\` | \`强(动机建立+系统激活)\` |
| | \`\` / \`\` / \`\` | \`\` |
| | **** \`X秒\`,禁止用分钟 | \`50秒\` |
| | \`+\` 连接,禁止星级/数字 | \`转折+悬疑\` |
**线**线///
****+45-6035-4525-35
****\`冲突\`\`恐怖\`\`情感\`\`转折\`\`高潮\`\`平铺\`\`喜剧\`\`悬疑\`\`情感崩溃\`
##
****
\`\`\`
| 1 | | "如果会魔法就好了" | + | | 50 | + |
\`\`\`
\`\`\`
| 12 | | | | | 25 | + |
\`\`\`
##
-
- 使
- 线
-
`;
}
}