feat: add CometAPI integration with ChatCometAPI node (#5160)
* feat: add CometAPI integration with ChatCometAPI node and credential support * feat: remove timeout and stop sequence parameters from ChatCometAPI node
This commit is contained in:
parent
113086a2fb
commit
099cf481b4
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { INodeCredential, INodeParams } from '../src/Interface'
|
||||||
|
|
||||||
|
class CometApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Comet API'
|
||||||
|
this.name = 'cometApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Comet API Key',
|
||||||
|
name: 'cometApiKey',
|
||||||
|
type: 'password'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: CometApi }
|
||||||
|
|
@ -0,0 +1,176 @@
|
||||||
|
import { BaseCache } from '@langchain/core/caches'
|
||||||
|
import { ChatOpenAI, ChatOpenAIFields } from '@langchain/openai'
|
||||||
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
|
||||||
|
class ChatCometAPI_ChatModels implements INode {
|
||||||
|
readonly baseURL: string = 'https://api.cometapi.com/v1'
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
type: string
|
||||||
|
icon: string
|
||||||
|
category: string
|
||||||
|
description: string
|
||||||
|
baseClasses: string[]
|
||||||
|
credential: INodeParams
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'ChatCometAPI'
|
||||||
|
this.name = 'chatCometAPI'
|
||||||
|
this.version = 1.0
|
||||||
|
this.type = 'ChatCometAPI'
|
||||||
|
this.icon = 'cometapi.svg'
|
||||||
|
this.category = 'Chat Models'
|
||||||
|
this.description = 'Wrapper around CometAPI large language models that use the Chat endpoint'
|
||||||
|
this.baseClasses = [this.type, ...getBaseClasses(ChatOpenAI)]
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
credentialNames: ['cometApi']
|
||||||
|
}
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Cache',
|
||||||
|
name: 'cache',
|
||||||
|
type: 'BaseCache',
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Model Name',
|
||||||
|
name: 'modelName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'gpt-5-mini',
|
||||||
|
description: 'Enter the model name (e.g., gpt-5-mini, claude-sonnet-4-20250514, gemini-2.0-flash)'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Temperature',
|
||||||
|
name: 'temperature',
|
||||||
|
type: 'number',
|
||||||
|
step: 0.1,
|
||||||
|
default: 0.7,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Streaming',
|
||||||
|
name: 'streaming',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Max Tokens',
|
||||||
|
name: 'maxTokens',
|
||||||
|
type: 'number',
|
||||||
|
step: 1,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Top Probability',
|
||||||
|
name: 'topP',
|
||||||
|
type: 'number',
|
||||||
|
step: 0.1,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Frequency Penalty',
|
||||||
|
name: 'frequencyPenalty',
|
||||||
|
type: 'number',
|
||||||
|
step: 0.1,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Presence Penalty',
|
||||||
|
name: 'presencePenalty',
|
||||||
|
type: 'number',
|
||||||
|
step: 0.1,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Base Options',
|
||||||
|
name: 'baseOptions',
|
||||||
|
type: 'json',
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true,
|
||||||
|
description: 'Additional options to pass to the CometAPI client. This should be a JSON object.'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
|
const temperature = nodeData.inputs?.temperature as string
|
||||||
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
|
const maxTokens = nodeData.inputs?.maxTokens as string
|
||||||
|
const topP = nodeData.inputs?.topP as string
|
||||||
|
const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string
|
||||||
|
const presencePenalty = nodeData.inputs?.presencePenalty as string
|
||||||
|
const streaming = nodeData.inputs?.streaming as boolean
|
||||||
|
const baseOptions = nodeData.inputs?.baseOptions
|
||||||
|
|
||||||
|
if (nodeData.inputs?.credentialId) {
|
||||||
|
nodeData.credential = nodeData.inputs?.credentialId
|
||||||
|
}
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const openAIApiKey = getCredentialParam('cometApiKey', credentialData, nodeData)
|
||||||
|
|
||||||
|
// Custom error handling for missing API key
|
||||||
|
if (!openAIApiKey || openAIApiKey.trim() === '') {
|
||||||
|
throw new Error(
|
||||||
|
'CometAPI API Key is missing or empty. Please provide a valid CometAPI API key in the credential configuration.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom error handling for missing model name
|
||||||
|
if (!modelName || modelName.trim() === '') {
|
||||||
|
throw new Error('Model Name is required. Please enter a valid model name (e.g., gpt-5-mini, claude-sonnet-4-20250514).')
|
||||||
|
}
|
||||||
|
|
||||||
|
const cache = nodeData.inputs?.cache as BaseCache
|
||||||
|
|
||||||
|
const obj: ChatOpenAIFields = {
|
||||||
|
temperature: parseFloat(temperature),
|
||||||
|
modelName,
|
||||||
|
openAIApiKey,
|
||||||
|
apiKey: openAIApiKey,
|
||||||
|
streaming: streaming ?? true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
|
||||||
|
if (topP) obj.topP = parseFloat(topP)
|
||||||
|
if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)
|
||||||
|
if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)
|
||||||
|
if (cache) obj.cache = cache
|
||||||
|
|
||||||
|
let parsedBaseOptions: any | undefined = undefined
|
||||||
|
|
||||||
|
if (baseOptions) {
|
||||||
|
try {
|
||||||
|
parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
|
||||||
|
if (parsedBaseOptions.baseURL) {
|
||||||
|
console.warn("The 'baseURL' parameter is not allowed when using the ChatCometAPI node.")
|
||||||
|
parsedBaseOptions.baseURL = undefined
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
throw new Error('Invalid JSON in the BaseOptions: ' + exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const model = new ChatOpenAI({
|
||||||
|
...obj,
|
||||||
|
configuration: {
|
||||||
|
baseURL: this.baseURL,
|
||||||
|
...parsedBaseOptions
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nodeClass: ChatCometAPI_ChatModels }
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="207" height="232">
|
||||||
|
<path d="M0 0 C0.67675781 0.46921875 1.35351562 0.9384375 2.05078125 1.421875 C17.41087449 13.29936953 26.5563465 33.10648567 29 52 C30.88353091 73.63839398 25.57681073 94.24662535 12.078125 111.44921875 C3.52802952 121.42968735 -6.99880017 129.74646365 -17.29296875 137.85546875 C-20.80734684 140.63958646 -24.27616958 143.47806764 -27.75 146.3125 C-33.38311845 150.9007126 -39.05678704 155.43068832 -44.78027344 159.90551758 C-49.04401373 163.24101866 -53.27752081 166.61244975 -57.5 170 C-65.19965911 176.17403006 -72.95956911 182.26929551 -80.72949219 188.35449219 C-82.46597474 189.71488377 -84.201812 191.07609486 -85.9375 192.4375 C-86.79347778 193.10785278 -86.79347778 193.10785278 -87.66674805 193.79174805 C-90.77553239 196.23184554 -93.86474805 198.69340592 -96.93359375 201.18359375 C-97.59174072 201.71605713 -98.2498877 202.24852051 -98.92797852 202.79711914 C-100.18028531 203.81199799 -101.42972104 204.83043537 -102.67553711 205.85327148 C-113.67406316 214.75771491 -113.67406316 214.75771491 -119 215.3125 C-119.66 215.209375 -120.32 215.10625 -121 215 C-120.76709766 206.13030267 -117.19647897 198.99781748 -113.5 191.125 C-112.58712887 189.14895917 -111.67783856 187.17130284 -110.76916504 185.19332886 C-109.94887846 183.41284051 -109.12017404 181.63623744 -108.29101562 179.85986328 C-106.94852395 177.01575524 -106.94852395 177.01575524 -106 174 C-111.81280806 176.66712818 -116.32649031 179.60521955 -121.0625 183.875 C-121.70026367 184.43727295 -122.33802734 184.9995459 -122.99511719 185.57885742 C-127.01702202 189.14802701 -130.94253647 192.81269758 -134.84643555 196.51000977 C-148.71629517 209.64341666 -148.71629517 209.64341666 -155 213 C-155.99 212.67 -156.98 212.34 -158 212 C-157.4887063 206.47279763 -156.48994938 202.10988914 -154.26953125 196.96484375 C-153.99662766 196.32366104 -153.72372406 195.68247833 -153.44255066 195.02186584 C-152.57534585 192.98952075 -151.69455566 190.96343746 -150.8125 188.9375 C-148.52960643 183.63017721 -146.25725257 178.31827892 -144 173 C-143.70816833 172.31351379 -143.41633667 171.62702759 -143.11566162 170.91973877 C-142.25821582 168.88940943 -141.41429529 166.85397475 -140.57421875 164.81640625 C-140.07881592 163.6260376 -139.58341309 162.43566895 -139.07299805 161.20922852 C-138.07156521 158.21404429 -137.75796746 156.11997935 -138 153 C-146.93919642 160.27430311 -154.518973 168.82712219 -161.6875 177.8125 C-165.32819613 182.32251855 -169.13147644 186.77267556 -174 190 C-174.99 190 -175.98 190 -177 190 C-177.4046542 183.89279484 -176.01282428 179.27664925 -173.9140625 173.57421875 C-173.5860817 172.65574158 -173.25810089 171.7372644 -172.92018127 170.79095459 C-171.83227842 167.75258546 -170.72872039 164.72015532 -169.625 161.6875 C-168.84968909 159.53233408 -168.07537462 157.37680947 -167.30200195 155.22094727 C-165.68521472 150.71991256 -164.06188369 146.22131861 -162.43310547 141.72460938 C-160.13107613 135.36796141 -157.84629984 129.00524003 -155.56640625 122.640625 C-152.24887824 113.38342752 -148.91109678 104.13369846 -145.56491089 94.88682556 C-143.03925807 87.89940757 -140.53790092 80.90366027 -138.04859924 73.9032135 C-136.26757654 68.89703093 -134.47331016 63.8956159 -132.67861938 58.89431763 C-131.8214001 56.49792847 -130.9687066 54.09991471 -130.12094116 51.70016479 C-123.98775591 34.3499988 -118.12632414 19.31829963 -105 6 C-104.44957031 5.37738281 -103.89914063 4.75476563 -103.33203125 4.11328125 C-76.27136915 -25.62003884 -30.00866348 -21.14678947 0 0 Z " fill="#00ACE2" transform="translate(177,17)"/>
|
||||||
|
<path d="M0 0 C3.59370889 2.76840946 6.81090677 5.77847531 10 9 C10.69867188 9.66515625 11.39734375 10.3303125 12.1171875 11.015625 C16.54012757 15.52461449 19.531169 20.41283818 22.375 26 C22.70902832 26.65234619 23.04305664 27.30469238 23.38720703 27.97680664 C29.78966214 41.20843735 30.40448825 59.20573624 26.08984375 73.18359375 C18.48979965 92.82385108 6.27019435 105.41854323 -13 114 C-29.20527458 120.38314632 -45.91187826 119.08787574 -61.9140625 112.8671875 C-78.47633521 105.1244532 -90.6818902 90.79579279 -97.20117188 73.89526367 C-101.70761398 60.18076397 -101.08909063 42.12663774 -95 29 C-94.57589844 28.06671875 -94.15179688 27.1334375 -93.71484375 26.171875 C-85.2846631 9.3584785 -71.84223513 -1.671465 -54.3125 -7.96484375 C-35.99378812 -13.48589997 -16.09003976 -10.05627485 0 0 Z " fill="#0274C3" transform="translate(163,25)"/>
|
||||||
|
<path d="M0 0 C3.59370889 2.76840946 6.81090677 5.77847531 10 9 C10.69867188 9.66515625 11.39734375 10.3303125 12.1171875 11.015625 C16.54012757 15.52461449 19.531169 20.41283818 22.375 26 C22.70902832 26.65234619 23.04305664 27.30469238 23.38720703 27.97680664 C29.78966214 41.20843735 30.40448825 59.20573624 26.08984375 73.18359375 C18.48979965 92.82385108 6.27019435 105.41854323 -13 114 C-29.20527458 120.38314632 -45.91187826 119.08787574 -61.9140625 112.8671875 C-78.47633521 105.1244532 -90.6818902 90.79579279 -97.20117188 73.89526367 C-101.70761398 60.18076397 -101.08909063 42.12663774 -95 29 C-94.57589844 28.06671875 -94.15179688 27.1334375 -93.71484375 26.171875 C-85.2846631 9.3584785 -71.84223513 -1.671465 -54.3125 -7.96484375 C-35.99378812 -13.48589997 -16.09003976 -10.05627485 0 0 Z M-72.85546875 22.3046875 C-81.52384195 33.1993642 -85.32925872 46.19509438 -84 60 C-81.19770636 74.79342134 -74.05177982 85.87095721 -62 95 C-50.07317504 102.49999729 -36.59178226 103.84984433 -22.875 100.9375 C-9.58998661 97.14684284 0.96143129 88.7625654 7.6796875 76.7578125 C13.61298631 64.36459073 14.80612594 52.14069452 11.02734375 38.90625 C6.83721139 27.05279572 -1.00703398 17.2712335 -11.984375 10.95703125 C-15.54241409 9.26765223 -19.22605928 8.10166317 -23 7 C-23.99 6.67 -24.98 6.34 -26 6 C-44.99521417 4.32054509 -59.38243396 8.38333807 -72.85546875 22.3046875 Z " fill="#FAFDFE" transform="translate(163,25)"/>
|
||||||
|
<path d="M0 0 C6.24302767 5.06772084 11.11257121 12.4655725 12.15625 20.50390625 C12.39769334 29.34676869 10.95006126 36.08814626 5.75 43.375 C1.38925675 47.21456516 -1.15219336 48.71018589 -7.05664062 48.625 C-10.77603931 48.20106141 -13.73923312 46.63634037 -17 44.875 C-17.68956787 44.5147876 -18.37913574 44.1545752 -19.08959961 43.78344727 C-41.85230667 31.66318165 -41.85230667 31.66318165 -46.25 21.375 C-47.21511912 15.34300547 -45.21326136 11.66919243 -42.0234375 6.7421875 C-37.16499414 0.25712874 -31.52400844 -3.17464768 -23.75 -5.3125 C-15.10762666 -6.39279667 -7.23796009 -4.98215226 0 0 Z " fill="#FCFDFE" transform="translate(149.25,47.625)"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 6.4 KiB |
|
|
@ -1491,7 +1491,8 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
|
||||||
'chatTogetherAI_LlamaIndex',
|
'chatTogetherAI_LlamaIndex',
|
||||||
'chatFireworks',
|
'chatFireworks',
|
||||||
'ChatSambanova',
|
'ChatSambanova',
|
||||||
'chatBaiduWenxin'
|
'chatBaiduWenxin',
|
||||||
|
'chatCometAPI'
|
||||||
],
|
],
|
||||||
LLMs: ['azureOpenAI', 'openAI', 'ollama']
|
LLMs: ['azureOpenAI', 'openAI', 'ollama']
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue