* chore(pyproject.toml): update vulture dependency to version 2.11 * chore: Remove unused files and imports * Refactor legacy_custom/customs.py by removing unused nodes and chains * Refactor langflow.interface.custom.base.py by removing unused code * Refactor test_custom_component.py to import CustomComponent from langflow.custom * refactor(agents): remove AgentInitializer and OpenAIConversationalAgent components as they are no longer needed refactor(embeddings): remove client parameter from OpenAIEmbeddingsComponent as it is not used refactor(memories): change search_scope and search_type parameters in ZepMessageReaderComponent to be of type str refactor(model_specs): remove examples parameter from ChatVertexAIComponent as it is not used refactor(models): change metadata parameter type in OllamaModel to Dict for consistency refactor(VertexAiModel.py): remove examples parameter from ChatVertexAIComponent constructor to simplify the class structure refactor(MultiQueryRetriever.py): change prompt parameter type to Text for better consistency and readability refactor(JsonToolkit.py): update build method to handle both json and yaml file types for JsonToolkit creation refactor(OpenAPIToolkit.py): update build method to handle both json and yaml file types for JsonSpec creation and improve parameter naming for clarity * Format json * refactor(langflow.custom): update imports in code files to use the new langflow.custom module * chore(settings.py): remove unused settings file and related imports and classes from the project. * refactor(langflow): optimize imports in graph/__init__.py and graph/graph/base.py refactor(langflow): remove unused code and simplify logic in vertex/base.py refactor(types.py): remove unused imports and classes, clean up commented out code, and improve code readability by removing unnecessary methods and attributes refactor(utils.py): remove unused functions is_basic_type, invoke_lc_runnable, generate_result feat(load): add new functionality to load flow from JSON file or object and run flow from JSON file or object feat(load): add new modules load.py and __init__.py for loading and running flow from JSON feat(processing): remove unused functions get_result_and_steps, flush_langfuse_callback_if_present refactor(process.py): remove unused functions and imports to clean up the codebase feat(utils.py): remove unused file utils.py to declutter the project and improve maintainability test(test_loading.py): update import paths after restructuring the project folders
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
from langchain_core.documents import Document
|
|
|
|
from langflow.components import helpers
|
|
from langflow.custom.utils import build_custom_component_template
|
|
from langflow.schema import Record
|
|
|
|
|
|
def test_update_record_component():
|
|
# Arrange
|
|
update_record_component = helpers.UpdateRecordComponent()
|
|
|
|
# Act
|
|
new_data = {"new_key": "new_value"}
|
|
existing_record = Record(data={"existing_key": "existing_value"})
|
|
result = update_record_component.build(existing_record, new_data)
|
|
assert result.data == {"existing_key": "existing_value", "new_key": "new_value"}
|
|
assert result.existing_key == "existing_value"
|
|
assert result.new_key == "new_value"
|
|
|
|
|
|
def test_document_to_record_component():
|
|
# Arrange
|
|
document_to_record_component = helpers.DocumentToRecordComponent()
|
|
|
|
# Act
|
|
# Replace with your actual test data
|
|
document = Document(page_content="key: value", metadata={"url": "https://example.com"})
|
|
result = document_to_record_component.build(document)
|
|
|
|
# Assert
|
|
# Replace with your actual expected result
|
|
assert result == [Record(data={"text": "key: value", "url": "https://example.com"})]
|
|
|
|
|
|
def test_uuid_generator_component():
|
|
# Arrange
|
|
uuid_generator_component = helpers.UUIDGeneratorComponent()
|
|
uuid_generator_component.code = open(helpers.IDGenerator.__file__, "r").read()
|
|
|
|
frontend_node, _ = build_custom_component_template(uuid_generator_component)
|
|
|
|
# Act
|
|
build_config = frontend_node.get("template")
|
|
field_name = "unique_id"
|
|
build_config = uuid_generator_component.update_build_config(build_config, None, field_name)
|
|
unique_id = build_config["unique_id"]["value"]
|
|
result = uuid_generator_component.build(unique_id)
|
|
|
|
# Assert
|
|
# UUID should be a string of length 36
|
|
assert isinstance(result, str)
|
|
assert len(result) == 36
|
|
|
|
|
|
def test_records_as_text_component():
|
|
# Arrange
|
|
records_as_text_component = helpers.RecordsToTextComponent()
|
|
|
|
# Act
|
|
# Replace with your actual test data
|
|
records = [Record(data={"key": "value", "bacon": "eggs"})]
|
|
template = "Data:{data} -- Bacon:{bacon}"
|
|
result = records_as_text_component.build(records, template=template)
|
|
|
|
# Assert
|
|
# Replace with your actual expected result
|
|
assert result == "Data:{'key': 'value', 'bacon': 'eggs'} -- Bacon:eggs"
|
|
|
|
|
|
def test_text_to_record_component():
|
|
# Arrange
|
|
text_to_record_component = helpers.CreateRecordComponent()
|
|
|
|
# Act
|
|
# Replace with your actual test data
|
|
dict_with_text = {"field_1": {"key": "value"}}
|
|
result = text_to_record_component.build(number_of_fields=1, **dict_with_text)
|
|
|
|
# Assert
|
|
# Replace with your actual expected result
|
|
assert result == Record(data={"key": "value"})
|