refactor: Update langflow components and constants
Update langflow components and constants to improve functionality, error handling, and user experience. This includes fixing rendering issues in dropdownComponent and improving value handling in tableNodeCellRender. The MonitorService now supports read-only mode in the exec_query method. The APIRequestComponent has been enhanced to parse curl commands and update the build configuration accordingly. The URLComponent now includes metadata in the returned data objects. Additionally, the SessionView and MessagesPage components have been updated to sort columns using the messagesSorter utility function, ensuring consistent column ordering. The unused Tabs component has been removed from FlowLogsModal. The CHAT_FIRST_INITIAL_TEXT and CHAT_SECOND_INITIAL_TEXT constants have been updated. Lastly, the error message in the Vertex class of base.py has been improved for building Components. These changes enhance the overall performance, functionality, and clarity of the codebase.
This commit is contained in:
parent
18c4bebd57
commit
909501e212
9 changed files with 251 additions and 234 deletions
|
|
@ -13,7 +13,7 @@ from langflow.components import data
|
|||
@pytest.fixture
|
||||
def api_request():
|
||||
# This fixture provides an instance of APIRequest for each test case
|
||||
return data.APIRequest()
|
||||
return data.APIRequestComponent()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -102,7 +102,13 @@ async def test_build_with_multiple_urls(api_request):
|
|||
#
|
||||
|
||||
# Execute the build method
|
||||
results = await api_request.build(method=method, urls=urls)
|
||||
api_request.set_attributes(
|
||||
{
|
||||
"method": method,
|
||||
"urls": urls,
|
||||
}
|
||||
)
|
||||
results = await api_request.make_requests()
|
||||
|
||||
# Assertions
|
||||
assert len(results) == len(urls)
|
||||
|
|
@ -131,15 +137,18 @@ def test_directory_component_build_with_multithreading(
|
|||
mock_parallel_load_data.return_value = [Mock()]
|
||||
|
||||
# Act
|
||||
directory_component.build(
|
||||
path,
|
||||
depth,
|
||||
max_concurrency,
|
||||
load_hidden,
|
||||
recursive,
|
||||
silent_errors,
|
||||
use_multithreading,
|
||||
directory_component.set_attributes(
|
||||
{
|
||||
"path": path,
|
||||
"depth": depth,
|
||||
"max_concurrency": max_concurrency,
|
||||
"load_hidden": load_hidden,
|
||||
"recursive": recursive,
|
||||
"silent_errors": silent_errors,
|
||||
"use_multithreading": use_multithreading,
|
||||
}
|
||||
)
|
||||
directory_component.load_directory()
|
||||
|
||||
# Assert
|
||||
mock_resolve_path.assert_called_once_with(path)
|
||||
|
|
@ -160,7 +169,8 @@ def test_directory_without_mocks():
|
|||
# the directory component can be used to load the projects
|
||||
# and we can validate if the contents are the same as the projects variable
|
||||
setup_path = Path(setup.__file__).parent / "starter_projects"
|
||||
results = directory_component.build(str(setup_path), use_multithreading=False)
|
||||
directory_component.set_attributes({"path": str(setup_path), "use_multithreading": False})
|
||||
results = directory_component.load_directory()
|
||||
assert len(results) == len(projects)
|
||||
# each result is a Data that contains the content attribute
|
||||
# each are dict that are exactly the same as one of the projects
|
||||
|
|
@ -170,16 +180,19 @@ def test_directory_without_mocks():
|
|||
# in ../docs/docs/components there are many mdx files
|
||||
# check if the directory component can load them
|
||||
# just check if the number of results is the same as the number of files
|
||||
directory_component = data.DirectoryComponent()
|
||||
docs_path = Path(__file__).parent.parent / "docs" / "docs" / "components"
|
||||
results = directory_component.build(str(docs_path), use_multithreading=False)
|
||||
directory_component.set_attributes({"path": str(docs_path), "use_multithreading": False})
|
||||
results = directory_component.load_directory()
|
||||
docs_files = list(docs_path.glob("*.mdx"))
|
||||
assert len(results) == len(docs_files)
|
||||
|
||||
|
||||
def test_url_component():
|
||||
url_component = data.URLComponent()
|
||||
url_component.set_attributes({"urls": ["https://langflow.org"]})
|
||||
# the url component can be used to load the contents of a website
|
||||
_data = url_component.build(["https://langflow.org"])
|
||||
_data = url_component.fetch_content()
|
||||
assert all(value.data for value in _data)
|
||||
assert all(value.text for value in _data)
|
||||
assert all(value.content for value in _data)
|
||||
assert all(value.source for value in _data)
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ def test_get_all(client: TestClient, logged_in_headers):
|
|||
files
|
||||
) # Less or equal because we might have some files that don't have the dependencies installed
|
||||
assert "ChatInput" in json_response["inputs"]
|
||||
assert "Prompt" in json_response["inputs"]
|
||||
assert "Prompt" in json_response["prompts"]
|
||||
assert "ChatOutput" in json_response["outputs"]
|
||||
|
||||
|
||||
|
|
@ -480,7 +480,7 @@ def test_successful_run_with_output_type_text(client, starter_project, created_a
|
|||
display_names = [output.get("component_display_name") for output in outputs_dict.get("outputs")]
|
||||
assert all([name in display_names for name in ["Chat Output"]]), display_names
|
||||
inner_results = [output.get("results") for output in outputs_dict.get("outputs")]
|
||||
expected_keys = ["Data", "Message"]
|
||||
expected_keys = ["message"]
|
||||
assert all([key in result for result in inner_results for key in expected_keys]), outputs_dict
|
||||
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ def test_successful_run_with_output_type_any(client, starter_project, created_ap
|
|||
display_names = [output.get("component_display_name") for output in outputs_dict.get("outputs")]
|
||||
assert all([name in display_names for name in ["Chat Output"]]), display_names
|
||||
inner_results = [output.get("results") for output in outputs_dict.get("outputs")]
|
||||
expected_keys = ["Data", "Message"]
|
||||
expected_keys = ["message"]
|
||||
assert all([key in result for result in inner_results for key in expected_keys]), outputs_dict
|
||||
|
||||
|
||||
|
|
@ -600,7 +600,7 @@ def test_successful_run_with_input_type_chat(client, starter_project, created_ap
|
|||
assert len(chat_input_outputs) == 1
|
||||
# Now we check if the input_value is correct
|
||||
assert all(
|
||||
[output.get("results").get("Message").get("result") == "value1" for output in chat_input_outputs]
|
||||
[output.get("results").get("message").get("text") == "value1" for output in chat_input_outputs]
|
||||
), chat_input_outputs
|
||||
|
||||
|
||||
|
|
@ -636,7 +636,7 @@ def test_successful_run_with_input_type_any(client, starter_project, created_api
|
|||
assert len(any_input_outputs) == 1
|
||||
# Now we check if the input_value is correct
|
||||
assert all(
|
||||
[output.get("results").get("Message").get("result") == "value1" for output in any_input_outputs]
|
||||
[output.get("results").get("message").get("text") == "value1" for output in any_input_outputs]
|
||||
), any_input_outputs
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ def test_template_field_defaults(sample_template_field: Input):
|
|||
assert sample_template_field.is_list is False
|
||||
assert sample_template_field.show is True
|
||||
assert sample_template_field.multiline is False
|
||||
assert sample_template_field.value == ""
|
||||
assert sample_template_field.value is None
|
||||
assert sample_template_field.file_types == []
|
||||
assert sample_template_field.file_path == ""
|
||||
assert sample_template_field.password is False
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from typing import Union
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from langflow.template import Input, Output
|
||||
from langflow.template.field.base import UNDEFINED
|
||||
from langflow.type_extraction.type_extraction import post_process_type
|
||||
from pydantic import ValidationError
|
||||
|
||||
|
||||
@pytest.fixture(name="client", autouse=True)
|
||||
|
|
@ -56,6 +57,10 @@ class TestInput:
|
|||
"password": False,
|
||||
"advanced": False,
|
||||
"title_case": False,
|
||||
"dynamic": False,
|
||||
"info": "",
|
||||
"input_types": ["Text"],
|
||||
"load_from_db": False,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue