-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Fix: Exclude mirostat parameter when disabled in Ollama component #10201
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
Fix: Exclude mirostat parameter when disabled in Ollama component #10201
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughUpdates Ollama component to treat disabled mirostat as None instead of 0, adjusting parameter forwarding (mirostat, mirostat_eta, mirostat_tau). Adds unit tests verifying correct parameter propagation when mirostat is enabled for modes “Mirostat” and “Mirostat 2.0”. Addresses invalid-parameter issue when mirostat is disabled. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant LangFlow as LangFlow UI
participant OllamaComp as Ollama Component
participant ChatAPI as ChatOllama
User->>LangFlow: Configure model (mirostat: Disabled/Mirostat/Mirostat 2.0)
LangFlow->>OllamaComp: build_model(config)
alt mirostat Disabled (None)
Note over OllamaComp: Map mirostat=None<br/>mirostat_eta=None, mirostat_tau=None
OllamaComp->>ChatAPI: create(model, mirostat=None, eta=None, tau=None)
else mirostat = "Mirostat"
Note over OllamaComp: Map mirostat=1<br/>preserve eta/tau
OllamaComp->>ChatAPI: create(model, mirostat=1, eta, tau)
else mirostat = "Mirostat 2.0"
Note over OllamaComp: Map mirostat=2<br/>preserve eta/tau
OllamaComp->>ChatAPI: create(model, mirostat=2, eta, tau)
end
ChatAPI-->>OllamaComp: model instance
OllamaComp-->>LangFlow: return model
LangFlow-->>User: ready
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py(2 hunks)src/lfx/src/lfx/components/ollama/ollama.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
src/backend/tests/unit/components/**/*.py
📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)
src/backend/tests/unit/components/**/*.py: Mirror the component directory structure for unit tests in src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping for backward compatibility in component tests
Create comprehensive unit tests for all new components
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
{src/backend/**/*.py,tests/**/*.py,Makefile}
📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)
{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
src/backend/tests/unit/**/*.py
📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)
Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
src/backend/tests/**/*.py
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
src/backend/tests/**/*.py: Unit tests for backend code must be located in the 'src/backend/tests/' directory, with component tests organized by component subdirectory under 'src/backend/tests/unit/components/'.
Test files should use the same filename as the component under test, with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests in backend Python tests, as defined in 'src/backend/tests/conftest.py'.
When writing component tests, inherit from the appropriate base class in 'src/backend/tests/base.py' (ComponentTestBase, ComponentTestBaseWithClient, or ComponentTestBaseWithoutClient) and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping'.
Each test in backend Python test files should have a clear docstring explaining its purpose, and complex setups or mocks should be well-commented.
Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.
Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.
Test error handling and edge cases in backend Python tests, including using 'pytest.raises' and asserting error messages.
Validate input/output behavior and test component initialization and configuration in backend Python tests.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests when necessary.
Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.
Test error handling by mocking internal functions using monkeypatch in backend Python tests.
Test resource cleanup in backend Python tests by using fixtures that ensure proper initialization and cleanup of resources.
Test timeout and performance constraints in backend Python tests using 'asyncio.wait_for' and timing assertions.
Test Langflow's Messag...
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
src/backend/**/*component*.py
📄 CodeRabbit inference engine (.cursor/rules/icons.mdc)
In your Python component class, set the
iconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
src/backend/**/components/**/*.py
📄 CodeRabbit inference engine (.cursor/rules/icons.mdc)
In your Python component class, set the
iconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
**/{test_*.py,*.test.ts,*.test.tsx}
📄 CodeRabbit inference engine (coderabbit-custom-pre-merge-checks-unique-id-file-non-traceable-F7F2B60C-1728-4C9A-8889-4F2235E186CA.txt)
**/{test_*.py,*.test.ts,*.test.tsx}: Check test files for excessive use of mocks that obscure what's actually being tested
Warn when mocks replace testing real behavior/interactions
Suggest using real objects or simpler test doubles when mocks become excessive
Use mocks primarily for external dependencies, not core logic
Recommend integration tests when unit tests are overly mocked
Verify tests actually exercise the new/changed functionality (not placeholders)
Test files should use descriptive test names explaining what is being tested
Organize tests logically with proper setup/teardown
Include edge cases and error conditions for comprehensive coverage
Cover both positive and negative scenarios where appropriate
Tests should cover the main functionality being implemented
Tests should not be mere smoke tests; they must validate behavior
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
**/test_*.py
📄 CodeRabbit inference engine (coderabbit-custom-pre-merge-checks-unique-id-file-non-traceable-F7F2B60C-1728-4C9A-8889-4F2235E186CA.txt)
**/test_*.py: Backend test files must follow naming convention test_*.py
Backend tests should use proper pytest structure
For async backend functions, use proper async testing patterns with pytest
Backend tests should follow pytest conventions
For API endpoints, verify both success and error response tests are present
Files:
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
🧬 Code graph analysis (1)
src/backend/tests/unit/components/languagemodels/test_chatollama_component.py (1)
src/lfx/src/lfx/components/ollama/ollama.py (1)
build_model(144-210)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
- GitHub Check: Lint Backend / Run Mypy (3.10)
- GitHub Check: Test Docker Images / Test docker images
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
- GitHub Check: Lint Backend / Run Mypy (3.13)
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
- GitHub Check: Lint Backend / Run Mypy (3.12)
- GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
- GitHub Check: Lint Backend / Run Mypy (3.11)
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
- GitHub Check: Test Starter Templates
- GitHub Check: Run Ruff Check and Format
- GitHub Check: Update Starter Projects
🔇 Additional comments (4)
src/lfx/src/lfx/components/ollama/ollama.py (1)
149-157: LGTM! The implementation correctly handles the disabled mirostat case.The change from defaulting to
0to defaulting toNoneensures that when mirostat is "Disabled", the parameter is not sent to the Ollama API (filtered out on line 199). This fixes the issue where some Ollama models reject"mirostat": 0. The conditional logic properly preservesmirostat_etaandmirostat_tauvalues when mirostat is enabled.src/backend/tests/unit/components/languagemodels/test_chatollama_component.py (3)
58-58: LGTM! Clear documentation of the disabled behavior.The comment accurately explains that
mirostatis excluded from the API call when disabled (set toNoneand filtered out).
86-108: LGTM! Comprehensive test for Mirostat mode.This test properly verifies that when mirostat is set to "Mirostat", the correct value (
mirostat=1) and related parameters (mirostat_eta,mirostat_tau) are passed toChatOllama. The test follows best practices with clear documentation, proper mocking, and meaningful assertions.
109-130: LGTM! Comprehensive test for Mirostat 2.0 mode.This test properly verifies that when mirostat is set to "Mirostat 2.0", the correct value (
mirostat=2) and related parameters (mirostat_eta=0.2,mirostat_tau=10.0) are passed toChatOllama. The test follows best practices with clear documentation, proper mocking, and meaningful assertions.
| # Mapping mirostat settings to their corresponding values | ||
| mirostat_options = {"Mirostat": 1, "Mirostat 2.0": 2} | ||
|
|
||
| # Default to 0 for 'Disabled' |
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.
Update the outdated comment.
The comment states "Default to 0 for 'Disabled'" but the code now uses None as the default value (line 149). Update the comment to reflect the current behavior.
Apply this diff to update the comment:
- # Default to 0 for 'Disabled'
+ # Default to None for 'Disabled' (will be filtered out before sending to API)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Default to 0 for 'Disabled' | |
| # Default to None for 'Disabled' (will be filtered out before sending to API) |
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/ollama/ollama.py around line 148, the inline
comment "Default to 0 for 'Disabled'" is outdated because the code now uses None
as the default; update the comment to reflect that the default is None (meaning
'Disabled' or unset) so it matches current behavior and avoid confusion.
- Set mirostat to None instead of 0 when disabled - Ensures parameter is not sent to Ollama API - Update test to verify mirostat is excluded when disabled - Add tests for mirostat enabled states (1 and 2) Fixes langflow-ai#8666
790595b to
025abab
Compare
|
erichare
left a comment
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.
LGTM! Nice work @HzaRashid
…ngflow-ai#10201) * Fix: Exclude mirostat parameter when disabled in Ollama component - Set mirostat to None instead of 0 when disabled - Ensures parameter is not sent to Ollama API - Update test to verify mirostat is excluded when disabled - Add tests for mirostat enabled states (1 and 2) Fixes langflow-ai#8666 * correct inline comment * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes --------- Co-authored-by: Hamza Rashid <[email protected]> Co-authored-by: Eric Hare <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>



Description
Fixes #8666
When using the Ollama component with
mirostatset to "Disabled", the integration was sending"mirostat": 0to the Ollama API, which caused errors with certain models and Ollama versions. This PR fixes the issue by settingmirostattoNonewhen disabled, ensuring it gets filtered out and is not sent to the API.Changes
Code Changes
src/lfx/src/lfx/components/ollama/ollama.pymirostat_valuedefault from0toNonewhen "Disabled" is selectedif mirostat_value is Noneinstead ofif mirostat_value == 0Test Changes
src/backend/tests/unit/components/languagemodels/test_chatollama_component.pymirostat=0fromtest_build_modelassertion (parameter is now excluded when disabled)test_build_model_with_mirostat_enabledto verifymirostat=1is passed when "Mirostat" is selectedtest_build_model_with_mirostat_2_enabledto verifymirostat=2is passed when "Mirostat 2.0" is selectedRoot Cause
The Ollama Python client defines
mirostatasOptional[int] = None, meaning the default/disabled state should beNone, not0. While0is technically valid according to Ollama's documentation (0=disabled, 1=Mirostat, 2=Mirostat 2.0), some models reject"mirostat": 0as an invalid option. The safest approach is to omit the parameter entirely when disabled, matching the official client's behavior.Testing
mirostatparameter is excluded from API calls when disabledmirostat=1andmirostat=2are correctly passed when enabledBefore / After
Before:
After:
Summary by CodeRabbit
Bug Fixes
Tests