feat: Add suggestion message to API exception response (#3149)

* feat: suggest updating outdated components in API exception handling

Suggest updating the outdated components in the API exception handling. This commit adds a suggestion message to the API exception response when there are outdated components in the flow. The suggestion message provides the number of outdated components and recommends updating them. The suggestion is generated based on the list of outdated components obtained from the flow data.

* feat: refactor code

* [autofix.ci] apply automated fixes

* Update src/backend/base/langflow/exceptions/api.py

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* Update src/backend/base/langflow/api/utils.py

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* Update src/backend/base/langflow/exceptions/api.py

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* update function name

* [autofix.ci] apply automated fixes

* refactor: fix import casing in langflow.api.utils and langflow.exceptions.api

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* refactor: remove unused code and update exception handling in langflow.api.utils and langflow.exceptions.api

* [autofix.ci] apply automated fixes

* refactor: update exception handling and class  in langflow.api.utils and langflow.exceptions.api

* [autofix.ci] apply automated fixes

* update function name and refactor none flow logic

* [autofix.ci] apply automated fixes

* refactor: fix typo in get_suggestion_message function name

* refactor: improve get_suggestion_message function in langflow.api.utils

* refactor: add unit tests for get_suggestion_message and get_outdated_components functions

* refactor: add unit tests for APIException in langflow.exceptions.api

* refactor: improve test coverage for APIException and related functions

* [autofix.ci] apply automated fixes

* update file name

* refactor: update build_exception_body method in APIException to handle Exception type

* refactor: handle None flow data in get_components_versions

* [autofix.ci] apply automated fixes

* refactor: update useDeleteBuilds function signature in _builds API query

* fix: Fix test changing screen before request ended

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
anovazzi1 2024-08-07 12:26:24 -03:00 committed by GitHub
commit 48ffdbf760
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 172 additions and 3 deletions

View file

@ -0,0 +1,41 @@
from langflow.api.utils import get_suggestion_message
from unittest.mock import patch
from langflow.services.database.models.flow.utils import get_outdated_components
from langflow.utils.version import get_version_info
def test_get_suggestion_message():
# Test case 1: No outdated components
assert get_suggestion_message([]) == "The flow contains no outdated components."
# Test case 2: One outdated component
assert (
get_suggestion_message(["component1"])
== "The flow contains 1 outdated component. We recommend updating the following component: component1."
)
# Test case 3: Multiple outdated components
outdated_components = ["component1", "component2", "component3"]
expected_message = "The flow contains 3 outdated components. We recommend updating the following components: component1, component2, component3."
assert get_suggestion_message(outdated_components) == expected_message
def test_get_outdated_components():
# Mock data
flow = "mock_flow"
version = get_version_info()["version"]
mock_component_versions = {
"component1": version,
"component2": version,
"component3": "2.0",
}
# Expected result
expected_outdated_components = ["component3"]
with patch(
"langflow.services.database.models.flow.utils.get_components_versions", return_value=mock_component_versions
):
# Call the function with the mock flow
result = get_outdated_components(flow)
# Assert the result is as expected
assert result == expected_outdated_components