Skip to content

Commit

Permalink
community-experimental[minor]: Move experimental Chrome AI to LLMs (#…
Browse files Browse the repository at this point in the history
…5938)

* Move experimental Chrome AI to LLMs

* Docs

* Fix JSON

* Format

* Add support for workers

* Docs

* Update

* Lint
  • Loading branch information
jacoblee93 authored Jun 30, 2024
1 parent de4c660 commit bedc8de
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 2,988 deletions.
59 changes: 0 additions & 59 deletions docs/core_docs/docs/integrations/chat/chrome_ai.mdx

This file was deleted.

115 changes: 115 additions & 0 deletions docs/core_docs/docs/integrations/llms/chrome_ai.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
sidebar_label: ChromeAI
---

import CodeBlock from "@theme/CodeBlock";

# ChromeAI

:::info
This feature is **experimental** and is subject to change.
:::

:::note
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](https://developer.chrome.com/docs/ai/built-in).
:::

ChromeAI leverages Gemini Nano to run LLMs directly in the browser or in a [worker](https://developer.mozilla.org/en-US/docs/Web/API/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

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

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

```typescript
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` also supports streaming outputs:

```typescript
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
?
*/
```
4 changes: 4 additions & 0 deletions docs/core_docs/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
{
"source": "/docs/langsmith(/?)",
"destination": "https://docs.smith.langchain.com/"
},
{
"source": "/v0.2/docs/integrations/chat/chrome_ai(/?)",
"destination": "/v0.2/docs/integrations/llms/chrome_ai/"
}
]
}
8 changes: 4 additions & 4 deletions libs/langchain-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1030,10 +1030,10 @@ experimental/chat_models/ollama_functions.cjs
experimental/chat_models/ollama_functions.js
experimental/chat_models/ollama_functions.d.ts
experimental/chat_models/ollama_functions.d.cts
experimental/chat_models/chrome_ai.cjs
experimental/chat_models/chrome_ai.js
experimental/chat_models/chrome_ai.d.ts
experimental/chat_models/chrome_ai.d.cts
experimental/llms/chrome_ai.cjs
experimental/llms/chrome_ai.js
experimental/llms/chrome_ai.d.ts
experimental/llms/chrome_ai.d.cts
chains/graph_qa/cypher.cjs
chains/graph_qa/cypher.js
chains/graph_qa/cypher.d.ts
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const config = {
"experimental/hubs/makersuite/googlemakersuitehub":
"experimental/hubs/makersuite/googlemakersuitehub",
"experimental/chat_models/ollama_functions": "experimental/chat_models/ollama_functions",
"experimental/chat_models/chrome_ai": "experimental/chat_models/chrome_ai/chat_models",
"experimental/llms/chrome_ai": "experimental/llms/chrome_ai",
// chains
"chains/graph_qa/cypher": "chains/graph_qa/cypher"
},
Expand Down
20 changes: 10 additions & 10 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3022,14 +3022,14 @@
"import": "./experimental/chat_models/ollama_functions.js",
"require": "./experimental/chat_models/ollama_functions.cjs"
},
"./experimental/chat_models/chrome_ai": {
"./experimental/llms/chrome_ai": {
"types": {
"import": "./experimental/chat_models/chrome_ai.d.ts",
"require": "./experimental/chat_models/chrome_ai.d.cts",
"default": "./experimental/chat_models/chrome_ai.d.ts"
"import": "./experimental/llms/chrome_ai.d.ts",
"require": "./experimental/llms/chrome_ai.d.cts",
"default": "./experimental/llms/chrome_ai.d.ts"
},
"import": "./experimental/chat_models/chrome_ai.js",
"require": "./experimental/chat_models/chrome_ai.cjs"
"import": "./experimental/llms/chrome_ai.js",
"require": "./experimental/llms/chrome_ai.cjs"
},
"./chains/graph_qa/cypher": {
"types": {
Expand Down Expand Up @@ -4076,10 +4076,10 @@
"experimental/chat_models/ollama_functions.js",
"experimental/chat_models/ollama_functions.d.ts",
"experimental/chat_models/ollama_functions.d.cts",
"experimental/chat_models/chrome_ai.cjs",
"experimental/chat_models/chrome_ai.js",
"experimental/chat_models/chrome_ai.d.ts",
"experimental/chat_models/chrome_ai.d.cts",
"experimental/llms/chrome_ai.cjs",
"experimental/llms/chrome_ai.js",
"experimental/llms/chrome_ai.d.ts",
"experimental/llms/chrome_ai.d.cts",
"chains/graph_qa/cypher.cjs",
"chains/graph_qa/cypher.js",
"chains/graph_qa/cypher.d.ts",
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-community/src/embeddings/jina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class JinaEmbeddings extends Embeddings implements JinaEmbeddingsParams {
* @param input - An array of strings or objects to generate embeddings for.
* @returns A Promise that resolves to an array of embeddings.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async _embed(input: any): Promise<number[][]> {
const response = await fetch(JINA_API_URL, {
method: "POST",
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit bedc8de

Please sign in to comment.