-
-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Feature/add user parameter support to LiteLLM node #6121
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
Open
jwp83
wants to merge
3
commits into
FlowiseAI:main
Choose a base branch
from
jwp83:feature/add-litellm-user-param
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
packages/components/nodes/chatmodels/ChatLitellm/ChatLitellm.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { INodeData } from '../../../src/Interface' | ||
| import { ChatOpenAI } from '../ChatOpenAI/FlowiseChatOpenAI' | ||
|
|
||
| // Import the target node class for testing | ||
| const { nodeClass } = require('./ChatLitellm') | ||
|
|
||
| // Mock external utility functions | ||
| jest.mock('../../../src/utils', () => ({ | ||
| getBaseClasses: jest.fn().mockReturnValue(['BaseChatModel', 'ChatLitellm']), | ||
| getCredentialData: jest.fn().mockResolvedValue({}), | ||
| getCredentialParam: jest.fn().mockReturnValue('sk-test-api-key') | ||
| })) | ||
|
|
||
| // Mock FlowiseChatOpenAI class to prevent actual API calls and verify passed parameters | ||
| jest.mock('../ChatOpenAI/FlowiseChatOpenAI', () => { | ||
| return { | ||
| ChatOpenAI: jest.fn().mockImplementation((id, obj) => { | ||
| return { | ||
| id, | ||
| obj, // Expose the injected parameters for testing | ||
| setMultiModalOption: jest.fn() | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| describe('ChatLitellm_ChatModels', () => { | ||
| let node: any | ||
|
|
||
| beforeEach(() => { | ||
| node = new nodeClass() | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('should initialize with correct properties and inputs', () => { | ||
| expect(node.label).toBe('LiteLLM') | ||
| expect(node.name).toBe('chatLitellm') | ||
| expect(node.type).toBe('ChatLitellm') | ||
|
|
||
| // Verify that the newly added 'user' field exists in the inputs array | ||
| const userInput = node.inputs.find((input: any) => input.name === 'user') | ||
| expect(userInput).toBeDefined() | ||
| expect(userInput.type).toBe('string') | ||
| expect(userInput.additionalParams).toBe(true) | ||
| }) | ||
|
|
||
| it('should initialize the model with basic required parameters', async () => { | ||
| const nodeData: INodeData = { | ||
| id: 'test-node-id', | ||
| inputs: { | ||
| modelName: 'vertex-gemini-2.5-flash', | ||
| temperature: '0.7' | ||
| } | ||
| } as any | ||
|
|
||
| const model = await node.init(nodeData, '', {}) | ||
|
|
||
| expect(ChatOpenAI).toHaveBeenCalledTimes(1) | ||
| expect(model.id).toBe('test-node-id') | ||
|
|
||
| // Check basic parameter mapping | ||
| expect(model.obj.modelName).toBe('vertex-gemini-2.5-flash') | ||
| expect(model.obj.temperature).toBe(0.7) | ||
| expect(model.obj.streaming).toBe(true) // Default fallback | ||
| expect(model.obj.openAIApiKey).toBe('sk-test-api-key') | ||
| }) | ||
|
|
||
| it('should properly map advanced parameters including the new "user" parameter', async () => { | ||
| const nodeData: INodeData = { | ||
| id: 'test-node-id', | ||
| inputs: { | ||
| modelName: 'vertex-gemini-2.5-flash', | ||
| temperature: '0.5', | ||
| streaming: false, | ||
| maxTokens: '1024', | ||
| topP: '0.9', | ||
| timeout: '5000', | ||
| user: 'test01', // Added User ID | ||
| basePath: 'http://localhost:4000/v1', | ||
| allowImageUploads: true | ||
| } | ||
| } as any | ||
|
|
||
| const model = await node.init(nodeData, '', {}) | ||
|
|
||
| expect(ChatOpenAI).toHaveBeenCalledTimes(1) | ||
|
|
||
| // Check advanced parameter and user data mapping | ||
| expect(model.obj.user).toBe('test01') | ||
| expect(model.obj.maxTokens).toBe(1024) | ||
| expect(model.obj.topP).toBe(0.9) | ||
| expect(model.obj.timeout).toBe(5000) | ||
| expect(model.obj.streaming).toBe(false) | ||
|
|
||
| // Check Base URL configuration | ||
| expect(model.obj.configuration?.baseURL).toBe('http://localhost:4000/v1') | ||
|
|
||
| // Check multimodal option call | ||
| expect(model.setMultiModalOption).toHaveBeenCalledWith({ | ||
| image: { | ||
| allowImageUploads: true | ||
| } | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a
descriptionfor theuserparameter is recommended to clarify its purpose for end-users (e.g., for tracking or rate-limiting). Also, using a more descriptiveplaceholderlike'user-1234'is consistent with other LLM nodes in the repository.