2026-04-13 03:34:25 +08:00

163 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import express from "express";
import { success, error } from "@/lib/responseFormat";
import u from "@/utils";
import { z } from "zod";
import { validateFields } from "@/middleware/middleware";
const router = express.Router();
export default router.post(
"/",
validateFields({
key: z.string().optional(),
}),
async (req, res) => {
const { key } = req.body;
const vendorConfigData = await u.db("o_vendorConfig").where("id", "toonflow").first();
if (!vendorConfigData) return res.status(500).send(error("未找到该供应商配置"));
if (!vendorConfigData.inputValues) return res.status(500).send(error("未找到模型配置数据"));
const inputValue = JSON.parse(vendorConfigData.inputValues!);
inputValue.apiKey = key;
await u
.db("o_vendorConfig")
.where("id", "toonflow")
.update({
inputValues: JSON.stringify(inputValue),
});
try {
const resText = await u.Ai.Text(`toonflow:claude-haiku-4-5-20251001`).invoke({
prompt: "1+1等于几,请直接回答2不要解释",
});
if (resText.text) {
await u.db("o_agentDeploy").where("key", "scriptAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
});
await u.db("o_agentDeploy").where("key", "productionAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
});
await u.db("o_agentDeploy").where("key", "universalAi").update({
model: "claude-haiku-4-5",
modelName: "toonflow:claude-haiku-4-5-20251001",
vendorId: "toonflow",
});
await u.db("o_agentDeploy").where("key", "scriptAgent:decisionAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "scriptAgent:supervisionAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "scriptAgent:storySkeletonAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "scriptAgent:adaptationStrategyAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "scriptAgent:scriptAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:decisionAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:supervisionAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:deriveAssetsAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:generateAssetsAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:directorPlanAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:storyboardGenAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:storyboardPanelAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
await u.db("o_agentDeploy").where("key", "productionAgent:storyboardTableAgent").update({
model: "claude-sonnet-4-6",
modelName: "toonflow:claude-sonnet-4-6",
vendorId: "toonflow",
topP: 1,
temperature: 1,
maxOutputTokens: 8192,
});
res.status(200).send(success("一键填入成功"));
}
} catch (err) {
console.error(err);
inputValue.apiKey = "";
await u
.db("o_vendorConfig")
.where("id", "toonflow")
.update({ inputValues: JSON.stringify(inputValue) });
res.status(400).send(error("KEY无效请重新输入"));
}
},
);