-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Groq Chat Model Node): Add support for Groq chat models (#9250)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com>
- Loading branch information
1 parent
abae635
commit 96f02bd
Showing
7 changed files
with
276 additions
and
3 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/@n8n/nodes-langchain/credentials/GroqApi.credentials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { | ||
IAuthenticateGeneric, | ||
ICredentialTestRequest, | ||
ICredentialType, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
export class GroqApi implements ICredentialType { | ||
name = 'groqApi'; | ||
|
||
displayName = 'Groq'; | ||
|
||
documentationUrl = 'groq'; | ||
|
||
properties: INodeProperties[] = [ | ||
{ | ||
displayName: 'API Key', | ||
name: 'apiKey', | ||
type: 'string', | ||
typeOptions: { password: true }, | ||
required: true, | ||
default: '', | ||
}, | ||
]; | ||
|
||
authenticate: IAuthenticateGeneric = { | ||
type: 'generic', | ||
properties: { | ||
headers: { | ||
Authorization: '=Bearer {{$credentials.apiKey}}', | ||
}, | ||
}, | ||
}; | ||
|
||
test: ICredentialTestRequest = { | ||
request: { | ||
baseURL: 'https://api.groq.com/openai/v1', | ||
url: '/models', | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */ | ||
import { | ||
NodeConnectionType, | ||
type IExecuteFunctions, | ||
type INodeType, | ||
type INodeTypeDescription, | ||
type SupplyData, | ||
} from 'n8n-workflow'; | ||
|
||
import { ChatGroq } from '@langchain/groq'; | ||
import { logWrapper } from '../../../utils/logWrapper'; | ||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; | ||
|
||
export class LmChatGroq implements INodeType { | ||
description: INodeTypeDescription = { | ||
displayName: 'Groq Chat Model', | ||
// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased | ||
name: 'lmChatGroq', | ||
icon: 'file:groq.svg', | ||
group: ['transform'], | ||
version: 1, | ||
description: 'Language Model Groq', | ||
defaults: { | ||
name: 'Groq Chat Model', | ||
}, | ||
codex: { | ||
categories: ['AI'], | ||
subcategories: { | ||
AI: ['Language Models'], | ||
}, | ||
resources: { | ||
primaryDocumentation: [ | ||
{ | ||
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatgroq/', | ||
}, | ||
], | ||
}, | ||
}, | ||
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node | ||
inputs: [], | ||
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong | ||
outputs: [NodeConnectionType.AiLanguageModel], | ||
outputNames: ['Model'], | ||
credentials: [ | ||
{ | ||
name: 'groqApi', | ||
required: true, | ||
}, | ||
], | ||
requestDefaults: { | ||
baseURL: 'https://api.groq.com/openai/v1', | ||
}, | ||
properties: [ | ||
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiChain]), | ||
{ | ||
displayName: 'Model', | ||
name: 'model', | ||
type: 'options', | ||
typeOptions: { | ||
loadOptions: { | ||
routing: { | ||
request: { | ||
method: 'GET', | ||
url: '/models', | ||
}, | ||
output: { | ||
postReceive: [ | ||
{ | ||
type: 'rootProperty', | ||
properties: { | ||
property: 'data', | ||
}, | ||
}, | ||
{ | ||
type: 'filter', | ||
properties: { | ||
pass: '={{ $responseItem.active === true && $responseItem.object === "model" }}', | ||
}, | ||
}, | ||
{ | ||
type: 'setKeyValue', | ||
properties: { | ||
name: '={{$responseItem.id}}', | ||
value: '={{$responseItem.id}}', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
routing: { | ||
send: { | ||
type: 'body', | ||
property: 'model', | ||
}, | ||
}, | ||
description: | ||
'The model which will generate the completion. <a href="https://console.groq.com/docs/models">Learn more</a>.', | ||
default: 'llama3-8b-8192', | ||
}, | ||
{ | ||
displayName: 'Options', | ||
name: 'options', | ||
placeholder: 'Add Option', | ||
description: 'Additional options to add', | ||
type: 'collection', | ||
default: {}, | ||
options: [ | ||
{ | ||
displayName: 'Maximum Number of Tokens', | ||
name: 'maxTokensToSample', | ||
default: 4096, | ||
description: 'The maximum number of tokens to generate in the completion', | ||
type: 'number', | ||
}, | ||
{ | ||
displayName: 'Sampling Temperature', | ||
name: 'temperature', | ||
default: 0.7, | ||
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 }, | ||
description: | ||
'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.', | ||
type: 'number', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> { | ||
const credentials = await this.getCredentials('groqApi'); | ||
|
||
const modelName = this.getNodeParameter('model', itemIndex) as string; | ||
const options = this.getNodeParameter('options', itemIndex, {}) as { | ||
maxTokensToSample?: number; | ||
temperature: number; | ||
}; | ||
|
||
const model = new ChatGroq({ | ||
apiKey: credentials.apiKey as string, | ||
modelName, | ||
maxTokens: options.maxTokensToSample, | ||
temperature: options.temperature, | ||
}); | ||
|
||
return { | ||
response: logWrapper(model, this), | ||
}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/groq.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.