Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(core): Tweaks for Some AI nodes (no-changelog) #7774

Merged
merged 25 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4f8ff36
:zap: fixes
michael-radency Nov 21, 2023
d95599a
:zap: chat output property renamed, output panel UI update
michael-radency Nov 22, 2023
e4ad14f
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 22, 2023
4b88a88
:zap: rlc for pinecone index
michael-radency Nov 23, 2023
d69237f
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 23, 2023
cc9ec9c
:zap: pinecone credentials test
michael-radency Nov 23, 2023
86cd053
:zap: supabase table name rlc
michael-radency Nov 23, 2023
d8ec941
:zap: openAi llm model rlc
michael-radency Nov 23, 2023
b9ba079
:zap: default expression for input update
michael-radency Nov 24, 2023
ba4025d
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 24, 2023
d84f0c6
:zap: linter fix
michael-radency Nov 24, 2023
fff6d86
:zap: test fix
michael-radency Nov 24, 2023
4a6d6d5
:zap: defaults update
michael-radency Nov 24, 2023
a707740
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 27, 2023
05acd31
:zap: error fixes and mapping
michael-radency Nov 27, 2023
48b1296
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 27, 2023
014c5ee
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 27, 2023
06c3244
:zap: editor-ui tests fix
michael-radency Nov 27, 2023
fc899c0
Merge branch 'ai-beta' of https://github.com/n8n-io/n8n into node-939…
michael-radency Nov 28, 2023
8b032b4
:zap: linter fixes
michael-radency Nov 28, 2023
b205470
:zap: zep error checking improved
michael-radency Nov 28, 2023
6d36bab
:bug: Differentiate between sub-node runNodeHint
OlegIvaniv Nov 28, 2023
435cfff
⏪️ Revert d95599a RunData changes
OlegIvaniv Nov 28, 2023
488bf3c
Merge branch 'ai-beta' into node-939-ai-node-tweaks
OlegIvaniv Nov 28, 2023
420d852
Merge remote-tracking branch 'origin/ai-beta' into node-939-ai-node-t…
netroy Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
IAuthenticateGeneric,
// ICredentialTestRequest,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand Down Expand Up @@ -38,4 +38,13 @@ export class PineconeApi implements ICredentialType {
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '=https://controller.{{$credentials.environment}}.pinecone.io/databases',
headers: {
accept: 'application/json; charset=utf-8',
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Agent implements INodeType {
name: 'agent',
icon: 'fa:robot',
group: ['transform'],
version: 1,
version: [1, 1.1],
description: 'Generates an action plan and executes it. Can use external tools.',
subtitle:
"={{ { conversationalAgent: 'Conversational Agent', openAiFunctionsAgent: 'OpenAI Functions Agent', reactAgent: 'ReAct Agent', sqlAgent: 'SQL Agent' }[$parameter.agent] }}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ export const conversationalAgentProperties: INodeProperties[] = [
displayOptions: {
show: {
agent: ['conversationalAgent'],
'@version': [1],
},
},
default: '={{ $json.input }}',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
required: true,
displayOptions: {
show: {
agent: ['conversationalAgent'],
'@version': [1.1],
},
},
default: '={{ $json.chat_input }}',
},
{
displayName: 'Options',
name: 'options',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ export const openAiFunctionsAgentProperties: INodeProperties[] = [
displayOptions: {
show: {
agent: ['openAiFunctionsAgent'],
'@version': [1],
},
},
default: '={{ $json.input }}',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
required: true,
displayOptions: {
show: {
agent: ['openAiFunctionsAgent'],
'@version': [1.1],
},
},
default: '={{ $json.chat_input }}',
},
{
displayName: 'Options',
name: 'options',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ export const planAndExecuteAgentProperties: INodeProperties[] = [
displayOptions: {
show: {
agent: ['planAndExecuteAgent'],
'@version': [1],
},
},
default: '={{ $json.input }}',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
required: true,
displayOptions: {
show: {
agent: ['planAndExecuteAgent'],
'@version': [1.1],
},
},
default: '={{ $json.chat_input }}',
},
{
displayName: 'Options',
name: 'options',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ export const reActAgentAgentProperties: INodeProperties[] = [
displayOptions: {
show: {
agent: ['reActAgent'],
'@version': [1],
},
},
default: '={{ $json.input }}',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
required: true,
displayOptions: {
show: {
agent: ['reActAgent'],
'@version': [1.1],
},
},
default: '={{ $json.chat_input }}',
},
{
displayName: 'Options',
name: 'options',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export const sqlAgentAgentProperties: INodeProperties[] = [
},
},
{
displayName: 'Top K',
displayName: 'Limit',
name: 'topK',
type: 'number',
default: 10,
description: 'Number of top results agent should return',
description: 'The maximum number of results to return',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class ChainLlm implements INodeType {
name: 'chainLlm',
icon: 'fa:link',
group: ['transform'],
version: 1,
version: [1, 1.1],
description: 'A simple chain to prompt a large language model',
defaults: {
name: 'Basic LLM Chain',
Expand Down Expand Up @@ -240,6 +240,23 @@ export class ChainLlm implements INodeType {
type: 'string',
required: true,
default: '={{ $json.input }}',
displayOptions: {
show: {
'@version': [1],
},
},
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
required: true,
default: '={{ $json.chat_input }}',
displayOptions: {
show: {
'@version': [1.1],
},
},
},
{
displayName: 'Chat Messages (if Using a Chat Model)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ChainRetrievalQa implements INodeType {
name: 'chainRetrievalQa',
icon: 'fa:link',
group: ['transform'],
version: 1,
version: [1, 1.1],
description: 'Answer questions about retrieved documents',
defaults: {
name: 'Question and Answer Chain',
Expand Down Expand Up @@ -64,6 +64,23 @@ export class ChainRetrievalQa implements INodeType {
type: 'string',
required: true,
default: '={{ $json.input }}',
displayOptions: {
show: {
'@version': [1],
},
},
},
{
displayName: 'Query',
name: 'query',
type: 'string',
required: true,
default: '={{ $json.chat_input }}',
displayOptions: {
show: {
'@version': [1.1],
},
},
},
],
};
Expand Down
107 changes: 61 additions & 46 deletions packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
import {
NodeConnectionType,
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type SupplyData,
import { NodeConnectionType } from 'n8n-workflow';
import type {
IExecuteFunctions,
INodeType,
INodeTypeDescription,
SupplyData,
IDataObject,
ILoadOptionsFunctions,
} from 'n8n-workflow';

import type { ClientOptions } from 'openai';
Expand Down Expand Up @@ -58,55 +60,33 @@ export class LmOpenAi implements INodeType {
{
displayName: 'Model',
name: 'model',
type: 'options',
type: 'resourceLocator',
default: { mode: 'list', value: 'gpt-3.5-turbo-instruct' },
required: true,
description:
'The model which will generate the completion. <a href="https://beta.openai.com/docs/models/overview">Learn more</a>.',
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '={{ $parameter.options?.baseURL?.split("/").slice(-1).pop() || "v1" }}/models',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'data',
},
},
{
type: 'filter',
properties: {
pass: "={{$responseItem.owned_by.startsWith('system')",
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.id}}',
value: '={{$responseItem.id}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
modes: [
{
displayName: 'From List',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'openAiModelSearch',
},
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
},
],
routing: {
send: {
type: 'body',
property: 'model',
value: '={{$parameter.model.value}}',
},
},
default: 'gpt-3.5-turbo-instruct',
},
{
displayName: 'Options',
Expand Down Expand Up @@ -189,10 +169,45 @@ export class LmOpenAi implements INodeType {
],
};

methods = {
listSearch: {
async openAiModelSearch(this: ILoadOptionsFunctions) {
const results = [];

const options = this.getNodeParameter('options', {}) as IDataObject;

let uri = 'https://api.openai.com/v1/models';

if (options.baseURL) {
uri = `${options.baseURL}/models`;
}

const { data } = await this.helpers.requestWithAuthentication.call(this, 'openAiApi', {
method: 'GET',
uri,
json: true,
});

for (const model of data as IDataObject[]) {
if (!(model.owned_by as string)?.startsWith('system')) continue;
results.push({
name: model.id as string,
value: model.id as string,
});
}

return { results };
},
},
};

async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
const credentials = await this.getCredentials('openAiApi');

const modelName = this.getNodeParameter('model', itemIndex) as string;
const modelName = this.getNodeParameter('model', itemIndex, '', {
extractValue: true,
}) as string;

const options = this.getNodeParameter('options', itemIndex, {}) as {
baseURL?: string;
frequencyPenalty?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MemoryBufferWindow implements INodeType {
icon: 'fa:database',
group: ['transform'],
version: 1,
description: 'Stores the chat history in a windowed buffer. Refreshes on restart.',
description: 'Stores in n8n memory, so no credentials required',
defaults: {
name: 'Window Buffer Memory',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export class OutputParserAutofixing implements INodeType {
outputs: [NodeConnectionType.AiOutputParser],
outputNames: ['Output Parser'],
properties: [
{
displayName:
'This node wraps another output parser. If the first one fails it calls an LLM to fix the format',
name: 'info',
type: 'notice',
default: '',
},
getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiAgent]),
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export class RetrieverVectorStore implements INodeType {
outputNames: ['Retriever'],
properties: [
{
displayName: 'Top K',
displayName: 'Limit',
name: 'topK',
type: 'number',
default: 4,
description: 'Number of top results to fetch from vector store',
description: 'The maximum number of results to return',
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ManualChatTrigger implements INodeType {
name: 'manualChatTrigger',
icon: 'fa:comments',
group: ['trigger'],
version: 1,
version: [1, 1.1],
description: 'Runs the flow on new manual chat message',
eventTriggerDescription: '',
maxNodes: 1,
Expand Down
Loading