mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 09:04:07 -08:00
87def60979
Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/langchain-memory-chat/23733 --------- Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Deborah <deborah@starfallprojects.co.uk> Co-authored-by: Jesper Bylund <mail@jesperbylund.com> Co-authored-by: Jon <jonathan.bennetts@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Mason Geloso <Mason.geloso@gmail.com> Co-authored-by: Mason Geloso <hone@Masons-Mac-mini.local> Co-authored-by: Mutasem Aldmour <mutasem@n8n.io>
142 lines
4 KiB
TypeScript
142 lines
4 KiB
TypeScript
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
|
import {
|
|
NodeConnectionType,
|
|
type IExecuteFunctions,
|
|
type INodeType,
|
|
type INodeTypeDescription,
|
|
type SupplyData,
|
|
} from 'n8n-workflow';
|
|
|
|
import { ChatAnthropic } from 'langchain/chat_models/anthropic';
|
|
import { logWrapper } from '../../../utils/logWrapper';
|
|
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
|
|
|
export class LmChatAnthropic implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Anthropic Chat Model',
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased
|
|
name: 'lmChatAnthropic',
|
|
icon: 'file:anthropic.svg',
|
|
group: ['transform'],
|
|
version: 1,
|
|
description: 'Language Model Anthropic',
|
|
defaults: {
|
|
name: 'Anthropic 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.lmchatanthropic/',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
// 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: 'anthropicApi',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiChain]),
|
|
{
|
|
displayName: 'Model',
|
|
name: 'model',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Claude 2',
|
|
value: 'claude-2',
|
|
},
|
|
{
|
|
name: 'Claude 2.1',
|
|
value: 'claude-2.1',
|
|
},
|
|
{
|
|
name: 'Claude Instant 1.2',
|
|
value: 'claude-instant-1.2',
|
|
},
|
|
{
|
|
name: 'Claude Instant 1',
|
|
value: 'claude-instant-1',
|
|
},
|
|
],
|
|
description:
|
|
'The model which will generate the completion. <a href="https://docs.anthropic.com/claude/reference/selecting-a-model">Learn more</a>.',
|
|
default: 'claude-2',
|
|
},
|
|
{
|
|
displayName: 'Options',
|
|
name: 'options',
|
|
placeholder: 'Add Option',
|
|
description: 'Additional options to add',
|
|
type: 'collection',
|
|
default: {},
|
|
options: [
|
|
{
|
|
displayName: 'Maximum Number of Tokens',
|
|
name: 'maxTokensToSample',
|
|
default: 32768,
|
|
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',
|
|
},
|
|
{
|
|
displayName: 'Top K',
|
|
name: 'topK',
|
|
default: -1,
|
|
typeOptions: { maxValue: 1, minValue: -1, numberPrecision: 1 },
|
|
description:
|
|
'Used to remove "long tail" low probability responses. Defaults to -1, which disables it.',
|
|
type: 'number',
|
|
},
|
|
{
|
|
displayName: 'Top P',
|
|
name: 'topP',
|
|
default: 1,
|
|
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },
|
|
description:
|
|
'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',
|
|
type: 'number',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
|
const credentials = await this.getCredentials('anthropicApi');
|
|
|
|
const modelName = this.getNodeParameter('model', itemIndex) as string;
|
|
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
|
|
|
const model = new ChatAnthropic({
|
|
anthropicApiKey: credentials.apiKey as string,
|
|
modelName,
|
|
...options,
|
|
});
|
|
|
|
return {
|
|
response: logWrapper(model, this),
|
|
};
|
|
}
|
|
}
|