8.0
热点
AI SCORE
编程提效2026-10-07 01:19
Vercel AI Gateway 新增置信度触发降级策略
Vercel Blog#Vercel#AI Gateway#可靠性
Editor brief · 编辑速览
AI Gateway 支持设置置信度条件,当主模型答案低于阈值时自动切换到备用模型,支持组合条件判断,按选择题和评分题分别处理。
AI Gateway 现在可以在主模型的回答触发你设定的置信度条件时,将决策请求升级到备选模型。
条件可以组合,因此升级可以依赖多个信号。你已在 models 中列出的普通模型名称仍然会捕获明显的错误,因此现有的备选行为不受影响。置信度条件覆盖 Choice 和 Score 问题。Boolean 问题则根据概率范围进行升级。
通过在 providerOptions.gateway.models 中添加一个条件对象来设置备选模型。没有该配置时,请求保持现有行为。
1import { gateway } from '@ai-sdk/gateway';
2import { experimental_decide as decide } from 'ai';
3
4const result = await decide({
5 model: gateway.decisionModel('typesafe-ai/jev'),
6 state: 'I was charged twice and now the app will not load.',
7 questions: {
8 intent: {
9 type: 'choice',
10 instructions: 'Which team should handle this?',
11 criteria: { billing: 'Charges and refunds', technical: 'Bugs and outages' },
12 },
13 },
14 providerOptions: {
15 gateway: {
16 models: [{ model: 'openai/gpt-6-astra', when: { question: 'intent', confidenceBelow: 0.6 } }],
17 },
18 },
19});
20
21console.log(result.answers.intent.choice);
用置信度条件将不确定的答案升级到备选模型
省略 question 时,条件会检查所有匹配类型的问题,因此 { confidenceBelow: 0.6 } 会在任何 Choice 或 Score 回答低于 0.6 时触发升级。
因为触发的备选运行的是第二次决策,两个阶段都会计费。
Decision fallbacks 目前处于 beta 阶段。了解更多请参阅 decision fallbacks 文档。