feat: Add AI tool building capabilities (#7336)

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>
This commit is contained in:
Jan Oberhauser
2023-11-29 12:13:55 +01:00
committed by GitHub
parent dbfd617ace
commit 87def60979
243 changed files with 21526 additions and 321 deletions

View File

@@ -0,0 +1,161 @@
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
import {
NodeConnectionType,
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type SupplyData,
} from 'n8n-workflow';
import { ChatOllama } from 'langchain/chat_models/ollama';
// import { ChatAnthropic } from 'langchain/chat_models/anthropic';
import { logWrapper } from '../../../utils/logWrapper';
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
export class LmChatOllama implements INodeType {
description: INodeTypeDescription = {
displayName: 'Ollama Chat Model',
// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased
name: 'lmChatOllama',
icon: 'file:ollama.svg',
group: ['transform'],
version: 1,
description: 'Language Model Ollama',
defaults: {
name: 'Ollama 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.lmchatollama/',
},
],
},
},
// 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: 'ollamaApi',
required: true,
},
],
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: '={{ $credentials.baseUrl.replace(new RegExp("/$"), "") }}',
},
properties: [
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiAgent]),
{
displayName: 'Model',
name: 'model',
type: 'options',
default: 'llama2',
description:
'The model which will generate the completion. To download models, visit <a href="https://ollama.ai/library">Ollama Models Library</a>.',
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '/api/tags',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'models',
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.name}}',
value: '={{$responseItem.name}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
},
routing: {
send: {
type: 'body',
property: 'model',
},
},
required: true,
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
description: 'Additional options to add',
type: 'collection',
default: {},
options: [
{
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('ollamaApi');
const modelName = this.getNodeParameter('model', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {}) as object;
const model = new ChatOllama({
baseUrl: credentials.baseUrl as string,
model: modelName,
...options,
});
return {
response: logWrapper(model, this),
};
}
}

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="181.000000pt" height="256.000000pt" viewBox="0 0 181.000000 256.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,256.000000) scale(0.100000,-0.100000)"
fill="#7D7D87" stroke="none">
<path d="M377 2365 c-52 -18 -83 -49 -117 -116 -45 -89 -62 -192 -58 -355 l3
-142 -58 -61 c-148 -155 -185 -387 -92 -574 l34 -69 -20 -44 c-34 -82 -50
-164 -50 -263 0 -108 18 -190 58 -262 l26 -48 -21 -49 c-12 -27 -26 -71 -32
-98 -14 -62 -15 -221 -1 -257 10 -26 14 -27 76 -27 73 0 70 -4 53 86 -15 82 2
188 42 266 37 70 38 104 5 148 -47 64 -68 136 -69 240 -1 103 14 160 66 261
31 61 29 87 -10 122 -11 10 -31 42 -43 70 -19 42 -24 69 -23 142 0 114 25 183
95 260 70 76 142 110 239 112 41 0 78 2 82 2 4 1 17 22 29 47 30 59 96 119
167 152 49 23 70 27 147 27 79 0 97 -4 149 -29 68 -33 133 -94 159 -148 10
-20 23 -41 30 -45 6 -4 46 -8 87 -8 67 -1 83 -5 140 -36 123 -68 193 -187 193
-334 1 -67 -4 -90 -27 -142 -16 -35 -35 -68 -43 -75 -34 -28 -35 -58 -5 -117
52 -101 67 -158 66 -261 -1 -104 -22 -176 -69 -240 -33 -44 -32 -78 5 -148 40
-78 57 -184 42 -266 -17 -90 -20 -86 53 -86 62 0 66 1 76 27 14 36 13 195 -1
257 -6 27 -20 71 -32 98 l-21 49 26 48 c76 139 79 359 6 528 l-20 47 25 46
c99 183 64 439 -81 591 l-58 61 3 142 c4 164 -13 266 -58 357 -64 126 -172
159 -263 79 -54 -47 -92 -138 -123 -298 -3 -14 -10 -22 -17 -18 -182 80 -297
85 -443 21 l-54 -24 -4 22 c-36 185 -85 285 -156 322 -43 21 -74 24 -113 10z
m77 -168 c42 -71 81 -301 57 -336 -5 -8 -31 -16 -58 -18 -26 -2 -62 -8 -80
-13 l-31 -8 -7 49 c-8 59 2 172 22 248 14 57 48 121 63 121 5 0 20 -19 34 -43z
m965 10 c40 -65 69 -239 56 -336 l-7 -49 -31 8 c-18 5 -54 11 -80 13 -27 2
-53 10 -58 18 -12 17 -3 141 17 229 15 64 57 150 74 150 4 0 18 -15 29 -33z"/>
<path d="M778 1361 c-73 -24 -116 -51 -165 -104 -55 -60 -76 -120 -71 -201 5
-76 35 -129 106 -183 62 -47 127 -63 257 -63 172 0 258 36 329 138 42 59 48
155 16 230 -29 68 -111 143 -188 173 -80 31 -207 36 -284 10z m257 -100 c161
-71 194 -232 66 -318 -49 -33 -94 -43 -196 -43 -102 0 -147 10 -196 43 -178
120 -32 356 211 343 39 -2 86 -12 115 -25z"/>
<path d="M838 1159 c-25 -14 -22 -44 7 -67 20 -16 24 -26 19 -49 -7 -36 15
-58 51 -49 21 5 25 12 25 46 0 29 5 42 20 50 27 15 27 66 0 75 -10 3 -28 1
-40 -5 -14 -7 -26 -8 -39 0 -23 12 -22 12 -43 -1z"/>
<path d="M397 1348 c-9 -7 -23 -30 -32 -50 -21 -53 -1 -103 47 -116 43 -11 60
-6 92 27 40 41 43 81 11 119 -21 25 -34 32 -64 32 -20 0 -45 -6 -54 -12z"/>
<path d="M1295 1328 c-32 -38 -29 -78 11 -119 32 -33 49 -38 92 -27 49 13 68
62 46 118 -19 47 -38 60 -87 60 -27 0 -41 -7 -62 -32z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB