first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { Ollama } from '@langchain/ollama';
|
||||
import {
|
||||
NodeConnectionTypes,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type ISupplyDataFunctions,
|
||||
type SupplyData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { ollamaDescription, ollamaModel, ollamaOptions } from './description';
|
||||
import {
|
||||
makeN8nLlmFailedAttemptHandler,
|
||||
N8nLlmTracing,
|
||||
getConnectionHintNoticeField,
|
||||
} from '@n8n/ai-utilities';
|
||||
|
||||
export class LmOllama implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Ollama Model',
|
||||
|
||||
name: 'lmOllama',
|
||||
icon: 'file:ollama.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Language Model Ollama',
|
||||
defaults: {
|
||||
name: 'Ollama Model',
|
||||
},
|
||||
codex: {
|
||||
categories: ['AI'],
|
||||
subcategories: {
|
||||
AI: ['Language Models', 'Root Nodes'],
|
||||
'Language Models': ['Text Completion Models'],
|
||||
},
|
||||
resources: {
|
||||
primaryDocumentation: [
|
||||
{
|
||||
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmollama/',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
inputs: [],
|
||||
|
||||
outputs: [NodeConnectionTypes.AiLanguageModel],
|
||||
outputNames: ['Model'],
|
||||
...ollamaDescription,
|
||||
properties: [
|
||||
getConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),
|
||||
ollamaModel,
|
||||
ollamaOptions,
|
||||
],
|
||||
};
|
||||
|
||||
async supplyData(this: ISupplyDataFunctions, 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 headers = credentials.apiKey
|
||||
? {
|
||||
Authorization: `Bearer ${credentials.apiKey as string}`,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const model = new Ollama({
|
||||
baseUrl: credentials.baseUrl as string,
|
||||
model: modelName,
|
||||
...options,
|
||||
callbacks: [new N8nLlmTracing(this)],
|
||||
onFailedAttempt: makeN8nLlmFailedAttemptHandler(this),
|
||||
headers,
|
||||
});
|
||||
|
||||
return {
|
||||
response: model,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
import type { INodeProperties, INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
export const ollamaDescription: Partial<INodeTypeDescription> = {
|
||||
credentials: [
|
||||
{
|
||||
name: 'ollamaApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
requestDefaults: {
|
||||
ignoreHttpStatusErrors: true,
|
||||
baseURL: '={{ $credentials.baseUrl.replace(new RegExp("/$"), "") }}',
|
||||
},
|
||||
};
|
||||
|
||||
export const ollamaModel: INodeProperties = {
|
||||
displayName: 'Model',
|
||||
name: 'model',
|
||||
type: 'options',
|
||||
default: 'llama3.2',
|
||||
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,
|
||||
};
|
||||
|
||||
export const ollamaOptions: INodeProperties = {
|
||||
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 the randomness of the generated text. Lower values make the output more focused and deterministic, while higher values make it more diverse and random.',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
displayName: 'Top K',
|
||||
name: 'topK',
|
||||
default: -1,
|
||||
typeOptions: { maxValue: 100, minValue: -1, numberPrecision: 1 },
|
||||
description:
|
||||
'Limits the number of highest probability vocabulary tokens to consider at each step. A higher value increases diversity but may reduce coherence. Set to -1 to disable.',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
displayName: 'Top P',
|
||||
name: 'topP',
|
||||
default: 1,
|
||||
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },
|
||||
description:
|
||||
'Chooses from the smallest possible set of tokens whose cumulative probability exceeds the probability top_p. Helps generate more human-like text by reducing repetitions.',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
displayName: 'Frequency Penalty',
|
||||
name: 'frequencyPenalty',
|
||||
type: 'number',
|
||||
default: 0.0,
|
||||
typeOptions: { minValue: 0 },
|
||||
description:
|
||||
'Adjusts the penalty for tokens that have already appeared in the generated text. Higher values discourage repetition.',
|
||||
},
|
||||
{
|
||||
displayName: 'Keep Alive',
|
||||
name: 'keepAlive',
|
||||
type: 'string',
|
||||
default: '5m',
|
||||
description:
|
||||
'Specifies the duration to keep the loaded model in memory after use. Useful for frequently used models. Format: 1h30m (1 hour 30 minutes).',
|
||||
},
|
||||
{
|
||||
displayName: 'Low VRAM Mode',
|
||||
name: 'lowVram',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to Activate low VRAM mode, which reduces memory usage at the cost of slower generation speed. Useful for GPUs with limited memory.',
|
||||
},
|
||||
{
|
||||
displayName: 'Main GPU ID',
|
||||
name: 'mainGpu',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
description:
|
||||
'Specifies the ID of the GPU to use for the main computation. Only change this if you have multiple GPUs.',
|
||||
},
|
||||
{
|
||||
displayName: 'Context Batch Size',
|
||||
name: 'numBatch',
|
||||
type: 'number',
|
||||
default: 512,
|
||||
description:
|
||||
'Sets the batch size for prompt processing. Larger batch sizes may improve generation speed but increase memory usage.',
|
||||
},
|
||||
{
|
||||
displayName: 'Context Length',
|
||||
name: 'numCtx',
|
||||
type: 'number',
|
||||
default: 2048,
|
||||
description:
|
||||
'The maximum number of tokens to use as context for generating the next token. Smaller values reduce memory usage, while larger values provide more context to the model.',
|
||||
},
|
||||
{
|
||||
displayName: 'Number of GPUs',
|
||||
name: 'numGpu',
|
||||
type: 'number',
|
||||
default: -1,
|
||||
description:
|
||||
'Specifies the number of GPUs to use for parallel processing. Set to -1 for auto-detection.',
|
||||
},
|
||||
{
|
||||
displayName: 'Max Tokens to Generate',
|
||||
name: 'numPredict',
|
||||
type: 'number',
|
||||
default: -1,
|
||||
description:
|
||||
'The maximum number of tokens to generate. Set to -1 for no limit. Be cautious when setting this to a large value, as it can lead to very long outputs.',
|
||||
},
|
||||
{
|
||||
displayName: 'Number of CPU Threads',
|
||||
name: 'numThread',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
description:
|
||||
'Specifies the number of CPU threads to use for processing. Set to 0 for auto-detection.',
|
||||
},
|
||||
{
|
||||
displayName: 'Penalize Newlines',
|
||||
name: 'penalizeNewline',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether the model will be less likely to generate newline characters, encouraging longer continuous sequences of text',
|
||||
},
|
||||
{
|
||||
displayName: 'Presence Penalty',
|
||||
name: 'presencePenalty',
|
||||
type: 'number',
|
||||
default: 0.0,
|
||||
description:
|
||||
'Adjusts the penalty for tokens based on their presence in the generated text so far. Positive values penalize tokens that have already appeared, encouraging diversity.',
|
||||
},
|
||||
{
|
||||
displayName: 'Repetition Penalty',
|
||||
name: 'repeatPenalty',
|
||||
type: 'number',
|
||||
default: 1.0,
|
||||
description:
|
||||
'Adjusts the penalty factor for repeated tokens. Higher values more strongly discourage repetition. Set to 1.0 to disable repetition penalty.',
|
||||
},
|
||||
{
|
||||
displayName: 'Use Memory Locking',
|
||||
name: 'useMLock',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to lock the model in memory to prevent swapping. This can improve performance but requires sufficient available memory.',
|
||||
},
|
||||
{
|
||||
displayName: 'Use Memory Mapping',
|
||||
name: 'useMMap',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to use memory mapping for loading the model. This can reduce memory usage but may impact performance. Recommended to keep enabled.',
|
||||
},
|
||||
{
|
||||
displayName: 'Load Vocabulary Only',
|
||||
name: 'vocabOnly',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to only load the model vocabulary without the weights. Useful for quickly testing tokenization.',
|
||||
},
|
||||
{
|
||||
displayName: 'Output Format',
|
||||
name: 'format',
|
||||
type: 'options',
|
||||
options: [
|
||||
{ name: 'Default', value: 'default' },
|
||||
{ name: 'JSON', value: 'json' },
|
||||
],
|
||||
default: 'default',
|
||||
description: 'Specifies the format of the API response',
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="241.333" height="341.333" version="1.0" viewBox="0 0 181 256"><g fill="#7D7D87"><path d="M37.7 19.5c-5.2 1.8-8.3 4.9-11.7 11.6-4.5 8.9-6.2 19.2-5.8 35.5l.3 14.2-5.8 6.1c-14.8 15.5-18.5 38.7-9.2 57.4l3.4 6.9-2 4.4c-3.4 8.2-5 16.4-5 26.3 0 10.8 1.8 19 5.8 26.2l2.6 4.8-2.1 4.9c-1.2 2.7-2.6 7.1-3.2 9.8-1.4 6.2-1.5 22.1-.1 25.7 1 2.6 1.4 2.7 7.6 2.7 7.3 0 7 .4 5.3-8.6-1.5-8.2.2-18.8 4.2-26.6 3.7-7 3.8-10.4.5-14.8-4.7-6.4-6.8-13.6-6.9-24-.1-10.3 1.4-16 6.6-26.1 3.1-6.1 2.9-8.7-1-12.2-1.1-1-3.1-4.2-4.3-7-1.9-4.2-2.4-6.9-2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.4-15 .4 0 1.8 1.5 2.9 3.3"/><path d="M77.8 119.9c-7.3 2.4-11.6 5.1-16.5 10.4-5.5 6-7.6 12-7.1 20.1.5 7.6 3.5 12.9 10.6 18.3 6.2 4.7 12.7 6.3 25.7 6.3 17.2 0 25.8-3.6 32.9-13.8 4.2-5.9 4.8-15.5 1.6-23-2.9-6.8-11.1-14.3-18.8-17.3-8-3.1-20.7-3.6-28.4-1m25.7 10c16.1 7.1 19.4 23.2 6.6 31.8-4.9 3.3-9.4 4.3-19.6 4.3s-14.7-1-19.6-4.3c-17.8-12-3.2-35.6 21.1-34.3 3.9.2 8.6 1.2 11.5 2.5"/><path d="M83.8 140.1c-2.5 1.4-2.2 4.4.7 6.7 2 1.6 2.4 2.6 1.9 4.9-.7 3.6 1.5 5.8 5.1 4.9 2.1-.5 2.5-1.2 2.5-4.6 0-2.9.5-4.2 2-5 2.7-1.5 2.7-6.6 0-7.5-1-.3-2.8-.1-4 .5-1.4.7-2.6.8-3.9 0-2.3-1.2-2.2-1.2-4.3.1m-44.1-18.9c-.9.7-2.3 3-3.2 5-2.1 5.3-.1 10.3 4.7 11.6 4.3 1.1 6 .6 9.2-2.7 4-4.1 4.3-8.1 1.1-11.9-2.1-2.5-3.4-3.2-6.4-3.2-2 0-4.5.6-5.4 1.2m89.8 2c-3.2 3.8-2.9 7.8 1.1 11.9 3.2 3.3 4.9 3.8 9.2 2.7 4.9-1.3 6.8-6.2 4.6-11.8-1.9-4.7-3.8-6-8.7-6-2.7 0-4.1.7-6.2 3.2"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
Reference in New Issue
Block a user