Skip to main content

ChromeAI

info

此功能尚处于实验阶段,可能会有所变更。

¥This feature is experimental and is subject to change.

note

Google 的 Built-in AI Early Preview Program 目前处于测试阶段。要申请访问权限或了解更多信息,请访问 此链接

¥The Built-in AI Early Preview Program by Google is currently in beta. To apply for access or find more information, please visit this link.

ChromeAI 利用 Gemini Nano 直接在浏览器或 worker 中运行 LLM,无需网络连接。这允许运行更快且私密的模型,而无需数据离开消费者设备。

¥ChromeAI leverages Gemini Nano to run LLMs directly in the browser or in a worker, without the need for an internet connection. This allows for running faster and private models without ever having data leave the consumers device.

开始使用

¥Getting started

获得程序访问权限后,请按照 Google 提供的说明下载模型。

¥Once you've been granted access to the program, follow Google's provided instructions to download the model.

下载完成后,你可以按如下方式在浏览器中开始使用 ChromeAI

¥Once downloaded, you can start using ChromeAI in the browser as follows:

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.
*/

流式传输

¥Streaming

ChromeAI 还支持流式输出:

¥ChromeAI also supports streaming outputs:

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
?
*/

¥Related