Liquid AI 的 d1.2 和 d1.2-ultra 现已在 AI Gateway 上线,支持音频输入和边界框。
这些决策模型返回结构化答案,而不是生成文本。可以提出 Boolean 问题以获得是/否概率,提出 Choice 问题以选择一个类别,或提出 Score 问题以根据评分标准对输入打分。一次请求中多个问题可以共享同一份输入。
d1.2 是速度更快、成本更低的模型。d1.2-ultra 是 Liquid AI 最准确的决策模型。
使用 liquid/d1.2 或 liquid/d1.2-ultra 作为模型名称。运行示例之前,请将 AI_GATEWAY_API_KEY 设置为 AI Gateway API 密钥。
Copy link to headingClassify a voicemail with AI SDK 7
以文件 part 的形式将音频传入 state。此示例读取 voicemail.flac,并返回来电者要求退款的概率。它需要 ai 7.0.136 或更高版本。
import { readFile } from 'node:fs/promises';import { experimental_decide as decide } from 'ai';
const { answers } = await decide({ model: 'liquid/d1.2-ultra', state: [ { type: 'file', mediaType: 'audio/flac', data: await readFile('voicemail.flac') }, ], questions: { refund: { type: 'boolean', instructions: 'Is the caller asking for a refund?' }, },});
console.log(answers.refund.probability);
对于图像分类,请传入图像字节及匹配的媒体类型,例如 image/png。
Copy link to headingLocate an object with the Decisions API
Box 问题将 top 和 bottom 返回为图像高度的比例,将 left 和 right 返回为图像宽度的比例。
此 Python 示例使用 Decisions API 在 form.png 中定位签名,并打印其边界框:
import base64import jsonimport osfrom pathlib import Pathfrom urllib.request import Request, urlopen
image = base64.b64encode(Path("label.png").read_bytes()).decode("ascii")body = { "model": "liquid/d1.2-ultra", "input": [{"role": "user", "content": [ {"type": "input_image", "image_url": f"data:image/png;base64,{image}"}, ]}], "questions": [{"type": "box", "name": "label", "instructions": "Locate the red rectangle."}],}request = Request( "https://ai-gateway.vercel.sh/v1/decisions", data=json.dumps(body).encode(), headers={ "Authorization": f"Bearer {os.environ['AI_GATEWAY_API_KEY']}", "Content-Type": "application/json", },)with urlopen(request, timeout=30) as response: answer = json.load(response)["answers"][0]print(answer.get("box"))
决策请求会出现在 AI Gateway 日志中,并计入预算。
在决策模型文档中了解更多信息,或浏览所有决策模型。