跳到正文
Vercel Blog· Bruce Liu·· 2 天前精选AI 评分75

Vercel AI Gateway 支持提取模型并首发接入 ScaleDown Extract-1

AI Gateway now supports extraction models

AI 导读

Vercel AI Gateway 宣布支持提取模型,首发上线 ScaleDown Extract-1,可从文本、图像和 PDF 中抽取指定字段并返回结构化数据。

推荐理由

原文提供了代码调用示例与置信度打分机制,开发者可以直接评估其在发票与合同结构化解析中的接入成本。

正文 · AI 翻译

AI Gateway 现已上线提取模型。这类模型能从你提供的内容中找出具体细节(如发票号码或联系人姓名),并将其作为独立字段返回,便于代码直接调用。

ScaleDown Extract-1 是首个可用的提取模型,能从文本、图片和 PDF 中提取文本值或文本列表,可用于处理发票、合同等各类单据与记录。

目前提取功能仅支持通过 AI SDK 调用。在 [email protected] 及以上版本中,调用 experimental_extract 并传入模型 ID scaledown/extract-1:

import { experimental_extract as extract } from 'ai';

const result = await extract({

model: 'scaledown/extract-1',

state: 'Invoice INV-2041 from Acme Corp. Contacts: Ana, Bo.',

fields: {

invoiceNumber: { type: 'text', instructions: 'The invoice number' },

contacts: { type: 'list', items: 'text', instructions: 'Contact names' },

},

});

console.log(result.answers.invoiceNumber.value); // 'INV-2041'

console.log(result.answers.contacts.value); // ['Ana', 'Bo']

从文本中提取发票号码和联系人姓名。

fields 中的每个键都对应 result.answers 中的一个条目。若未找到某个字段,其 value 会返回 null。Extract-1 会为匹配项(包括列表中的各个独立项)提供 0 到 1 之间的置信度评分,方便你标记存疑结果以便人工复核。对于文本输入,它还能返回字符偏移量,指示匹配项在原文中的出现位置。

若要从 PDF 或图片中提取内容,请在 state 中将其作为文件部分传入:

import { readFile } from 'node:fs/promises';

import { experimental_extract as extract } from 'ai';

const result = await extract({

model: 'scaledown/extract-1',

state: [

{

type: 'file',

data: await readFile('./invoice.pdf'),

mediaType: 'application/pdf',

},

],

fields: {

vendor: { type: 'text', instructions: 'The company that issued the invoice' },

total: { type: 'text', instructions: 'The total amount due' },

lineItems: { type: 'list', items: 'text', instructions: 'The line items' },

},

});

console.log(result.answers);

从 PDF 中提取供应商、总金额以及各项明细条目。

提取请求会显示在 AI Gateway 日志和支出跟踪中。有关配置与身份验证的方法,请参阅提取功能快速入门。

来源:Vercel Blog · vercel.com

EVAOO 主站实战落地 · AI Agent 与研发提效

看完情报?回到 EVAOO 主站直接上手工具与完整 SOP

返回 EVAOO 主站