langchain.js
    Preparing search index...

    Install and import from "@langchain/cloudflare" instead.

    A class that enables calls to the Cloudflare Workers AI API to access large language models in a chat-like fashion. It extends the SimpleChatModel class and implements the CloudflareWorkersAIInput interface.

    const model = new ChatCloudflareWorkersAI({
    model: "@cf/meta/llama-2-7b-chat-int8",
    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);

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    • Parameters

      • Optionalfields: any

      Returns ChatCloudflareWorkersAI

    Properties

    baseUrl: string
    cloudflareAccountId?: string
    cloudflareApiToken?: string
    lc_serializable: boolean = true
    model: string = "@cf/meta/llama-2-7b-chat-int8"
    streaming: boolean = false

    Accessors

    • get identifyingParams(): { model: string }

      Get the identifying parameters for this LLM.

      Returns { model: string }

    • get lc_secrets(): undefined | { [key: string]: string }

      Returns undefined | { [key: string]: string }

    Methods

    • Returns {}

    • Parameters

      • messages: BaseMessage[]

      Returns { content: string; role: string }[]

    • Returns string

    • Parameters

      • messages: BaseMessage[]
      • options: unknown
      • Optionalstream: boolean

      Returns Promise<any>

    • Parameters

      • messages: BaseMessage[]
      • options: unknown
      • OptionalrunManager: any

      Returns AsyncGenerator<ChatGenerationChunk>

    • Get the parameters used to invoke the model

      Parameters

      • Optional_options: unknown

      Returns { model: string }

    • Method to validate the environment.

      Returns void

    • Returns string