Featured image of post Google I/O 2025:集成网络技术和人工智能Featured image of post Google I/O 2025:集成网络技术和人工智能

Google I/O 2025:集成网络技术和人工智能

查看 Google I/O 2025 的开发者更新,详细介绍 Gemini API 升级和 Chrome 的新原生设备上 AI API。

介绍

在 Google 年度开发者大会 Google I/O 2025 上,重大公告强调了人工智能和网络平台的融合。

对于 Web 开发人员来说,关注点已经扩展到云托管模型端点之外。业界正在向设备上人工智能执行转变,允许开发人员直接在客户端浏览器内运行轻量级法学硕士。

本文回顾了 Google I/O 2025 中以 Web 为中心的关键 AI 公告,并解释了它们将如何影响前端应用程序架构。


1. Chrome 中的设备端 AI:标准化内置 AI API

Google I/O 2025 上最受关注的网络更新是 Chrome 原生 内置 AI API 的发布,它直接在浏览器中运行 Google 的轻量级 Gemini Nano 模型。

传统上,向 Web 应用程序添加人工智能功能(例如摘要或翻译)需要在服务器端托管昂贵的模型或通过安全代理服务器路由客户端调用以保护 API 密钥。

Chrome 的内置人工智能通过将处理卸载到用户的本地硬件、在本地免费运行任务来改变这一点。

使用提示 API

async function askLocalAI(promptText) {
  // Verify if the browser supports the built-in Gemini Nano model
  const capabilities = await ai.assistant.capabilities();

  if (capabilities.available === "no") {
    console.error("On-device AI is not supported in this browser environment.");
    return;
  }

  // Spin up a new AI session thread
  const session = await ai.assistant.create();

  // Prompt the local model and retrieve the response
  const result = await session.prompt(promptText);

  // Clean up session resources
  session.destroy();

  return result;
}

// Usage Example
askLocalAI("Identify bugs in the following snippet and summarize corrections...")
  .then(console.log);

核心优势

  • 低延迟和离线支持: 无需网络往返,响应即可快速解决,应用程序甚至可以在离线或飞行模式下运行。
  • 隐私控制: 数据不会离开用户的计算机,使这种方法符合严格的隐私法规。
  • 无 API 开销: 消除托管成本、令牌使用定价和速率限制问题。

2.Gemini API 升级:结构化 JSON 输出

谷歌的云托管Gemini API也进行了升级。最新的 Gemini 1.5 Pro 和 Flash 型号现在通过 Google AI Studio 控制台支持开箱即用的结构化 JSON 输出。

利用 JavaScript SDK

官方 JS/TS SDK (@google/generative-ai) 已更新,以强制 JSON 输出匹配定义的架构。

import { GoogleGenAI } from '@google/generative-ai';

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

// Configure Gemini to output data matching a defined JSON schema
const response = await ai.models.generateContent({
  model: 'gemini-1.5-flash',
  contents: 'List three clothing recommendations based on a rainy day forecast.',
  config: {
    responseMimeType: 'application/json',
    responseSchema: {
      type: 'object',
      properties: {
        outfits: {
          type: 'array',
          items: { type: 'string' }
        },
        reasoning: { type: 'string' }
      }
    }
  }
});

实施结构化输出模式可确保 AI 输出与您的应用程序代码可靠地集成。


3.WebAssembly (Wasm) 和 WebGPU 加速

谷歌还宣布更新 WebAssembly (Wasm) 运行时,以支持设备上的人工智能工作负载。

Chrome 的多线程 WebGPU 支持已更新,允许 Wasm 二进制文件(例如 TensorFlow.js 模型)在主机系统的 GPU 上编译和运行。这加快了实时浏览器内媒体处理、模型执行和物理模拟的速度。

结论

Google I/O 2025 展示了网络浏览器正在从简单的显示引擎转向原生人工智能执行平台

Chrome 的内置 AI API 将塑造开发人员处理用户隐私和应用程序成本结构的方式。开始尝试这些本机 API,为下一代 Web 应用程序做好准备。