Merge branch 'develop' of https://github.com/HBAI-Ltd/Toonflow-app into develop
This commit is contained in:
commit
e1094a980e
@ -5,6 +5,9 @@ import { transform } from "sucrase";
|
|||||||
import u from "@/utils";
|
import u from "@/utils";
|
||||||
|
|
||||||
type AiType =
|
type AiType =
|
||||||
|
| "scriptAgent"
|
||||||
|
| "productionAgent"
|
||||||
|
| "universalAi"
|
||||||
| "scriptAgent:decisionAgent"
|
| "scriptAgent:decisionAgent"
|
||||||
| "scriptAgent:supervisionAgent"
|
| "scriptAgent:supervisionAgent"
|
||||||
| "scriptAgent:storySkeletonAgent"
|
| "scriptAgent:storySkeletonAgent"
|
||||||
@ -17,11 +20,14 @@ type AiType =
|
|||||||
| "productionAgent:directorPlanAgent"
|
| "productionAgent:directorPlanAgent"
|
||||||
| "productionAgent:storyboardGenAgent"
|
| "productionAgent:storyboardGenAgent"
|
||||||
| "productionAgent:storyboardPanelAgent"
|
| "productionAgent:storyboardPanelAgent"
|
||||||
| "productionAgent:storyboardTableAgent"
|
| "productionAgent:storyboardTableAgent";
|
||||||
| "universalAi";
|
|
||||||
type FnName = "textRequest" | "imageRequest" | "videoRequest" | "ttsRequest";
|
type FnName = "textRequest" | "imageRequest" | "videoRequest" | "ttsRequest";
|
||||||
|
|
||||||
const AiTypeValues: AiType[] = [
|
const AiTypeValues: AiType[] = [
|
||||||
|
"scriptAgent",
|
||||||
|
"productionAgent",
|
||||||
|
"universalAi",
|
||||||
"scriptAgent:decisionAgent",
|
"scriptAgent:decisionAgent",
|
||||||
"scriptAgent:supervisionAgent",
|
"scriptAgent:supervisionAgent",
|
||||||
"scriptAgent:storySkeletonAgent",
|
"scriptAgent:storySkeletonAgent",
|
||||||
@ -42,7 +48,7 @@ async function resolveModelName(value: AiType | `${string}:${string}`): Promise<
|
|||||||
const agentDeployData = await u.db("o_agentDeploy").where("key", value).first();
|
const agentDeployData = await u.db("o_agentDeploy").where("key", value).first();
|
||||||
let modelName = null;
|
let modelName = null;
|
||||||
if (!agentDeployData?.modelName) {
|
if (!agentDeployData?.modelName) {
|
||||||
const [mainly] = value.split(/:(.+)/);
|
const [mainly] = agentDeployData!.key!.split(/:(.+)/);
|
||||||
const mainlyData = await u.db("o_agentDeploy").where("key", mainly).first();
|
const mainlyData = await u.db("o_agentDeploy").where("key", mainly).first();
|
||||||
if (!mainlyData?.modelName) throw new Error(`未找到部署配置 ${value}`);
|
if (!mainlyData?.modelName) throw new Error(`未找到部署配置 ${value}`);
|
||||||
modelName = mainlyData.modelName;
|
modelName = mainlyData.modelName;
|
||||||
@ -54,14 +60,17 @@ async function resolveModelName(value: AiType | `${string}:${string}`): Promise<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getModelConfig(value: AiType | `${string}:${string}`) {
|
async function getModelConfig(value: AiType | `${string}:${string}`) {
|
||||||
const agentDeployData = await u.db("o_agentDeploy").where("key", value).first();
|
if (AiTypeValues.includes(value as AiType)) {
|
||||||
if (!agentDeployData?.modelName) {
|
const agentDeployData = await u.db("o_agentDeploy").where("key", value).first();
|
||||||
const [mainly] = value.split(/:(.+)/);
|
if (!agentDeployData?.modelName) {
|
||||||
const mainlyData = await u.db("o_agentDeploy").where("key", mainly).first();
|
const [mainly] = agentDeployData!.key!.split(/:(.+)/);
|
||||||
if (!mainlyData?.modelName) throw new Error(`未找到部署配置 ${value}`);
|
const mainlyData = await u.db("o_agentDeploy").where("key", mainly).first();
|
||||||
return mainlyData;
|
if (!mainlyData?.modelName) throw new Error(`未找到部署配置 ${value}`);
|
||||||
|
return mainlyData;
|
||||||
|
}
|
||||||
|
return agentDeployData;
|
||||||
}
|
}
|
||||||
return agentDeployData;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVendorTemplateFn(
|
async function getVendorTemplateFn(
|
||||||
@ -149,13 +158,14 @@ class AiText {
|
|||||||
}
|
}
|
||||||
async invoke(input: Omit<Parameters<typeof generateText>[0], "model">) {
|
async invoke(input: Omit<Parameters<typeof generateText>[0], "model">) {
|
||||||
const config = await getModelConfig(this.AiType);
|
const config = await getModelConfig(this.AiType);
|
||||||
|
console.log("%c Line:161 🥃 config", "background:#3f7cff", config);
|
||||||
|
|
||||||
return generateText({
|
return generateText({
|
||||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }),
|
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }),
|
||||||
...input,
|
...input,
|
||||||
model: await this.resolveModel(),
|
model: await this.resolveModel(),
|
||||||
...(config.temperature && { temperature: config.temperature }),
|
...(config?.temperature && { temperature: config.temperature }),
|
||||||
...(config.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }),
|
...(config?.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }),
|
||||||
} 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">) {
|
||||||
@ -165,8 +175,8 @@ class AiText {
|
|||||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }),
|
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }),
|
||||||
...input,
|
...input,
|
||||||
model: await this.resolveModel(extractReasoningMiddleware({ tagName: "reasoning_content", separator: "\n" })),
|
model: await this.resolveModel(extractReasoningMiddleware({ tagName: "reasoning_content", separator: "\n" })),
|
||||||
...(config.temperature && { temperature: config.temperature }),
|
...(config?.temperature && { temperature: config.temperature }),
|
||||||
...(config.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }),
|
...(config?.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }),
|
||||||
} as Parameters<typeof streamText>[0]);
|
} as Parameters<typeof streamText>[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user