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: improve maintainability and testability of Vertex.build_params #5808

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Jan 20, 2025

This pull request introduces significant changes to the langflow project, focusing on refactoring the parameter handling logic in vertices and adding comprehensive tests for the new functionality. The most important changes include the introduction of a new ParameterHandler class, refactoring the build_params method to use this new class, and adding tests to ensure the correctness of the new implementation.

Refactoring and Code Simplification:

  • Introduction of ParameterHandler class:

    • Created a new ParameterHandler class in src/backend/base/langflow/graph/vertex/param_handler.py to handle parameter processing for vertices. This class centralizes the logic for processing edge and field parameters, improving code organization and maintainability.
  • Refactoring build_params method:

    • Refactored the build_params method in src/backend/base/langflow/graph/vertex/base.py to utilize the new ParameterHandler class for processing edge and field parameters. This change simplifies the parameter handling logic and reduces code duplication.

Code Cleanup:

  • Removed unused imports:
    • Cleaned up the src/backend/base/langflow/graph/vertex/base.py file by removing unused imports such as ast, os, and pandas.

Documentation:

  • Added module-level docstrings:
    • Added docstrings to various test modules to provide a clear description of their purpose. This includes files like src/backend/tests/__init__.py, src/backend/tests/unit/__init__.py, src/backend/tests/unit/graph/__init__.py, and src/backend/tests/unit/graph/vertex/__init__.py. [1] [2] [3] [4]

Testing:

  • New tests for ParameterHandler:
    • Added a new test module src/backend/tests/unit/graph/vertex/test_vertex_base.py to verify the functionality of the ParameterHandler class. This includes tests for edge parameter processing, file field processing, field skipping logic, non-list edge parameter processing, and handling optional fields.

@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 20, 2025
Copy link

codspeed-hq bot commented Jan 20, 2025

CodSpeed Performance Report

Merging #5808 will degrade performances by 91.15%

Comparing refactor-build-params (0ae4c42) with main (25ca57f)

Summary

⚡ 2 improvements
❌ 2 regressions
✅ 5 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main refactor-build-params Change
test_build_flow 387.4 ms 4,375.6 ms -91.15%
test_successful_run_with_input_type_any 348.6 ms 271.6 ms +28.39%
test_successful_run_with_input_type_text 250.1 ms 341.3 ms -26.72%
test_successful_run_with_output_type_any 4,155.5 ms 245.3 ms ×17

@ogabrielluiz ogabrielluiz force-pushed the refactor-build-params branch from 331dc58 to 0ae4c42 Compare January 20, 2025 16:56
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 20, 2025
…ng names

- Introduced a new OpenAIModelComponent class to facilitate text generation using OpenAI's language models.
- Implemented various input fields including max_tokens, model_kwargs, json_mode, model_name, openai_api_base, api_key, temperature, and seed for enhanced configurability.
- Added methods for building the model and handling exceptions from OpenAI API calls.
- This component enhances the existing framework by integrating OpenAI's capabilities, allowing users to generate text with customizable parameters.
…_model

- Changed import statements in model_input_constants.py, __init__.py, and test_tool_calling_agent.py to reflect the new OpenAIModelComponent location.
- This refactor improves code organization and clarity by ensuring consistent usage of the updated component structure.
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 20, 2025
- Introduced a ValueError exception for invalid field types in the ParameterHandler class.
- This change enhances robustness by ensuring that only valid field types are processed, improving error reporting for developers.
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 20, 2025
@ogabrielluiz ogabrielluiz requested a review from Copilot January 20, 2025 18:06

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (5)
  • src/backend/tests/unit/graph/init.py: Evaluated as low risk
  • src/backend/base/langflow/components/models/init.py: Evaluated as low risk
  • src/backend/tests/unit/components/agents/test_tool_calling_agent.py: Evaluated as low risk
  • src/backend/base/langflow/graph/vertex/base.py: Evaluated as low risk
  • src/backend/base/langflow/base/models/model_input_constants.py: Evaluated as low risk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Maintenance tasks and housekeeping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant