Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(Basic LLM Chain Node): Refactor Basic LLM Chain & add tests #13850

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

OlegIvaniv
Copy link
Contributor

@OlegIvaniv OlegIvaniv commented Mar 12, 2025

Summary

  • Extracted logic into dedicated utility modules (chainExecutor.ts, promptUtils.ts, imageUtils.ts, responseFormatter.ts) under a new methods directory.
  • Updated the main node (ChainLlm.node.ts) to use these utility modules.
  • Consolidated repeated or duplicated functions (e.g., prompt handling, response formatting) into reusable methods.
  • Updated node properties and inputs definitions to reference new modular configuration utilities.
  • Added unit tests for the new utility modules (chainExecutor, promptUtils, imageUtils, responseFormatter).

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Mar 12, 2025
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 95.72650% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gchain/nodes/chains/ChainLLM/methods/imageUtils.ts 93.33% 1 Missing and 1 partial ⚠️
...s/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts 0.00% 2 Missing ⚠️
...ain/nodes/chains/ChainLLM/methods/chainExecutor.ts 95.45% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@burivuhster burivuhster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Just a couple of comments/questions

noDataExpression: true,
displayOptions: {
hide: {
'@version': [1, 1.1, 1.3],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 1.2 skipped intentionally here?

Comment on lines +137 to +149
name: 'AI',
value: AIMessagePromptTemplate.lc_name(),
},
{
name: 'System',
value: SystemMessagePromptTemplate.lc_name(),
},
{
name: 'User',
value: HumanMessagePromptTemplate.lc_name(),
},
],
default: SystemMessagePromptTemplate.lc_name(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using LangChain constants for values might break nodes in the future, if LangChain for some reason decides to change them and we update the langchain dependency. As users will have old values stored as node props in their workflows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see now that was already the case before refactoring, please disregard :)

});

// Ensure response is always returned as an array
return [response];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to use the same isArray check here, as in executeChain?

};

describe('imageUtils', () => {
// The dataUriFromImageData tests are already covered in the existing utils.test.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this comment, can you elaborate? utils.test.ts is deleted in this PR

}

// If multiple parsers, combine them
return new CombiningOutputParser(...outputParsers) as unknown as N8nOutputParser;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this use case a bit unreliable (something is off, at least on a logs panel). I understand it was already there before. Just wonder do we need to support this at all? Can we remove it and limit with a single parser? Seems like super-rare use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants