forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Cloudflare Workers AI LLM and chat model (langchain-ai#2923)
* Adds Cloudflare Workers AI LLM and chat model * Formatting
- Loading branch information
1 parent
38eee64
commit c5d5e86
Showing
20 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
docs/docs/modules/model_io/models/chat/integrations/cloudflare_workersai.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
sidebar_label: Cloudflare Workers AI | ||
--- | ||
|
||
# ChatCloudflareWorkersAI | ||
|
||
:::info | ||
Workers AI is currently in Open Beta and is not recommended for production data and traffic, and limits + access are subject to change | ||
::: | ||
|
||
Workers AI allows you to run machine learning models, on the Cloudflare network, from your own code. | ||
|
||
## Usage | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/models/chat/integration_cloudflare_workersai.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
14 changes: 14 additions & 0 deletions
14
docs/docs/modules/model_io/models/llms/integrations/cloudflare_workersai.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Cloudflare Workers AI | ||
|
||
:::info | ||
Workers AI is currently in Open Beta and is not recommended for production data and traffic, and limits + access are subject to change | ||
::: | ||
|
||
Workers AI allows you to run machine learning models, on the Cloudflare network, from your own code. | ||
|
||
## Usage | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/models/llm/cloudflare_workersai.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
examples/src/models/chat/integration_cloudflare_workersai.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ChatCloudflareWorkersAI } from "langchain/chat_models/cloudflare_workersai"; | ||
|
||
const model = new ChatCloudflareWorkersAI({ | ||
model: "@cf/meta/llama-2-7b-chat-int8", // Default value | ||
cloudflareAccountId: process.env.CLOUDFLARE_ACCOUNT_ID, | ||
cloudflareApiToken: process.env.CLOUDFLARE_API_TOKEN, | ||
}); | ||
|
||
const response = await model.invoke([ | ||
["system", "You are a helpful assistant that translates English to German."], | ||
["human", `Translate "I love programming".`], | ||
]); | ||
|
||
console.log(response); | ||
|
||
/* | ||
AIMessage { | ||
content: `Sure! Here's the translation of "I love programming" into German:\n` + | ||
'\n' + | ||
'"Ich liebe Programmieren."\n' + | ||
'\n' + | ||
'In this sentence, "Ich" means "I," "liebe" means "love," and "Programmieren" means "programming."', | ||
additional_kwargs: {} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CloudflareWorkersAI } from "langchain/llms/cloudflare_workersai"; | ||
|
||
const model = new CloudflareWorkersAI({ | ||
model: "@cf/meta/llama-2-7b-chat-int8", // Default value | ||
cloudflareAccountId: process.env.CLOUDFLARE_ACCOUNT_ID, | ||
cloudflareApiToken: process.env.CLOUDFLARE_API_TOKEN, | ||
}); | ||
|
||
const response = await model.invoke( | ||
`Translate "I love programming" into German.` | ||
); | ||
|
||
console.log(response); | ||
|
||
/* | ||
Here are a few options: | ||
1. "Ich liebe Programmieren" - This is the most common way to say "I love programming" in German. "Liebe" means "love" in German, and "Programmieren" means "programming". | ||
2. "Programmieren macht mir Spaß" - This means "Programming makes me happy". This is a more casual way to express your love for programming in German. | ||
3. "Ich bin ein großer Fan von Programmieren" - This means "I'm a big fan of programming". This is a more formal way to express your love for programming in German. | ||
4. "Programmieren ist mein Hobby" - This means "Programming is my hobby". This is a more casual way to express your love for programming in German. | ||
5. "Ich liebe es, Programme zu schreiben" - This means "I love writing programs". This is a more formal way to express your love for programming in German. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.