Feature/ChatCloudflareWorkersAI (#5644)

* Feature/ChatCloudflareWorkersAI

* Return Promise<ChatCloudflareWorkersAI>

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* add @langchain/cloudflare

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Henry Heng <[email protected]>
This commit is contained in:
Udaykumar Dhokia
2026-01-20 17:09:53 +08:00
committed by GitHub
co-authored by gemini-code-assist[bot] Henry Heng
parent 3901ef2652
commit 84d0b0b22e
5 changed files with 39386 additions and 39254 deletions
@@ -0,0 +1,30 @@
import { INodeParams, INodeCredential } from '../src/Interface'
class CloudflareApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]
constructor() {
this.label = 'Cloudflare API'
this.name = 'cloudflareApi'
this.version = 1.0
this.description = 'Use your Cloudflare Account ID and API Token'
this.inputs = [
{
label: 'Cloudflare Account ID',
name: 'cloudflareAccountId',
type: 'string'
},
{
label: 'Cloudflare API Token',
name: 'cloudflareApiToken',
type: 'password'
}
]
}
}
module.exports = { credClass: CloudflareApi }
@@ -0,0 +1,81 @@
import { ChatCloudflareWorkersAI, type CloudflareWorkersAIInput } from '@langchain/cloudflare'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
class ChatCloudflareWorkersAI_ChatModels implements INode {
label: string
name: string
version: number
type: string
icon: string
category: string
description: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]
constructor() {
this.label = 'ChatCloudflareWorkersAI'
this.name = 'chatCloudflareWorkersAI'
this.version = 1.0
this.type = 'ChatCloudflareWorkersAI'
this.icon = 'cloudflare.svg'
this.category = 'Chat Models'
this.description = 'Wrapper around Cloudflare Workers AI chat models'
this.baseClasses = [this.type, ...getBaseClasses(ChatCloudflareWorkersAI)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['cloudflareApi']
}
this.inputs = [
{
label: 'Model',
name: 'model',
type: 'string',
default: '@cf/meta/llama-3.1-8b-instruct-fast',
description: 'Model to use, e.g. @cf/meta/llama-3.1-8b-instruct-fast'
},
{
label: 'Base URL',
name: 'baseUrl',
type: 'string',
description: 'Base URL for Cloudflare Workers AI. Defaults to https://api.cloudflare.com/client/v4/accounts',
optional: true,
additionalParams: true
}
]
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<ChatCloudflareWorkersAI> {
const model = nodeData.inputs?.model as string
const baseUrl = nodeData.inputs?.baseUrl as string
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const cloudflareAccountId = getCredentialParam('cloudflareAccountId', credentialData, nodeData)
if (!cloudflareAccountId) {
throw new Error('Cloudflare Account ID is missing in credential.')
}
const cloudflareApiToken = getCredentialParam('cloudflareApiToken', credentialData, nodeData)
if (!cloudflareApiToken) {
throw new Error('Cloudflare API Token is missing in credential.')
}
const obj: CloudflareWorkersAIInput = {
cloudflareAccountId,
cloudflareApiToken,
model
}
if (baseUrl) {
obj.baseUrl = baseUrl
}
const chatModel = new ChatCloudflareWorkersAI(obj)
return chatModel
}
}
module.exports = { nodeClass: ChatCloudflareWorkersAI_ChatModels }
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><linearGradient id="a" x1="-.556" x2="-.628" y1="128.705" y2="128.977" gradientTransform="matrix(155.9359 0 0 -364.3 119.128 47001.098)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#eb6f07"/><stop offset="1" stop-color="#fab743"/></linearGradient><path fill="url(#a)" d="M33.882 9.694 48.491 36.05 35.075 60.199a7.75 7.75 0 0 0 0 7.543l13.416 24.209-14.609 26.356a15.501 15.501 0 0 1-6.559-6.172L4.068 71.737a15.563 15.563 0 0 1 0-15.503l23.255-40.398a15.501 15.501 0 0 1 6.559-6.142z"/><linearGradient id="b" x1="-.594" x2="-.715" y1="129.358" y2="129.519" gradientTransform="matrix(149.7049 0 0 -194.8 131.59 25305.098)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#d96504"/><stop offset="1" stop-color="#d96504" stop-opacity="0"/></linearGradient><path fill="url(#b)" d="M35.075 60.229a7.75 7.75 0 0 0 0 7.513l13.416 24.209-14.609 26.356a15.501 15.501 0 0 1-6.559-6.172L4.068 71.737c-1.848-3.19 8.497-7.006 31.007-11.478v-.03z" opacity=".7"/><linearGradient id="c" x1="-2.234" x2="-2.109" y1="128.901" y2="128.689" gradientTransform="matrix(95.8 0 0 -101.1 239.4 13048.3)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#eb6f07"/><stop offset="1" stop-color="#eb720a" stop-opacity="0"/></linearGradient><path fill="url(#c)" d="m35.373 12.347 13.118 23.702-2.176 3.786-11.568-19.587c-3.339-5.456-8.437-2.624-14.818 8.408l.954-1.64 6.44-11.18a15.51 15.51 0 0 1 6.499-6.142l1.521 2.653h.03z" opacity=".5"/><linearGradient id="d" x1="-.847" x2="-.919" y1="128.688" y2="128.96" gradientTransform="matrix(207.975 0 0 -375 275.025 48376)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#ee6f05"/><stop offset="1" stop-color="#fab743"/></linearGradient><path fill="url(#d)" d="m100.665 15.835 23.255 40.398a15.485 15.485 0 0 1 0 15.503l-23.255 40.398a15.504 15.504 0 0 1-13.416 7.752H63.994l28.92-52.145a7.75 7.75 0 0 0 0-7.513L63.994 8.084h23.255a15.502 15.502 0 0 1 13.416 7.751z"/><linearGradient id="e" x1="-2.602" x2="-2.229" y1="128.679" y2="128.977" gradientTransform="matrix(118.9101 0 0 -375.1 361.09 48388.902)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#d96504" stop-opacity=".8"/><stop offset=".498" stop-color="#d96504" stop-opacity=".2"/><stop offset="1" stop-color="#d96504" stop-opacity="0"/></linearGradient><path fill="url(#e)" d="m86.057 119.708-22.957.208 27.787-52.413a8.053 8.053 0 0 0 0-7.573L63.1 8.084h5.247l29.158 51.608a8.048 8.048 0 0 1-.03 7.99 4670.283 4670.283 0 0 0-18.693 32.796c-5.665 9.957-3.22 16.367 7.275 19.23z"/><linearGradient id="f" x1="-.561" x2="-.634" y1="128.688" y2="128.96" gradientTransform="matrix(201.2571 0 0 -375 180.743 48376)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#ffa95f"/><stop offset="1" stop-color="#ffebc8"/></linearGradient><path fill="url(#f)" d="M40.739 119.886c-2.385 0-4.77-.566-6.857-1.58l28.681-51.727a5.353 5.353 0 0 0 0-5.188L33.882 9.694a15.492 15.492 0 0 1 6.857-1.61h23.255l28.92 52.145a7.75 7.75 0 0 1 0 7.513l-28.92 52.145H40.739z"/><linearGradient id="g" x1="-2.816" x2="-2.552" y1="128.861" y2="128.719" gradientTransform="matrix(109.2571 0 0 -375 364.743 48376)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#fff" stop-opacity=".5"/><stop offset="1" stop-color="#fff" stop-opacity=".1"/></linearGradient><path fill="url(#g)" d="M90.886 61.391 61.311 8.084h2.683l28.92 52.145a7.75 7.75 0 0 1 0 7.513l-28.92 52.145h-2.683l29.576-53.308a5.35 5.35 0 0 0-.001-5.188z" opacity=".6"/><linearGradient id="h" x1="-2.34" x2="-2.001" y1="128.779" y2="128.952" gradientTransform="matrix(107.2571 0 0 -371.4 274.743 47913.2)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#fff" stop-opacity=".5"/><stop offset="1" stop-color="#fff" stop-opacity=".1"/></linearGradient><path fill="url(#h)" d="M62.563 61.391 33.882 9.694c.894-.477 1.968-.835 2.981-1.133 6.321 11.359 15.652 28.592 28.025 51.668a7.75 7.75 0 0 1 0 7.513L36.416 119.29c-1.014-.298-1.55-.507-2.504-.954l28.622-51.727a5.353 5.353 0 0 0 0-5.188l.029-.03z" opacity=".6"/></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

+1
View File
@@ -47,6 +47,7 @@
"@langchain/anthropic": "0.3.33",
"@langchain/aws": "^0.1.11",
"@langchain/baidu-qianfan": "^0.1.0",
"@langchain/cloudflare": "^1.0.1",
"@langchain/cohere": "^0.0.7",
"@langchain/community": "^0.3.47",
"@langchain/core": "0.3.61",
+39273 -39254
View File
File diff suppressed because one or more lines are too long