跳到主要内容
此功能为实验性功能,可能会发生变化。
Google 的 Built-in AI Early Preview Program 目前处于 Beta 阶段。如需申请访问权限或查找更多信息,请访问此链接
ChromeAI 利用 Gemini Nano 直接在浏览器或Worker中运行大型语言模型,无需互联网连接。这使得运行速度更快、私密性更高的模型成为可能,且数据永远不会离开用户设备。

入门

一旦您获得该程序的访问权限,请按照 Google 提供的说明下载模型。 下载后,您可以按以下方式在浏览器中使用 ChromeAI
import { ChromeAI } from "@langchain/community/experimental/llms/chrome_ai";

const model = new ChromeAI({
  temperature: 0.5, // Optional, defaults to 0.5
  topK: 40, // Optional, defaults to 40
});

const response = await model.invoke("Write me a short poem please");

/*
  In the realm where moonlight weaves its hue,
  Where dreams and secrets gently intertwine,
  There's a place of tranquility and grace,
  Where whispers of the night find their place.

  Beneath the canopy of starlit skies,
  Where dreams take flight and worries cease,
  A haven of tranquility, pure and true,
  Where the heart finds solace, finding dew.

  In this realm where dreams find their release,
  Where the soul finds peace, at every peace,
  Let us wander, lost in its embrace,
  Finding solace in this tranquil space.
*/

流式处理

ChromeAI 还支持流式输出
import { ChromeAI } from "@langchain/community/experimental/llms/chrome_ai";

const model = new ChromeAI({
  temperature: 0.5, // Optional, defaults to 0.5
  topK: 40, // Optional, defaults to 40
});

for await (const chunk of await model.stream("How are you?")) {
  console.log(chunk);
}

/*
  As
   an
   AI
   language
   model
  ,
   I
   don
  '
  t
   have
   personal
   experiences
   or
   the
   ability
   to
   experience
   emotions
  .
   Therefore
  ,
   I
   cannot
   directly
   answer
   the
   question
   "
  How
   are
   you
  ?".



  May
   I
   suggest
   answering
   something
   else
  ?
*/

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.