缓解模型流式卡死导致站点偶发无响应
This commit is contained in:
parent
5361f7fc29
commit
c4ca7e4282
@ -994,6 +994,7 @@ export async function POST(request: Request) {
|
||||
// 获取语言模型实例
|
||||
let languageModel;
|
||||
let actualModelId: string;
|
||||
let resolvedModelSupportsImageGen = false;
|
||||
|
||||
if (isUUID) {
|
||||
// 从数据库获取动态配置的模型
|
||||
@ -1055,6 +1056,7 @@ export async function POST(request: Request) {
|
||||
// 对于动态模型,我们需要从数据库获取 modelId
|
||||
const finalModelData = await getAiModelById({ id: targetModelId });
|
||||
actualModelId = finalModelData?.modelId ?? targetModelId;
|
||||
resolvedModelSupportsImageGen = Boolean(finalModelData?.supportsImageGen);
|
||||
} else {
|
||||
// 使用预定义的模型
|
||||
languageModel = myProvider.languageModel(finalModelId);
|
||||
@ -2456,6 +2458,10 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
// 常规文本模型使用 streamText
|
||||
const streamRequestTimeoutMs = resolvedModelSupportsImageGen ? 180_000 : 90_000;
|
||||
const shouldDisableSmoothStream =
|
||||
resolvedModelSupportsImageGen || isVolcanoVideoModel;
|
||||
|
||||
const result = streamText({
|
||||
model: languageModel,
|
||||
system: systemPrompt({ selectedChatModel: finalModelId, requestHints }),
|
||||
@ -2463,8 +2469,11 @@ export async function POST(request: Request) {
|
||||
stopWhen: stepCountIs(5),
|
||||
experimental_activeTools:
|
||||
finalModelId === "chat-model-reasoning" || isVolcanoVideoModel ? [] : activeTools,
|
||||
experimental_transform: smoothStream({ chunking: "word" }),
|
||||
experimental_transform: shouldDisableSmoothStream
|
||||
? undefined
|
||||
: smoothStream({ chunking: "word" }),
|
||||
tools: isVolcanoVideoModel ? {} : tools, // 🆕 视频模型禁用工具
|
||||
abortSignal: AbortSignal.timeout(streamRequestTimeoutMs),
|
||||
experimental_telemetry: {
|
||||
isEnabled: isProductionEnvironment,
|
||||
functionId: "stream-text",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user