ai生成任务字段单独拿出来
This commit is contained in:
parent
0fe8001d2f
commit
3998d441d4
@ -263,8 +263,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
{
|
{
|
||||||
name: "剧本资产提取",
|
name: "剧本资产提取",
|
||||||
type: "scriptAssetExtraction",
|
type: "scriptAssetExtraction",
|
||||||
data: `
|
data: `---
|
||||||
---
|
|
||||||
name: universal_agent
|
name: universal_agent
|
||||||
description: 专注于从剧本内容中提取所使用的资产(角色、场景、道具)并生成结构化资产列表的助手。
|
description: 专注于从剧本内容中提取所使用的资产(角色、场景、道具)并生成结构化资产列表的助手。
|
||||||
---
|
---
|
||||||
|
|||||||
@ -110,16 +110,20 @@ export default router.post("/", validateFields(requestSchema), async (req, res)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const aiImage = u.Ai.Image(model);
|
const aiImage = u.Ai.Image(model);
|
||||||
await aiImage.run({
|
await aiImage.run(
|
||||||
|
{
|
||||||
prompt: userPrompt,
|
prompt: userPrompt,
|
||||||
imageBase64: item.base64 ? [item.base64] : [],
|
imageBase64: item.base64 ? [item.base64] : [],
|
||||||
size: resolution,
|
size: resolution,
|
||||||
aspectRatio: "16:9",
|
aspectRatio: "16:9",
|
||||||
|
},
|
||||||
|
{
|
||||||
taskClass: cfg.taskClass,
|
taskClass: cfg.taskClass,
|
||||||
describe,
|
describe,
|
||||||
projectId,
|
projectId,
|
||||||
relatedObjects: JSON.stringify(relatedObjects),
|
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();
|
||||||
|
|||||||
@ -98,16 +98,20 @@ export default router.post("/", validateFields(requestSchema), async (req, res)
|
|||||||
try {
|
try {
|
||||||
// 4. 调用 AI 生成图片
|
// 4. 调用 AI 生成图片
|
||||||
const aiImage = u.Ai.Image(model);
|
const aiImage = u.Ai.Image(model);
|
||||||
await aiImage.run({
|
await aiImage.run(
|
||||||
|
{
|
||||||
prompt: userPrompt,
|
prompt: userPrompt,
|
||||||
imageBase64: base64 ? [base64] : [],
|
imageBase64: base64 ? [base64] : [],
|
||||||
size: resolution,
|
size: resolution,
|
||||||
aspectRatio: "16:9",
|
aspectRatio: "16:9",
|
||||||
|
},
|
||||||
|
{
|
||||||
taskClass: cfg.taskClass,
|
taskClass: cfg.taskClass,
|
||||||
describe,
|
describe,
|
||||||
projectId,
|
projectId,
|
||||||
relatedObjects: JSON.stringify(relatedObjects),
|
relatedObjects: JSON.stringify(relatedObjects),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
aiImage.save(imagePath);
|
aiImage.save(imagePath);
|
||||||
|
|
||||||
// 5. 更新记录 & 返回结果
|
// 5. 更新记录 & 返回结果
|
||||||
|
|||||||
@ -105,8 +105,8 @@ export default router.post(
|
|||||||
console.log("%c Line:110 🍑 prompt", "background:#b03734", prompt);
|
console.log("%c Line:110 🍑 prompt", "background:#b03734", prompt);
|
||||||
|
|
||||||
const aiVideo = u.Ai.Video(model);
|
const aiVideo = u.Ai.Video(model);
|
||||||
await aiVideo.run({
|
await aiVideo.run(
|
||||||
projectId,
|
{
|
||||||
prompt,
|
prompt,
|
||||||
imageBase64: base64.filter((item) => item !== null) as string[],
|
imageBase64: base64.filter((item) => item !== null) as string[],
|
||||||
mode,
|
mode,
|
||||||
@ -114,10 +114,14 @@ export default router.post(
|
|||||||
aspectRatio: (ratio?.videoRatio as `${number}:${number}`) || "16:9",
|
aspectRatio: (ratio?.videoRatio as `${number}:${number}`) || "16:9",
|
||||||
resolution,
|
resolution,
|
||||||
audio,
|
audio,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
projectId,
|
||||||
taskClass: "视频生成",
|
taskClass: "视频生成",
|
||||||
describe: "根据提示词生成视频",
|
describe: "根据提示词生成视频",
|
||||||
relatedObjects: JSON.stringify(relatedObjects),
|
relatedObjects: JSON.stringify(relatedObjects),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
await aiVideo.save(videoPath);
|
await aiVideo.save(videoPath);
|
||||||
await u.db("o_video").where("id", videoId).update({ state: "生成成功" });
|
await u.db("o_video").where("id", videoId).update({ state: "生成成功" });
|
||||||
// await u.db("o_videoConfig").where("storyboardId", storyboardId).update({ videoId, updateTime: Date.now() });
|
// await u.db("o_videoConfig").where("storyboardId", storyboardId).update({ videoId, updateTime: Date.now() });
|
||||||
|
|||||||
5
src/types/database.d.ts
vendored
5
src/types/database.d.ts
vendored
@ -1,8 +1,4 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
// @db-hash 93b2462070c45c2b449e9a18c4e88763
|
|
||||||
=======
|
|
||||||
// @db-hash 24748d4ef971381a79c720c846f83847
|
// @db-hash 24748d4ef971381a79c720c846f83847
|
||||||
>>>>>>> 796947cef173e7fe2f96e21fa8aeae23ff0fdf4a
|
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
export interface memories {
|
export interface memories {
|
||||||
@ -182,6 +178,7 @@ export interface o_storyboard {
|
|||||||
'sound'?: string | null;
|
'sound'?: string | null;
|
||||||
'state'?: string | null;
|
'state'?: string | null;
|
||||||
'title'?: string | null;
|
'title'?: string | null;
|
||||||
|
'videoPrompt'?: string | null;
|
||||||
}
|
}
|
||||||
export interface o_tasks {
|
export interface o_tasks {
|
||||||
'describe'?: string | null;
|
'describe'?: string | null;
|
||||||
|
|||||||
@ -25,23 +25,10 @@ async function getVendorTemplateFn(fnName: FnName, modelName: `${string}:${strin
|
|||||||
const selectedModel = modelList.find((i: any) => i.modelName == name);
|
const selectedModel = modelList.find((i: any) => i.modelName == name);
|
||||||
if (!selectedModel) throw new Error(`未找到模型 ${name} id=${id}`);
|
if (!selectedModel) throw new Error(`未找到模型 ${name} id=${id}`);
|
||||||
const jsCode = transform(vendorConfigData.code!, { transforms: ["typescript"] }).code;
|
const jsCode = transform(vendorConfigData.code!, { transforms: ["typescript"] }).code;
|
||||||
const running = u.vm(jsCode);
|
const fn = u.vm(jsCode)[fnName];
|
||||||
Object.assign(running.vendor.inputValues, JSON.parse(vendorConfigData.inputValues ?? "{}"));
|
|
||||||
running.vendor.models = modelList;
|
|
||||||
const fn = running[fnName];
|
|
||||||
if (!fn) throw new Error(`未找到供应商配置中的函数 ${fnName} id=${id}`);
|
if (!fn) throw new Error(`未找到供应商配置中的函数 ${fnName} id=${id}`);
|
||||||
if (fnName == "textRequest") {
|
if (fnName == "textRequest") return fn(selectedModel);
|
||||||
const model = fn(selectedModel);
|
else return <T>(input: T) => fn(input, selectedModel);
|
||||||
if (!model) throw new Error(`供应商 textRequest 返回无效模型 id=${id}`);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
return async <T>(input: T) => {
|
|
||||||
const result = await fn(input, selectedModel);
|
|
||||||
if (result === undefined || result === null) {
|
|
||||||
throw new Error(`供应商函数 ${fnName} 未返回有效结果 id=${id}`);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withTaskRecord<T>(
|
async function withTaskRecord<T>(
|
||||||
@ -113,6 +100,9 @@ interface ImageConfig {
|
|||||||
imageBase64: string[]; //输入的图片提示词
|
imageBase64: string[]; //输入的图片提示词
|
||||||
size: "1K" | "2K" | "4K"; // 图片尺寸
|
size: "1K" | "2K" | "4K"; // 图片尺寸
|
||||||
aspectRatio: `${number}:${number}`; // 长宽比
|
aspectRatio: `${number}:${number}`; // 长宽比
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TaskRecord {
|
||||||
taskClass: string; // 任务分类
|
taskClass: string; // 任务分类
|
||||||
describe: string; // 任务描述
|
describe: string; // 任务描述
|
||||||
relatedObjects: string; // 相关对象信息,便于后续分析和追踪
|
relatedObjects: string; // 相关对象信息,便于后续分析和追踪
|
||||||
@ -125,8 +115,8 @@ class AiImage {
|
|||||||
constructor(key: `${string}:${string}`) {
|
constructor(key: `${string}:${string}`) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
async run(input: ImageConfig) {
|
async run(input: ImageConfig, taskRecord: TaskRecord) {
|
||||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
return withTaskRecord(this.key, taskRecord.taskClass, taskRecord.describe, taskRecord.relatedObjects, taskRecord.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);
|
||||||
@ -139,7 +129,6 @@ class AiImage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
interface VideoConfig {
|
interface VideoConfig {
|
||||||
projectId: number; // 项目ID
|
|
||||||
prompt: string; //视频提示词
|
prompt: string; //视频提示词
|
||||||
imageBase64: string[]; //输入的图片提示词
|
imageBase64: string[]; //输入的图片提示词
|
||||||
aspectRatio: `${number}:${number}`; // 长宽比
|
aspectRatio: `${number}:${number}`; // 长宽比
|
||||||
@ -147,9 +136,6 @@ interface VideoConfig {
|
|||||||
duration: number; // 视频时长,单位秒
|
duration: number; // 视频时长,单位秒
|
||||||
resolution: string; // 视频分辨率
|
resolution: string; // 视频分辨率
|
||||||
audio: boolean; // 是否需要配音
|
audio: boolean; // 是否需要配音
|
||||||
taskClass: string; // 任务分类
|
|
||||||
describe: string; // 任务描述
|
|
||||||
relatedObjects: string; // 相关对象信息,便于后续分析和追踪
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AiVideo {
|
class AiVideo {
|
||||||
@ -158,8 +144,8 @@ class AiVideo {
|
|||||||
constructor(key: `${string}:${string}`) {
|
constructor(key: `${string}:${string}`) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
async run(input: VideoConfig) {
|
async run(input: VideoConfig, taskRecord: TaskRecord) {
|
||||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
return withTaskRecord(this.key, taskRecord.taskClass, taskRecord.describe, taskRecord.relatedObjects, taskRecord.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);
|
||||||
@ -177,8 +163,8 @@ class AiAudio {
|
|||||||
constructor(key: `${string}:${string}`) {
|
constructor(key: `${string}:${string}`) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
async run(input: VideoConfig) {
|
async run(input: VideoConfig, taskRecord: TaskRecord) {
|
||||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
return withTaskRecord(this.key, taskRecord.taskClass, taskRecord.describe, taskRecord.relatedObjects, taskRecord.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