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