2023-11-29 03:13:55 -08:00
|
|
|
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
|
|
|
import {
|
|
|
|
NodeConnectionType,
|
|
|
|
type IExecuteFunctions,
|
|
|
|
type INodeType,
|
|
|
|
type INodeTypeDescription,
|
|
|
|
type SupplyData,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2024-03-07 02:36:36 -08:00
|
|
|
import { Ollama } from '@langchain/community/llms/ollama';
|
2023-11-29 03:13:55 -08:00
|
|
|
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
2024-05-12 12:12:07 -07:00
|
|
|
import { N8nLlmTracing } from '../N8nLlmTracing';
|
2024-02-26 05:20:18 -08:00
|
|
|
import { ollamaDescription, ollamaModel, ollamaOptions } from './description';
|
2023-11-29 03:13:55 -08:00
|
|
|
|
|
|
|
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'],
|
|
|
|
},
|
|
|
|
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'],
|
2024-02-26 05:20:18 -08:00
|
|
|
...ollamaDescription,
|
2023-11-29 03:13:55 -08:00
|
|
|
properties: [
|
|
|
|
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiAgent]),
|
2024-02-26 05:20:18 -08:00
|
|
|
ollamaModel,
|
|
|
|
ollamaOptions,
|
2023-11-29 03:13:55 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
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 Ollama({
|
|
|
|
baseUrl: credentials.baseUrl as string,
|
|
|
|
model: modelName,
|
|
|
|
...options,
|
2024-05-12 12:12:07 -07:00
|
|
|
callbacks: [new N8nLlmTracing(this)],
|
2023-11-29 03:13:55 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2024-05-12 12:12:07 -07:00
|
|
|
response: model,
|
2023-11-29 03:13:55 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|