chore: remove unused files and update imports (#1967)

* 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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-05-24 13:13:38 -07:00 • committed by GitHub
commit 4ebfd59b1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
206 changed files with 6311 additions and 11113 deletions

View file

@ -1,52 +0,0 @@
from typing import Dict, List
import pytest
from langflow.interface.agents.base import AgentCreator
from langflow.interface.base import LangChainTypeCreator
@pytest.fixture
def sample_lang_chain_type_creator() -> LangChainTypeCreator:
class SampleLangChainTypeCreator(LangChainTypeCreator):
type_name: str = "test_type"
def type_to_loader_dict(self) -> Dict: # type: ignore
return {"test_type": "TestClass"}
def to_list(self) -> List[str]:
return ["node1", "node2"]
def get_signature(self, name: str) -> Dict:
return {
"template": {"test_field": {"type": "str"}},
"description": "test description",
"base_classes": ["base_class1", "base_class2"],
}
return SampleLangChainTypeCreator()
@pytest.fixture
def sample_agent_creator() -> AgentCreator:
return AgentCreator()
def test_lang_chain_type_creator_to_dict(
client,
sample_lang_chain_type_creator: LangChainTypeCreator,
):
type_dict = sample_lang_chain_type_creator.to_dict()
assert len(type_dict) == 1
assert "test_type" in type_dict
assert "node1" in type_dict["test_type"]
assert "node2" in type_dict["test_type"]
assert "template" in type_dict["test_type"]["node1"]
assert "description" in type_dict["test_type"]["node1"]
assert "base_classes" in type_dict["test_type"]["node1"]
def test_agent_creator_type_to_loader_dict(sample_agent_creator: AgentCreator):
type_to_loader_dict = sample_agent_creator.type_to_loader_dict
assert len(type_to_loader_dict) > 0
assert "JsonAgent"

View file

@ -5,14 +5,14 @@ from uuid import uuid4
import pytest
from langchain_core.documents import Document
from langflow.interface.custom.base import CustomComponent
from langflow.interface.custom.code_parser.code_parser import CodeParser, CodeSyntaxError
from langflow.interface.custom.custom_component.component import Component, ComponentCodeNullError
from langflow.custom import CustomComponent
from langflow.custom.code_parser.code_parser import CodeParser, CodeSyntaxError
from langflow.custom.custom_component.component import Component, ComponentCodeNullError
from langflow.services.database.models.flow import Flow, FlowCreate
code_default = """
from langflow.field_typing import Prompt
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langchain.chains import LLMChain

View file

@ -1,33 +0,0 @@
# Test this:
import pytest
from langflow.interface.custom.utils import get_function
from langflow.interface.tools.custom import PythonFunction, PythonFunctionTool
from langflow.utils import constants
def test_python_function_tool():
"""Test Python function"""
code = constants.DEFAULT_PYTHON_FUNCTION
func = get_function(code)
func = PythonFunctionTool(name="Test", description="Testing", code=code, func=func)
assert func("text") == "text"
# the tool decorator should raise an error if
# the function is not str -> str
# This raises ValidationError
with pytest.raises(SyntaxError):
code = pytest.CODE_WITH_SYNTAX_ERROR
func = get_function(code)
func = PythonFunctionTool(name="Test", description="Testing", code=code, func=func)
def test_python_function():
"""Test Python function"""
func = PythonFunction(code=constants.DEFAULT_PYTHON_FUNCTION)
assert get_function(func.code)("text") == "text"
# the tool decorator should raise an error if
# the function is not str -> str
# This raises ValidationError
with pytest.raises(SyntaxError):
func = PythonFunction(code=pytest.CODE_WITH_SYNTAX_ERROR)

View file

@ -4,10 +4,8 @@ from uuid import UUID, uuid4
import pytest
from fastapi import status
from fastapi.testclient import TestClient
from langflow.interface.custom.directory_reader.directory_reader import DirectoryReader
from langflow.custom.directory_reader.directory_reader import DirectoryReader
from langflow.services.deps import get_settings_service
from langflow.template.frontend_node.chains import TimeTravelGuideChainNode
def run_post(client, flow_id, headers, post_data):
@ -271,7 +269,7 @@ def test_get_all(client: TestClient, logged_in_headers):
all_names = [component_name for _, components in response.json().items() for component_name in components]
json_response = response.json()
# We need to test the custom nodes
assert len(all_names) > len(files)
assert len(all_names) == len(files)
assert "ChatInput" in json_response["inputs"]
assert "Prompt" in json_response["inputs"]
assert "ChatOutput" in json_response["outputs"]
@ -385,7 +383,6 @@ def test_invalid_prompt(client: TestClient):
],
)
def test_various_prompts(client, prompt, expected_input_variables):
TimeTravelGuideChainNode().to_dict()
PROMPT_REQUEST["template"] = prompt
response = client.post("api/v1/validate/prompt", json=PROMPT_REQUEST)
assert response.status_code == 200

View file

@ -1,6 +1,7 @@
from langchain_core.documents import Document
from langflow.components import helpers
from langflow.interface.custom.utils import build_custom_component_template
from langflow.custom.utils import build_custom_component_template
from langflow.schema import Record

View file

@ -2,7 +2,7 @@ import pytest
from langflow.graph import Graph
from langflow.graph.schema import RunOutputs
from langflow.initial_setup.setup import load_starter_projects
from langflow.processing.load import load_flow_from_json, run_flow_from_json
from langflow.load import load_flow_from_json, run_flow_from_json
@pytest.mark.noclient