From 43c1d5d017c3dd1cabd5440da7d1904caf75f4ee Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 29 Feb 2024 03:12:11 +0800 Subject: [PATCH] add groq --- .../credentials/GroqApi.credential.ts | 23 +++++ .../components/nodes/chatmodels/Groq/Groq.ts | 80 ++++++++++++++++++ .../components/nodes/chatmodels/Groq/groq.png | Bin 0 -> 1450 bytes packages/components/package.json | 1 + packages/server/src/utils/index.ts | 3 +- 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 packages/components/credentials/GroqApi.credential.ts create mode 100644 packages/components/nodes/chatmodels/Groq/Groq.ts create mode 100644 packages/components/nodes/chatmodels/Groq/groq.png diff --git a/packages/components/credentials/GroqApi.credential.ts b/packages/components/credentials/GroqApi.credential.ts new file mode 100644 index 00000000..a1c79060 --- /dev/null +++ b/packages/components/credentials/GroqApi.credential.ts @@ -0,0 +1,23 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class GroqApi implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'Groq API' + this.name = 'groqApi' + this.version = 1.0 + this.inputs = [ + { + label: 'Groq Api Key', + name: 'groqApiKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: GroqApi } diff --git a/packages/components/nodes/chatmodels/Groq/Groq.ts b/packages/components/nodes/chatmodels/Groq/Groq.ts new file mode 100644 index 00000000..91e96aef --- /dev/null +++ b/packages/components/nodes/chatmodels/Groq/Groq.ts @@ -0,0 +1,80 @@ +import { BaseCache } from '@langchain/core/caches' +import { ChatGroq, ChatGroqInput } from '@langchain/groq' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' + +class Groq_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 = 'GroqChat' + this.name = 'groqChat' + this.version = 2.0 + this.type = 'GroqChat' + this.icon = 'groq.png' + this.category = 'Chat Models' + this.description = 'Wrapper around Groq API with LPU Inference Engine' + this.baseClasses = [this.type, ...getBaseClasses(ChatGroq)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['groqApi'], + optional: true + } + this.inputs = [ + { + label: 'Cache', + name: 'cache', + type: 'BaseCache', + optional: true + }, + { + label: 'Model Name', + name: 'modelName', + type: 'string', + placeholder: 'ft:gpt-3.5-turbo:my-org:custom_suffix:id' + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.9, + optional: true + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const cache = nodeData.inputs?.cache as BaseCache + const temperature = nodeData.inputs?.temperature as string + const streaming = nodeData.inputs?.streaming as boolean + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const groqApiKey = getCredentialParam('groqApiKey', credentialData, nodeData) + + const obj: ChatGroqInput = { + modelName, + temperature: parseFloat(temperature), + apiKey: groqApiKey, + streaming: streaming ?? true + } + if (cache) obj.cache = cache + + const model = new ChatGroq(obj) + return model + } +} + +module.exports = { nodeClass: Groq_ChatModels } diff --git a/packages/components/nodes/chatmodels/Groq/groq.png b/packages/components/nodes/chatmodels/Groq/groq.png new file mode 100644 index 0000000000000000000000000000000000000000..31564145e1068131f3cf0a49766efbd68a0b4d54 GIT binary patch literal 1450 zcmb7^dotQT$Rm%*&tNegE6tFx zX~(OSS86M*Ff-*bWJY9AB4p4GJG+1FUwh7;bMO7$d%x%2KR;Pc4mL7Uho!{C#AI+F z)C%l{0cSnPN$C?LbJuzsrmhz*qR>*$4wYt2$y}dOzvyq>& zo)P_{qe&3q`RD6y;l$`#fWt;PNp#!cIN&Y%CK2u8;F{Ovd()hO4f|a*!*N&(xA^jf z^3Rles?r(!-?BNJ5YNSJ!lO)dG|ma>xACQ5QGoxX5DA%2OicJ#s)R4HLuc6_j|jx0 z;O7)!mAT@M)~Uxdo)zTtdcmdtSd+ESw}f(9$38TNdkzn8R2Jn?jgJb>(uZWORTk$= zBT@1`oHOpek&s)%o~ZGd`S&W66sobV?>Q~&3ac{WHPfVvd+D-6T6JiIY@JD{sYekt z1a8zYf4aCts~1A4$todQY7yjB#)0Ku3n(^28dnh_x7q0(SbbeDr+WH%Gf24QMe`Tf z0&qE+M2%%+{!Q(>_o1Ui)#3Puyj%mY-%l_`YDj8d+T?MNwg}}ksa~Bl3zi_Faq-1H zCsmj@+;q$&6NP8gy~gcIGS$7?B})_@n?%ZkBP|B~rO029cEiObRKB%BIg~jPJeRg* zhwo|U-d^e+9db65(}A7RbiR70%yu-hxG>EDN9+!CI?M#qfWG+4as2xaUZ1c6G0$V$ z_f$JL7Rvtt_7jn?;NA9-SbZyNOcYPPzDW2;PZ8#>8azpQoRe;J8nF-N?v-We8LF$d z5BANgPH}gse2M^`FK0t}(%)MzCw~zOY$23fldH%M^97>bh&7e6{Yi5@wh)rLWgl0) zwaj^_oO}BP_x447>E+Va1f)9L%)rsGAWL`fJHxqvNNU^68cX17s(q_iqDYb~s`aIk zy-6=X+sw$8^h-(oB zpyN{1OEZ?{p1C$f+=Jz$nJFp^tpq&-F*S`A(*c0_bS-0GReH@J(5|l1SIk zlb9^Pzwdj?3d_e%yyuAH-dS~rL3s8xW>#4G^h;FN%T~+COa3>s+1$gu=lMy}Z~In) zgfvMol0Eozac0k5=H+rvCe$VM$nN97@TSjkJjO6^Xxq&X&W%wpX4a{4@#2EiH)IGy z=?bw?>p-%^>lIPY2 zV!qI2!{>Svz3FRiQ!m@XE9yUU+OA$XWVV4b@3fRzumHCa+Y}Ccj!O>4$HFRXE zZBT5<`L3Jtb;7_M%;xnN?IxvM7wTO4e%X)XntK<_Sft!Kd*c>k?Fnkx1MJU?E*j@2 z!r6lkL4oz0ZG%_E1mdkp--dRAVrP;+MKg{R5h*Lseb|K=B&j4 literal 0 HcmV?d00001 diff --git a/packages/components/package.json b/packages/components/package.json index 20aef68a..95605edd 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -33,6 +33,7 @@ "@langchain/cohere": "^0.0.5", "@langchain/community": "^0.0.30", "@langchain/google-genai": "^0.0.10", + "@langchain/groq": "^0.0.2", "@langchain/mistralai": "^0.0.7", "@langchain/openai": "^0.0.14", "@langchain/pinecone": "^0.0.3", diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 8092fbd8..df215270 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -855,7 +855,8 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod 'chatAnthropic_LlamaIndex', 'chatOllama', 'awsChatBedrock', - 'chatMistralAI' + 'chatMistralAI', + 'groqChat' ], LLMs: ['azureOpenAI', 'openAI', 'ollama'] }