本页还没有译文
本页 17 段还没译成한국어,下面显示的是英文原文。CloudflareWorkersAI integration
还没翻译译自英文(docs.langchain.com)本页 17 段都还没译
This will help you get started with Cloudflare Workers AI text completion models (LLMs) using LangChain. For detailed documentation on CloudflareWorkersAI features and configuration options, please refer to the API reference.
Overview
Integration details
| Class | Package | Local | Serializable | PY support | Downloads | Version |
|---|---|---|---|---|---|---|
CloudflareWorkersAI | @langchain/cloudflare | ❌ | ✅ | ❌ |
Setup
To access Cloudflare Workers AI models you'll need to create a Cloudflare account, get an API key, and install the @langchain/cloudflare integration package.
Credentials
Head to this page to sign up to Cloudflare and generate an API key. Once you've done this, set your credentials in the environment:
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
export CLOUDFLARE_API_TOKEN="your-api-token"Installation
The LangChain Cloudflare integration lives in the @langchain/cloudflare package:
npm install @langchain/cloudflare @langchain/coreyarn add @langchain/cloudflare @langchain/corepnpm add @langchain/cloudflare @langchain/coreInstantiation
Now we can instantiate our model object and generate chat completions:
// @lc-docs-hide-cell
// @ts-expect-error Deno is not recognized
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get("CLOUDFLARE_ACCOUNT_ID");
// @ts-expect-error Deno is not recognized
const CLOUDFLARE_API_TOKEN = Deno.env.get("CLOUDFLARE_API_TOKEN");import { CloudflareWorkersAI } from "@langchain/cloudflare";
const llm = new CloudflareWorkersAI({
model: "@cf/meta/llama-3.1-8b-instruct", // Default value
cloudflareAccountId: CLOUDFLARE_ACCOUNT_ID,
cloudflareApiToken: CLOUDFLARE_API_TOKEN,
// Pass a custom base URL to use Cloudflare AI Gateway
// baseUrl: `https://gateway.ai.cloudflare.com/v1/{YOUR_ACCOUNT_ID}/{GATEWAY_NAME}/workers-ai/`,
});Invocation
const inputText = "Cloudflare is an AI company that "
const completion = await llm.invoke(inputText);
completion"Cloudflare is not an AI company, but rather a content delivery network (CDN) and security company. T"... 876 more charactersAPI reference
For detailed documentation of all CloudflareWorkersAI features and configurations head to the API reference.