refactor: separating modules to fix circular import
This commit is contained in:
parent
9918e466d4
commit
c2d4d3e9c0
18 changed files with 36 additions and 35 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from langflow.node import nodes
|
||||
from langflow.template import nodes
|
||||
|
||||
|
||||
CUSTOM_NODES = {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@
|
|||
from copy import deepcopy
|
||||
import types
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from langflow.utils import payload
|
||||
from langflow.interface.listing import ALL_TYPES_DICT, ALL_TOOLS_NAMES, TOOLS_DICT
|
||||
from langflow.interface import loading
|
||||
from langflow.utils import payload, util
|
||||
from langflow.interface.listing import ALL_TYPES_DICT
|
||||
from langflow.utils.constants import ALL_TOOLS_NAMES
|
||||
|
||||
|
||||
class Node:
|
||||
|
|
@ -139,7 +138,7 @@ class Node:
|
|||
# and return the instance
|
||||
for base_type, value in ALL_TYPES_DICT.items():
|
||||
if base_type == "tools":
|
||||
value = util.get_tools_dict()
|
||||
value = TOOLS_DICT
|
||||
|
||||
if self.node_type in value:
|
||||
self._built_object = loading.instantiate_class(
|
||||
0
src/backend/langflow/graph/utils.py
Normal file
0
src/backend/langflow/graph/utils.py
Normal file
7
src/backend/langflow/interface/importing/__init__.py
Normal file
7
src/backend/langflow/interface/importing/__init__.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from langflow.interface.importing.utils import import_by_type # noqa: F401
|
||||
|
||||
# This module is used to import any langchain class by name.
|
||||
|
||||
ALL = [
|
||||
"import_by_type",
|
||||
]
|
||||
|
|
@ -7,7 +7,14 @@ from langflow.interface.custom_lists import (
|
|||
)
|
||||
from langflow.settings import settings
|
||||
from langflow.utils import util
|
||||
from langflow.utils.constants import ALL_TOOLS_NAMES
|
||||
from langchain.agents.load_tools import get_all_tool_names
|
||||
from langchain.agents import Tool
|
||||
from langflow.interface.custom_types import PythonFunction
|
||||
|
||||
|
||||
CUSTOM_TOOLS = {"Tool": Tool, "PythonFunction": PythonFunction}
|
||||
TOOLS_DICT = util.get_tools_dict()
|
||||
ALL_TOOLS_NAMES = set(get_all_tool_names() + list(CUSTOM_TOOLS.keys()))
|
||||
|
||||
|
||||
def get_type_dict():
|
||||
|
|
@ -51,9 +58,9 @@ def list_tools():
|
|||
|
||||
tools = []
|
||||
|
||||
for tool in list(ALL_TOOLS_NAMES):
|
||||
for tool in ALL_TOOLS_NAMES:
|
||||
tool_params = util.get_tool_params(util.get_tool_by_name(tool))
|
||||
if tool_params and tool_params["name"] in settings.tools or settings.dev:
|
||||
if tool_params and tool_params.get("name") in settings.tools or settings.dev:
|
||||
tools.append(tool_params["name"])
|
||||
|
||||
# Add Tool
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ from langchain.agents.load_tools import (
|
|||
_LLM_TOOLS,
|
||||
)
|
||||
from langchain.agents import agent as agent_module
|
||||
from langflow.utils.graph import Graph
|
||||
|
||||
from langflow.interface.importing import import_by_type
|
||||
|
||||
from langflow.interface.importing.utils import import_by_type
|
||||
|
||||
from langchain.agents import ZeroShotAgent
|
||||
from langchain.agents.loading import load_agent_from_config
|
||||
|
|
@ -61,6 +61,8 @@ def load_flow_from_json(path: str):
|
|||
|
||||
|
||||
def extract_json(data_graph):
|
||||
from langflow.graph.graph import Graph
|
||||
|
||||
nodes = data_graph["nodes"]
|
||||
# Substitute ZeroShotPrompt with PromptTemplate
|
||||
nodes = replace_zero_shot_prompt_with_prompt_template(nodes)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import Any, Dict
|
|||
|
||||
from langflow.interface import loading
|
||||
from langflow.utils import payload
|
||||
from langflow.utils.graph import Graph
|
||||
from langflow.graph.graph import Graph
|
||||
|
||||
|
||||
def process_data_graph(data_graph: Dict[str, Any]):
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ from langflow.interface.custom_lists import (
|
|||
llm_type_to_cls_dict,
|
||||
memory_type_to_cls_dict,
|
||||
)
|
||||
from langflow.node.template import Field, Template
|
||||
from langflow.interface.listing import CUSTOM_TOOLS, ALL_TOOLS_NAMES
|
||||
from langflow.template.template import Field, Template
|
||||
from langflow.utils import util
|
||||
from langflow.utils.constants import ALL_TOOLS_NAMES, CUSTOM_TOOLS
|
||||
|
||||
|
||||
def get_signature(name: str, object_type: str):
|
||||
|
|
|
|||
0
src/backend/langflow/template/__init__.py
Normal file
0
src/backend/langflow/template/__init__.py
Normal file
|
|
@ -1,4 +1,4 @@
|
|||
from langflow.node.template import Field, FrontendNode, Template
|
||||
from langflow.template.template import Field, FrontendNode, Template
|
||||
from langchain.agents.mrkl import prompt
|
||||
from langflow.utils.constants import DEFAULT_PYTHON_FUNCTION
|
||||
|
||||
|
|
@ -1,7 +1,3 @@
|
|||
from langchain.agents import Tool
|
||||
from langflow.interface.custom_types import PythonFunction
|
||||
from langchain.agents.load_tools import get_all_tool_names
|
||||
|
||||
OPENAI_MODELS = [
|
||||
"text-davinci-003",
|
||||
"text-davinci-002",
|
||||
|
|
@ -11,11 +7,8 @@ OPENAI_MODELS = [
|
|||
]
|
||||
CHAT_OPENAI_MODELS = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]
|
||||
|
||||
CUSTOM_TOOLS = {"Tool": Tool, "PythonFunction": PythonFunction}
|
||||
|
||||
DEFAULT_PYTHON_FUNCTION = """
|
||||
def python_function(text: str) -> str:
|
||||
return text
|
||||
"""
|
||||
|
||||
ALL_TOOLS_NAMES = set(get_all_tool_names() + list(CUSTOM_TOOLS.keys()))
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from langchain.agents.load_tools import (
|
|||
|
||||
from langchain.agents.tools import Tool
|
||||
|
||||
|
||||
from langflow.utils import constants
|
||||
|
||||
|
||||
|
|
@ -165,12 +166,14 @@ def get_default_factory(module: str, function: str):
|
|||
|
||||
def get_tools_dict():
|
||||
"""Get the tools dictionary."""
|
||||
from langflow.interface.listing import CUSTOM_TOOLS
|
||||
|
||||
tools = {
|
||||
**_BASE_TOOLS,
|
||||
**_LLM_TOOLS,
|
||||
**{k: v[0] for k, v in _EXTRA_LLM_TOOLS.items()},
|
||||
**{k: v[0] for k, v in _EXTRA_OPTIONAL_TOOLS.items()},
|
||||
**constants.CUSTOM_TOOLS,
|
||||
**CUSTOM_TOOLS,
|
||||
}
|
||||
return tools
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,4 @@
|
|||
# # build router
|
||||
# router = APIRouter()
|
||||
|
||||
|
||||
# @router.get("/all")
|
||||
# def get_all():
|
||||
# return build_langchain_types_dict()
|
||||
|
||||
|
||||
# Buil test for /all endpoint
|
||||
from langflow.utils.constants import CUSTOM_TOOLS
|
||||
from langflow.interface.listing import CUSTOM_TOOLS
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import json
|
||||
from langflow.utils.graph import Edge, Graph, Node
|
||||
from langflow.graph.graph import Edge, Graph, Node
|
||||
import pytest
|
||||
from langflow.utils.payload import build_json, get_root_node
|
||||
from langchain.agents import AgentExecutor
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
from langchain import LLMChain, OpenAI
|
||||
from langflow.utils.graph import Graph
|
||||
from langflow.graph.graph import Graph
|
||||
import pytest
|
||||
|
||||
from langflow import load_flow_from_json
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue