From 961344ce03527a9a8e9abbb491bfe52b2428fc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ACT=E4=B8=B6=E6=B5=81=E6=98=9F=E9=9B=A8?= <1340145680@qq.com> Date: Mon, 13 Apr 2026 04:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B8=A9=E5=BA=A6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ai.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/utils/ai.ts b/src/utils/ai.ts index f29c7eb..ed28d6e 100644 --- a/src/utils/ai.ts +++ b/src/utils/ai.ts @@ -53,6 +53,17 @@ async function resolveModelName(value: AiType | `${string}:${string}`): Promise< return value as `${number}:${string}`; } +async function getModelConfig(value: AiType | `${string}:${string}`) { + const agentDeployData = await u.db("o_agentDeploy").where("key", value).first(); + if (!agentDeployData?.modelName) { + const [mainly] = value.split(/:(.+)/); + const mainlyData = await u.db("o_agentDeploy").where("key", mainly).first(); + if (!mainlyData?.modelName) throw new Error(`未找到部署配置 ${value}`); + return mainlyData; + } + return agentDeployData; +} + async function getVendorTemplateFn( fnName: "textRequest", modelName: `${string}:${string}`, @@ -137,21 +148,25 @@ class AiText { return mws.length > 0 ? wrapLanguageModel({ model: baseModel, middleware: mws.length === 1 ? mws[0] : mws }) : baseModel; } async invoke(input: Omit[0], "model">) { + const config = await getModelConfig(this.AiType); + return generateText({ ...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }), ...input, model: await this.resolveModel(), - temperature: 1, - maxOutputTokens: 8129, + ...(config.temperature && { temperature: config.temperature }), + ...(config.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }), } as Parameters[0]); } async stream(input: Omit[0], "model">) { + const config = await getModelConfig(this.AiType); + return streamText({ ...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 50) }), ...input, model: await this.resolveModel(extractReasoningMiddleware({ tagName: "reasoning_content", separator: "\n" })), - temperature: 1, - maxOutputTokens: 8129, + ...(config.temperature && { temperature: config.temperature }), + ...(config.maxOutputTokens && { maxOutputTokens: config.maxOutputTokens }), } as Parameters[0]); } }