添加任务数据
This commit is contained in:
parent
55abe18db0
commit
6a74cf168c
@ -90,7 +90,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
||||
modelName: "",
|
||||
vendorId: null,
|
||||
key: "assetsAi",
|
||||
name: "资产AI",
|
||||
name: "资产Agent",
|
||||
desc: "根据角色和场景要素,生成精准的素材提示词",
|
||||
disabled: false,
|
||||
},
|
||||
@ -99,7 +99,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
||||
modelName: "",
|
||||
vendorId: null,
|
||||
key: "polishingAi",
|
||||
name: "润色AI",
|
||||
name: "润色Agent",
|
||||
desc: "将大纲扩展为完整剧本脚本,包含对话和场景描写",
|
||||
disabled: false,
|
||||
},
|
||||
@ -108,7 +108,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
||||
modelName: "",
|
||||
vendorId: null,
|
||||
key: "eventExtractAi",
|
||||
name: "事件提取AI",
|
||||
name: "事件提取Agent",
|
||||
desc: "从小说原文中提取事件,生成事件列表和事件关系",
|
||||
disabled: false,
|
||||
},
|
||||
|
||||
@ -87,18 +87,38 @@ export default router.post(
|
||||
try {
|
||||
let imagePath;
|
||||
let insertType;
|
||||
let describe;
|
||||
let relatedObjects = {};
|
||||
|
||||
if (type == "role") {
|
||||
insertType = "role";
|
||||
imagePath = `/${projectId}/role/${uuidv4()}.jpg`;
|
||||
describe = `生成角色图,名称:${name},提示词:${prompt}`;
|
||||
relatedObjects = {
|
||||
id: id,
|
||||
projectId,
|
||||
type: "角色",
|
||||
};
|
||||
}
|
||||
if (type == "scene") {
|
||||
insertType = "scene";
|
||||
imagePath = `/${projectId}/scene/${uuidv4()}.jpg`;
|
||||
describe = `生成场景图,名称:${name},提示词:${prompt}`;
|
||||
relatedObjects = {
|
||||
id: id,
|
||||
projectId,
|
||||
type: "场景",
|
||||
};
|
||||
}
|
||||
if (type == "tool") {
|
||||
insertType = "tool";
|
||||
imagePath = `/${projectId}/props/${uuidv4()}.jpg`;
|
||||
describe = `生成道具图,名称:${name},提示词:${prompt}`;
|
||||
relatedObjects = {
|
||||
id: id,
|
||||
projectId,
|
||||
type: "道具",
|
||||
};
|
||||
}
|
||||
|
||||
const aiImage = u.Ai.Image(model);
|
||||
@ -108,6 +128,10 @@ export default router.post(
|
||||
imageBase64: base64 ? [base64] : [],
|
||||
size: resolution,
|
||||
aspectRatio: "16:9",
|
||||
taskClass,
|
||||
describe: describe ?? "", // 描述
|
||||
projectId,
|
||||
relatedObjects: JSON.stringify(relatedObjects), // 相关对象信息,便于后续分析和追踪
|
||||
});
|
||||
aiImage.save(imagePath!);
|
||||
const imageData = await u.db("o_image").where("id", imageId).select("*").first();
|
||||
|
||||
74
src/types/database.d.ts
vendored
74
src/types/database.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// @db-hash feca77a2c2ec5b6a2989347f982558d5
|
||||
// @db-hash 04e1150a9773602183de5f660a52b092
|
||||
//该文件由脚本自动生成,请勿手动修改
|
||||
|
||||
export interface memories {
|
||||
@ -35,18 +35,12 @@ export interface o_assets {
|
||||
'projectId'?: number | null;
|
||||
'prompt'?: string | null;
|
||||
'remark'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sonId'?: number | null;
|
||||
'startTime'?: number | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_chatHistory {
|
||||
'data'?: string | null;
|
||||
'id'?: number;
|
||||
'novel'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_event {
|
||||
'createTime'?: number | null;
|
||||
'detail'?: string | null;
|
||||
@ -67,33 +61,10 @@ export interface o_image {
|
||||
'assetsId'?: number | null;
|
||||
'filePath'?: string | null;
|
||||
'id'?: number;
|
||||
'projectId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
'model'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
'videoId'?: number | null;
|
||||
}
|
||||
export interface o_model {
|
||||
'apiKey'?: string | null;
|
||||
'baseUrl'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'id'?: number;
|
||||
'index'?: number | null;
|
||||
'manufacturer'?: string | null;
|
||||
'model'?: string | null;
|
||||
'modelType'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_myTasks {
|
||||
'describe'?: string | null;
|
||||
'id'?: number;
|
||||
'model'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'reason'?: string | null;
|
||||
'relatedObjects'?: string | null;
|
||||
'startTime'?: number | null;
|
||||
'state'?: string | null;
|
||||
'taskClass'?: string | null;
|
||||
}
|
||||
export interface o_novel {
|
||||
'chapter'?: string | null;
|
||||
@ -126,15 +97,6 @@ export interface o_project {
|
||||
'userId'?: number | null;
|
||||
'videoRatio'?: string | null;
|
||||
}
|
||||
export interface o_prompts {
|
||||
'code'?: string | null;
|
||||
'customValue'?: string | null;
|
||||
'defaultValue'?: string | null;
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'parentCode'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_script {
|
||||
'content'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
@ -142,35 +104,15 @@ export interface o_script {
|
||||
'name'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
}
|
||||
export interface o_scriptAssets {
|
||||
'assetsId'?: number | null;
|
||||
'id'?: number;
|
||||
'scriptId'?: number | null;
|
||||
}
|
||||
export interface o_scriptOutline {
|
||||
'id'?: number;
|
||||
'outlineId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
}
|
||||
export interface o_setting {
|
||||
'key'?: string | null;
|
||||
'value'?: string | null;
|
||||
}
|
||||
export interface o_skills {
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'startTime'?: number | null;
|
||||
}
|
||||
export interface o_storyboard {
|
||||
'createTime'?: number | null;
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
}
|
||||
export interface o_storyboardScript {
|
||||
'id'?: number;
|
||||
'scriptId'?: number | null;
|
||||
'storyboardId'?: number | null;
|
||||
}
|
||||
export interface o_tasks {
|
||||
'describe'?: string | null;
|
||||
'id'?: number;
|
||||
@ -236,25 +178,17 @@ export interface DB {
|
||||
"o_agentDeploy": o_agentDeploy;
|
||||
"o_artStyle": o_artStyle;
|
||||
"o_assets": o_assets;
|
||||
"o_chatHistory": o_chatHistory;
|
||||
"o_event": o_event;
|
||||
"o_eventChapter": o_eventChapter;
|
||||
"o_flowData": o_flowData;
|
||||
"o_image": o_image;
|
||||
"o_model": o_model;
|
||||
"o_myTasks": o_myTasks;
|
||||
"o_novel": o_novel;
|
||||
"o_outline": o_outline;
|
||||
"o_outlineNovel": o_outlineNovel;
|
||||
"o_project": o_project;
|
||||
"o_prompts": o_prompts;
|
||||
"o_script": o_script;
|
||||
"o_scriptAssets": o_scriptAssets;
|
||||
"o_scriptOutline": o_scriptOutline;
|
||||
"o_setting": o_setting;
|
||||
"o_skills": o_skills;
|
||||
"o_storyboard": o_storyboard;
|
||||
"o_storyboardScript": o_storyboardScript;
|
||||
"o_tasks": o_tasks;
|
||||
"o_user": o_user;
|
||||
"o_vendorConfig": o_vendorConfig;
|
||||
|
||||
@ -34,10 +34,14 @@ async function getVendorTemplateFn(fnName: FnName, modelName: `${number}:${strin
|
||||
async function withTaskRecord<T>(
|
||||
modelKey: AiType | `${number}:${string}`,
|
||||
taskClass: string,
|
||||
describe: string,
|
||||
relatedObjects: string,
|
||||
projectId: number,
|
||||
fn: (modelName: `${number}:${string}`) => Promise<T>,
|
||||
): Promise<T> {
|
||||
const modelName = await resolveModelName(modelKey);
|
||||
const taskRecord = await u.task(1, taskClass, modelName, { describe: "", content: "" });
|
||||
const [id, model] = modelName.split(":");
|
||||
const taskRecord = await u.task(projectId, taskClass, model, { describe: describe, content: relatedObjects });
|
||||
try {
|
||||
const result = await fn(modelName);
|
||||
taskRecord(1);
|
||||
@ -60,22 +64,20 @@ class AiText {
|
||||
this.AiType = AiType;
|
||||
}
|
||||
async invoke(input: Omit<Parameters<typeof generateText>[0], "model">) {
|
||||
return withTaskRecord(this.AiType, "TaskClass", async (modelName) =>
|
||||
generateText({
|
||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 5) }),
|
||||
...input,
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
} as Parameters<typeof generateText>[0]),
|
||||
);
|
||||
const modelName = await resolveModelName(this.AiType);
|
||||
return generateText({
|
||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 5) }),
|
||||
...input,
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
} as Parameters<typeof generateText>[0]);
|
||||
}
|
||||
async stream(input: Omit<Parameters<typeof streamText>[0], "model">) {
|
||||
return withTaskRecord(this.AiType, "TaskClass", async (modelName) =>
|
||||
streamText({
|
||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 5) }),
|
||||
...input,
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
} as Parameters<typeof streamText>[0]),
|
||||
);
|
||||
const modelName = await resolveModelName(this.AiType);
|
||||
return streamText({
|
||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 5) }),
|
||||
...input,
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
} as Parameters<typeof streamText>[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +87,10 @@ interface ImageConfig {
|
||||
imageBase64: string[]; //输入的图片提示词
|
||||
size: "1K" | "2K" | "4K"; // 图片尺寸
|
||||
aspectRatio: `${number}:${number}`; // 长宽比
|
||||
taskClass: string; // 任务分类
|
||||
describe: string; // 任务描述
|
||||
relatedObjects: string; // 相关对象信息,便于后续分析和追踪
|
||||
projectId: number; // 项目ID
|
||||
}
|
||||
|
||||
class AiImage {
|
||||
@ -94,7 +100,7 @@ class AiImage {
|
||||
this.key = key;
|
||||
}
|
||||
async run(input: ImageConfig) {
|
||||
return withTaskRecord(this.key, "TaskClass", async (modelName) => {
|
||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
||||
const fn = await getVendorTemplateFn("imageRequest", modelName);
|
||||
this.result = await fn(input);
|
||||
if (this.result.startsWith("http")) this.result = await urlToBase64(this.result);
|
||||
@ -113,7 +119,7 @@ class AiVideo {
|
||||
this.key = key;
|
||||
}
|
||||
async run(input: ImageConfig) {
|
||||
return withTaskRecord(this.key, "TaskClass", async (modelName) => {
|
||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
||||
const fn = await getVendorTemplateFn("videoRequest", modelName);
|
||||
this.result = await fn(input);
|
||||
if (this.result.startsWith("http")) this.result = await urlToBase64(this.result);
|
||||
@ -132,7 +138,7 @@ class AiAudio {
|
||||
this.key = key;
|
||||
}
|
||||
async run(input: ImageConfig) {
|
||||
return withTaskRecord(this.key, "TaskClass", async (modelName) => {
|
||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
||||
const fn = await getVendorTemplateFn("ttsRequest", modelName);
|
||||
this.result = await fn(input);
|
||||
if (this.result.startsWith("http")) this.result = await urlToBase64(this.result);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user