mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 17:14:05 -08:00
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
|
import {
|
|
NodeConnectionType,
|
|
type INodeType,
|
|
type INodeTypeDescription,
|
|
type ISupplyDataFunctions,
|
|
type SupplyData,
|
|
} from 'n8n-workflow';
|
|
|
|
import { Ollama } from '@langchain/community/llms/ollama';
|
|
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
|
import { N8nLlmTracing } from '../N8nLlmTracing';
|
|
import { ollamaDescription, ollamaModel, ollamaOptions } from './description';
|
|
|
|
export class LmOllama implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Ollama Model',
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased
|
|
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/',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
// 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'],
|
|
...ollamaDescription,
|
|
properties: [
|
|
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.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 model = new Ollama({
|
|
baseUrl: credentials.baseUrl as string,
|
|
model: modelName,
|
|
...options,
|
|
callbacks: [new N8nLlmTracing(this)],
|
|
});
|
|
|
|
return {
|
|
response: model,
|
|
};
|
|
}
|
|
}
|