Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/components/credentials/CloudflareApi.credential.ts
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -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 }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading