设计内置 AI Web API

For the last year, I’ve been working as part of the Chrome built-in AI team on a set of APIs to bring various AI models to the web browser. As with all APIs we ship, our goal is to make these APIs compelling enough that other browsers adopt them, and they become part of the web’s standard library.

过去一年,我作为 Chrome 内置 AI 团队的一员,参与了 一组 API 的设计,旨在将各种 AI 模型引入网页浏览器。与我们发布的所有 API 一样,我们的目标是让这些 API 足够有吸引力,以便其他浏览器采纳,并成为 Web 标准库的一部分。

Working in such a fast-moving space brings tension with the usual process for building web APIs. When exposing other platform capabilities like USB, payments, or codecs, we can draw on years or decades of work in native platforms. But with built-in AI APIs, especially for language model-backed APIs like the prompt API, our precedent is barely two years old. Moreover, there are interesting differences between HTTP APIs and client-side APIs, and between vendor-specific APIs and those designed for a wide range of possible future implementations.

在这样一个快速发展的领域工作,与构建 Web API 的常规流程之间存在张力。当暴露 USB、支付或编解码器等其他平台能力时,我们可以借鉴原生平台多年甚至数十年的工作。但对于内置 AI API,尤其是像 prompt API 这样由语言模型支持的 API,我们的先例仅有 两年历史。此外,HTTP API 与客户端 API 之间,以及特定供应商 API 与为未来多种实现设计的 API 之间,也存在有趣的差异。

In what follows, I’ll focus mostly on the design of the prompt API, as it has the most complex API surface. But I’ll also touch on higher-level “task-based” APIs like summarizer, translator, and language detector.

接下来,我将主要聚焦于 prompt API 的设计,因为它拥有最复杂的 API 表面。但我也会简要提及更高层级的“基于任务”的 API,如summarizertranslator 和 language detector

Starting from precedent

从先例出发

The starting place for API design is the core loop: apart from any initialization or state management, when a developer wants to prompt a language model, what does the code for that look like? Even with only two years’ experience with language model prompting, the ecosystem has mostly converged on a shape here.

API 设计的起点是核心循环:抛开任何初始化或状态管理,当开发者想要提示语言模型时,这段代码长什么样?即便只有两年的语言模型提示经验,整个生态系统也已基本在这一形态上达成了共识。

The consensus shape is that a language model prompt consists of a series of messages, with one of three roles:...

开通本站会员,查看完整译文。

Home - Wiki
Copyright © 2011-2025 iteam. Current version is 2.146.0. UTC+08:00, 2025-08-29 03:54
浙ICP备14020137号-1 $Map of visitor$