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

16
poetry.lock generated
View file

@ -9295,6 +9295,20 @@ platformdirs = ">=3.9.1,<5"
docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"]
test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"]
[[package]]
name = "vulture"
version = "2.11"
description = "Find dead code"
optional = false
python-versions = ">=3.8"
files = [
{file = "vulture-2.11-py2.py3-none-any.whl", hash = "sha256:12d745f7710ffbf6aeb8279ba9068a24d4e52e8ed333b8b044035c9d6b823aba"},
{file = "vulture-2.11.tar.gz", hash = "sha256:f0fbb60bce6511aad87ee0736c502456737490a82d919a44e6d92262cb35f1c2"},
]
[package.dependencies]
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
[[package]]
name = "watchfiles"
version = "0.21.0"
@ -9991,4 +10005,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"]
[metadata]
lock-version = "2.0"
python-versions = ">=3.10,<3.13"
content-hash = "33629727ceeb0aa86064658e89349c24fd786bb1bd3833f093651b70b264edb7"
content-hash = "90454066807e8ae6341a0b4e9569bfabb027b005081e94bbfb763ce8c72de10f"

View file

@ -112,6 +112,7 @@ pytest-instafail = "^0.5.0"
pytest-asyncio = "^0.23.0"
pytest-profiling = "^1.7.0"
pre-commit = "^3.7.0"
vulture = "^2.11"
[tool.poetry.extras]
deploy = ["celery", "redis", "flower"]

View file

@ -18,9 +18,9 @@ from langflow.api.v1.schemas import (
UpdateCustomComponentRequest,
UploadFileResponse,
)
from langflow.custom import CustomComponent
from langflow.custom.utils import build_custom_component_template
from langflow.graph.graph.base import Graph
from langflow.interface.custom.custom_component import CustomComponent
from langflow.interface.custom.utils import build_custom_component_template
from langflow.processing.process import process_tweaks, run_graph_internal
from langflow.schema.graph import Tweaks
from langflow.services.auth.utils import api_key_security, get_current_active_user

View file

@ -1,8 +1,8 @@
from typing import Optional, Union
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.memory import store_message
from langflow.schema import Record

View file

@ -1,8 +1,8 @@
from typing import Optional
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record

View file

@ -1,6 +1,6 @@
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema.schema import Record

View file

@ -1,52 +0,0 @@
from typing import Callable, List, Optional, Union
from langchain.agents import AgentExecutor, AgentType, initialize_agent, types
from langflow.field_typing import BaseChatMemory, BaseLanguageModel, Tool
from langflow.interface.custom.custom_component import CustomComponent
class AgentInitializerComponent(CustomComponent):
display_name: str = "Agent Initializer"
description: str = "Initialize a Langchain Agent."
documentation: str = "https://python.langchain.com/docs/modules/agents/agent_types/"
def build_config(self):
agents = list(types.AGENT_TO_CLASS.keys())
# field_type and required are optional
return {
"agent": {"options": agents, "value": agents[0], "display_name": "Agent Type"},
"max_iterations": {"display_name": "Max Iterations", "value": 10},
"memory": {"display_name": "Memory"},
"tools": {"display_name": "Tools"},
"llm": {"display_name": "Language Model"},
"code": {"advanced": True},
}
def build(
self,
agent: str,
llm: BaseLanguageModel,
tools: List[Tool],
max_iterations: int,
memory: Optional[BaseChatMemory] = None,
) -> Union[AgentExecutor, Callable]:
agent = AgentType(agent)
if memory:
return initialize_agent(
tools=tools,
llm=llm,
agent=agent,
memory=memory,
return_intermediate_steps=True,
handle_parsing_errors=True,
max_iterations=max_iterations,
)
return initialize_agent(
tools=tools,
llm=llm,
agent=agent,
return_intermediate_steps=True,
handle_parsing_errors=True,
max_iterations=max_iterations,
)

View file

@ -1,11 +1,9 @@
from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import create_json_agent
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
from langflow.field_typing import (
BaseLanguageModel,
)
from langflow.interface.custom.custom_component import CustomComponent
from langchain_community.agent_toolkits import create_json_agent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class JsonAgentComponent(CustomComponent):

View file

@ -1,101 +0,0 @@
from typing import List, Optional
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_toolkits.conversational_retrieval.openai_functions import _get_default_system_message
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
from langchain.memory.token_buffer import ConversationTokenBufferMemory
from langchain_openai import ChatOpenAI
from langflow.field_typing.range_spec import RangeSpec
from langflow.interface.custom.custom_component import CustomComponent
from pydantic.v1 import SecretStr
from langchain_core.memory import BaseMemory
from langchain_core.prompts import MessagesPlaceholder, SystemMessagePromptTemplate
from langchain_core.tools import Tool
class ConversationalAgent(CustomComponent):
display_name: str = "OpenAI Conversational Agent"
description: str = "Conversational Agent that can use OpenAI's function calling API"
icon = "OpenAI"
def build_config(self):
openai_function_models = [
"gpt-4-turbo-preview",
"gpt-4-0125-preview",
"gpt-4-1106-preview",
"gpt-4-vision-preview",
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106",
]
return {
"tools": {"display_name": "Tools"},
"memory": {"display_name": "Memory"},
"system_message": {"display_name": "System Message"},
"max_token_limit": {"display_name": "Max Token Limit"},
"model_name": {
"display_name": "Model Name",
"options": openai_function_models,
"value": openai_function_models[0],
},
"code": {"show": False},
"temperature": {
"display_name": "Temperature",
"value": 0.2,
"rangeSpec": RangeSpec(min=0, max=2, step=0.1),
},
}
def build(
self,
model_name: str,
openai_api_key: str,
tools: List[Tool],
openai_api_base: Optional[str] = None,
memory: Optional[BaseMemory] = None,
system_message: Optional[SystemMessagePromptTemplate] = None,
max_token_limit: int = 2000,
temperature: float = 0.9,
) -> AgentExecutor:
if openai_api_key:
api_key = SecretStr(openai_api_key)
else:
api_key = None
llm = ChatOpenAI(
model=model_name,
api_key=api_key,
base_url=openai_api_base,
max_tokens=max_token_limit,
temperature=temperature,
)
if not memory:
memory_key = "chat_history"
memory = ConversationTokenBufferMemory(
memory_key=memory_key,
return_messages=True,
output_key="output",
llm=llm,
max_token_limit=max_token_limit,
)
else:
memory_key = memory.memory_key # type: ignore
_system_message = system_message or _get_default_system_message()
prompt = OpenAIFunctionsAgent.create_prompt(
system_message=_system_message, # type: ignore
extra_prompt_messages=[MessagesPlaceholder(variable_name=memory_key)],
)
agent = OpenAIFunctionsAgent(
llm=llm,
tools=tools,
prompt=prompt, # type: ignore
)
return AgentExecutor(
agent=agent,
tools=tools, # type: ignore
memory=memory,
verbose=True,
return_intermediate_steps=True,
handle_parsing_errors=True,
)

View file

@ -1,12 +1,12 @@
from typing import Callable, Union
from langchain.agents import AgentExecutor
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits import SQLDatabaseToolkit
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities import SQLDatabase
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class SQLAgentComponent(CustomComponent):

View file

@ -3,8 +3,8 @@ from typing import Callable, Union
from langchain.agents import AgentExecutor, create_vectorstore_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreToolkit
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class VectorStoreAgentComponent(CustomComponent):

View file

@ -4,7 +4,7 @@ from langchain.agents import create_vectorstore_router_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreRouterToolkit
from langchain_core.language_models.base import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class VectorStoreRouterAgentComponent(CustomComponent):

View file

@ -1,17 +1,13 @@
from .AgentInitializer import AgentInitializerComponent
from .CSVAgent import CSVAgentComponent
from .JsonAgent import JsonAgentComponent
from .OpenAIConversationalAgent import ConversationalAgent
from .SQLAgent import SQLAgentComponent
from .VectorStoreAgent import VectorStoreAgentComponent
from .VectorStoreRouterAgent import VectorStoreRouterAgentComponent
from .XMLAgent import XMLAgentComponent
__all__ = [
"AgentInitializerComponent",
"CSVAgentComponent",
"JsonAgentComponent",
"ConversationalAgent",
"SQLAgentComponent",
"VectorStoreAgentComponent",
"VectorStoreRouterAgentComponent",

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.chains import ConversationChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
class ConversationChainComponent(CustomComponent):

View file

@ -1,11 +1,11 @@
from typing import Optional
from langchain.chains.llm import LLMChain
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.prompts import PromptTemplate
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
class LLMChainComponent(CustomComponent):
display_name = "LLMChain"

View file

@ -1,7 +1,7 @@
from langchain.chains import LLMCheckerChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Text
from langflow.interface.custom.custom_component import CustomComponent
class LLMCheckerChainComponent(CustomComponent):

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.chains import LLMChain, LLMMathChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
class LLMMathChainComponent(CustomComponent):

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain.chains.retrieval_qa.base import RetrievalQA
from langchain_core.documents import Document
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever, Text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain.chains import RetrievalQAWithSourcesChain
from langchain_core.documents import Document
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever, Text
from langflow.interface.custom.custom_component import CustomComponent
class RetrievalQAWithSourcesChainComponent(CustomComponent):

View file

@ -5,8 +5,8 @@ from langchain_community.utilities.sql_database import SQLDatabase
from langchain_core.prompts import PromptTemplate
from langchain_core.runnables import Runnable
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Text
from langflow.interface.custom.custom_component import CustomComponent
class SQLGeneratorComponent(CustomComponent):

View file

@ -3,7 +3,8 @@ import json
from typing import List, Optional
import httpx
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
from typing import Any, Dict, List, Optional
from langflow.base.data.utils import parallel_load_records, parse_text_file_to_record, retrieve_file_paths
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Any, Dict
from langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -2,7 +2,7 @@ from typing import Any, Dict
from langchain_community.document_loaders.web_base import WebBaseLoader
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain_community.embeddings import BedrockEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langchain_community.embeddings import BedrockEmbeddings
from langchain_core.embeddings import Embeddings
from langflow.custom import CustomComponent
class AmazonBedrockEmeddingsComponent(CustomComponent):
display_name: str = "Amazon Bedrock Embeddings"

View file

@ -1,8 +1,9 @@
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.embeddings import Embeddings
from langchain_openai import AzureOpenAIEmbeddings
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
class AzureOpenAIEmbeddingsComponent(CustomComponent):
display_name: str = "Azure OpenAI Embeddings"

View file

@ -2,7 +2,7 @@ from typing import Dict, Optional
from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class HuggingFaceEmbeddingsComponent(CustomComponent):

View file

@ -3,7 +3,7 @@ from typing import Dict, Optional
from langchain_community.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
from pydantic.v1.types import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class HuggingFaceInferenceAPIEmbeddingsComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from langchain_mistralai.embeddings import MistralAIEmbeddings
from pydantic.v1 import SecretStr
from langchain_mistralai.embeddings import MistralAIEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain_community.embeddings import OllamaEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langchain_community.embeddings import OllamaEmbeddings
from langchain_core.embeddings import Embeddings
from langflow.custom import CustomComponent
class OllamaEmbeddingsComponent(CustomComponent):
display_name: str = "Ollama Embeddings"

View file

@ -1,10 +1,10 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
from langchain_openai.embeddings.base import OpenAIEmbeddings
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings, NestedDict
from langflow.interface.custom.custom_component import CustomComponent
class OpenAIEmbeddingsComponent(CustomComponent):
@ -94,7 +94,6 @@ class OpenAIEmbeddingsComponent(CustomComponent):
allowed_special: List[str] = [],
disallowed_special: List[str] = ["all"],
chunk_size: int = 1000,
client: Optional[Any] = None,
deployment: str = "text-embedding-ada-002",
embedding_ctx_length: int = 8191,
max_retries: int = 6,
@ -126,7 +125,6 @@ class OpenAIEmbeddingsComponent(CustomComponent):
allowed_special=set(allowed_special),
disallowed_special="all",
chunk_size=chunk_size,
client=client,
deployment=deployment,
embedding_ctx_length=embedding_ctx_length,
max_retries=max_retries,

View file

@ -2,7 +2,7 @@ from typing import List, Optional
from langchain_google_vertexai import VertexAIEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class VertexAIEmbeddingsComponent(CustomComponent):

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import delete_messages, get_messages

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from typing import List
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,8 @@
from typing import Union
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.schema import Record
class PassComponent(CustomComponent):

View file

@ -1,8 +1,8 @@
from typing import Callable
from langflow.custom import CustomComponent
from langflow.custom.utils import get_function
from langflow.field_typing import Code
from langflow.interface.custom.custom_component import CustomComponent
from langflow.interface.custom.utils import get_function
class PythonFunctionComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from langchain_core.runnables import Runnable
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
class RunnableExecComponent(CustomComponent):

View file

@ -1,8 +1,8 @@
from langchain_community.tools.sql_database.tool import QuerySQLDataBaseTool
from langchain_community.utilities import SQLDatabase
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
class SQLExecutorComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from typing import Optional
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.utils.util import unescape_string

View file

@ -1,6 +1,6 @@
from typing import List, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import get_messages, store_message
from langflow.schema import Record

View file

@ -1,8 +1,8 @@
from typing import Optional, Union
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.schema import Record
class TextOperatorComponent(CustomComponent):

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Text

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Text

View file

@ -1,6 +1,6 @@
# from langflow.field_typing import Data
from langflow.custom import CustomComponent
from langflow.schema import Record
from langflow.interface.custom.custom_component import CustomComponent
class Component(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import List
from langchain_core.documents import Document
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
import uuid
from typing import Any, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class UUIDGeneratorComponent(CustomComponent):

View file

@ -1,6 +1,6 @@
from typing import List, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import get_messages
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
from langchain_core.prompts import PromptTemplate
from langflow.custom import CustomComponent
from langflow.field_typing import Prompt, TemplateField, Text
from langflow.interface.custom.custom_component import CustomComponent
class PromptComponent(CustomComponent):

View file

@ -3,7 +3,7 @@
# We need to make sure this class is importable from the context where this code will be running.
from langchain_community.utilities.bing_search import BingSearchAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class BingSearchAPIWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.google_search import GoogleSearchAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class GoogleSearchAPIWrapperComponent(CustomComponent):

View file

@ -4,7 +4,7 @@ from typing import Dict
# If this class does not exist, you would need to create it or import the appropriate class from another module
from langchain_community.utilities.google_serper import GoogleSerperAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class GoogleSerperAPIWrapperComponent(CustomComponent):

View file

@ -13,7 +13,7 @@
from langchain_core.documents import Document
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.services.database.models.base import orjson_dumps

View file

@ -1,6 +1,6 @@
from langchain_experimental.sql.base import SQLDatabase
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SQLDatabaseComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Dict, Optional
from langchain_community.utilities.searx_search import SearxSearchWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SearxSearchWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.serpapi import SerpAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SerpAPIWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# Assuming WikipediaAPIWrapper is a class that needs to be imported.
# The import statement is not included as it is not provided in the JSON

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.wolfram_alpha import WolframAlphaAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# Since all the fields in the JSON have show=False, we will only create a basic component
# without any configurable fields.

View file

@ -116,19 +116,18 @@ class ZepMessageReaderComponent(BaseMemoryComponent):
url: Optional[Text] = None,
api_key: Optional[Text] = None,
query: Optional[Text] = None,
search_scope: SearchScope = SearchScope.messages,
search_type: SearchType = SearchType.similarity,
search_scope: str = SearchScope.messages,
search_type: str = SearchType.similarity,
limit: Optional[int] = None,
) -> list[Record]:
try:
from zep_python import ZepClient
from zep_python.langchain import ZepChatMessageHistory
# Monkeypatch API_BASE_PATH to
# avoid 404
# This is a workaround for the local Zep instance
# cloud Zep works with v2
import zep_python.zep_client
from zep_python import ZepClient
from zep_python.langchain import ZepChatMessageHistory
zep_python.zep_client.API_BASE_PATH = api_base_path
except ImportError:

View file

@ -1,8 +1,9 @@
from typing import Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.bedrock import Bedrock
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class AmazonBedrockComponent(CustomComponent):

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain_anthropic import ChatAnthropic
from langchain_core.language_models import BaseLanguageModel
from pydantic.v1 import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.language_models import BaseLanguageModel
from langflow.custom import CustomComponent
class ChatAntropicSpecsComponent(CustomComponent):

View file

@ -1,10 +1,11 @@
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.language_models import BaseLanguageModel
from langchain_openai import AzureChatOpenAI
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
class AzureChatOpenAISpecsComponent(CustomComponent):
display_name: str = "AzureChatOpenAI"

View file

@ -1,10 +1,11 @@
from typing import Optional
from langchain_community.chat_models.baidu_qianfan_endpoint import QianfanChatEndpoint
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class QianfanChatEndpointComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Optional
from langchain_community.llms.baidu_qianfan_endpoint import QianfanLLMEndpoint
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel

View file

@ -1,8 +1,9 @@
from typing import Any, Dict, Optional
from langchain_community.chat_models.litellm import ChatLiteLLM, ChatLiteLLMException
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class ChatLiteLLMComponent(CustomComponent):

View file

@ -1,11 +1,11 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
# from langchain_community.chat_models import ChatOllama
from langchain_community.chat_models import ChatOllama
from langchain_core.language_models.chat_models import BaseChatModel
# from langchain.chat_models import ChatOllama
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# from langchain.callbacks.manager import CallbackManager
@ -182,7 +182,7 @@ class ChatOllamaComponent(CustomComponent):
num_ctx: Optional[int] = None,
num_gpu: Optional[int] = None,
format: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict] = None,
num_thread: Optional[int] = None,
repeat_penalty: Optional[float] = None,
stop: Optional[List[str]] = None,

View file

@ -3,10 +3,9 @@ from typing import Optional
from langchain_openai import ChatOpenAI
from pydantic.v1 import SecretStr
from langflow.base.models.openai_constants import MODEL_NAMES
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, NestedDict
from langflow.interface.custom.custom_component import CustomComponent
class ChatOpenAIComponent(CustomComponent):

View file

@ -1,10 +1,9 @@
from typing import List, Optional
from typing import Optional
from langchain_community.chat_models.vertexai import ChatVertexAI
from langchain_core.messages.base import BaseMessage
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class ChatVertexAIComponent(CustomComponent):
@ -65,7 +64,6 @@ class ChatVertexAIComponent(CustomComponent):
self,
credentials: Optional[str],
project: str,
examples: Optional[List[BaseMessage]] = [],
location: str = "us-central1",
max_output_tokens: int = 128,
model_name: str = "chat-bison",
@ -76,7 +74,6 @@ class ChatVertexAIComponent(CustomComponent):
) -> BaseLanguageModel:
return ChatVertexAI(
credentials=credentials,
examples=examples,
location=location,
max_output_tokens=max_output_tokens,
model_name=model_name,

View file

@ -1,7 +1,7 @@
from langchain_community.llms.cohere import Cohere
from langchain_core.language_models.base import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class CohereComponent(CustomComponent):

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain_google_genai import ChatGoogleGenerativeAI # type: ignore
from pydantic.v1.types import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, RangeSpec
from langflow.interface.custom.custom_component import CustomComponent
class GoogleGenerativeAIComponent(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class HuggingFaceEndpointsComponent(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import List, Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.ollama import Ollama
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class OllamaLLM(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import Dict, Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.vertexai import VertexAI
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class VertexAIComponent(CustomComponent):

View file

@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
# from langchain_community.chat_models import ChatOllama
from langchain_community.chat_models import ChatOllama
@ -229,7 +229,7 @@ class ChatOllamaComponent(LCModelComponent):
num_ctx: Optional[int] = None,
num_gpu: Optional[int] = None,
format: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict] = None,
num_thread: Optional[int] = None,
repeat_penalty: Optional[float] = None,
stop: Optional[List[str]] = None,

View file

@ -1,6 +1,5 @@
from typing import List, Optional
from typing import Optional
from langchain_core.messages.base import BaseMessage
from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
@ -93,7 +92,6 @@ class ChatVertexAIComponent(LCModelComponent):
input_value: Text,
credentials: Optional[str],
project: str,
examples: Optional[List[BaseMessage]] = [],
location: str = "us-central1",
max_output_tokens: int = 128,
model_name: str = "chat-bison",
@ -112,7 +110,6 @@ class ChatVertexAIComponent(LCModelComponent):
)
output = ChatVertexAI(
credentials=credentials,
examples=examples,
location=location,
max_output_tokens=max_output_tokens,
model_name=model_name,

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain_community.retrievers import AmazonKendraRetriever
from langflow.interface.custom.custom_component import CustomComponent
from langchain_community.retrievers import AmazonKendraRetriever
from langchain_core.retrievers import BaseRetriever
from langflow.custom import CustomComponent
class AmazonKendraRetrieverComponent(CustomComponent):
display_name: str = "Amazon Kendra Retriever"

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain_community.retrievers import MetalRetriever
from langchain_core.retrievers import BaseRetriever
from metal_sdk.metal import Metal # type: ignore
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.retrievers import BaseRetriever
from langflow.custom import CustomComponent
class MetalRetrieverComponent(CustomComponent):

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.retrievers import MultiQueryRetriever
from langflow.field_typing import BaseRetriever, PromptTemplate, BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseRetriever, PromptTemplate, Text
class MultiQueryRetrieverComponent(CustomComponent):
@ -41,10 +41,13 @@ class MultiQueryRetrieverComponent(CustomComponent):
self,
llm: BaseLanguageModel,
retriever: BaseRetriever,
prompt: Optional[PromptTemplate] = None,
prompt: Optional[Text] = None,
parser_key: str = "lines",
) -> MultiQueryRetriever:
if not prompt:
return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, parser_key=parser_key)
else:
return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, prompt=prompt, parser_key=parser_key)
prompt_template = PromptTemplate.from_template(prompt)
return MultiQueryRetriever.from_llm(
llm=llm, retriever=retriever, prompt=prompt_template, parser_key=parser_key
)

View file

@ -1,13 +1,14 @@
import json
from typing import List
from langchain.chains.query_constructor.base import AttributeInfo
from langchain.retrievers.self_query.base import SelfQueryRetriever
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.language_models import BaseLanguageModel
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
from langflow.custom import CustomComponent
class VectaraSelfQueryRetriverComponent(CustomComponent):
"""

View file

@ -1,7 +1,7 @@
from langchain_core.vectorstores import VectorStoreRetriever
from langflow.custom import CustomComponent
from langflow.field_typing import VectorStore
from langflow.interface.custom.custom_component import CustomComponent
class VectoStoreRetrieverComponent(CustomComponent):

View file

@ -1,9 +1,10 @@
from typing import List
from langflow.interface.custom.custom_component import CustomComponent
from langchain_text_splitters import CharacterTextSplitter
from langflow.custom import CustomComponent
from langflow.schema.schema import Record
from langflow.utils.util import unescape_string
from langchain_text_splitters import CharacterTextSplitter
class CharacterTextSplitterComponent(CustomComponent):

View file

@ -1,9 +1,10 @@
from typing import List, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record
from langchain_text_splitters import Language, RecursiveCharacterTextSplitter
from langflow.custom import CustomComponent
from langflow.schema.schema import Record
class LanguageRecursiveTextSplitterComponent(CustomComponent):
display_name: str = "Language Recursive Text Splitter"

View file

@ -1,10 +1,11 @@
from typing import Optional
from langchain_core.documents import Document
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.documents import Document
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langflow.custom import CustomComponent
from langflow.schema import Record
from langflow.utils.util import build_loader_repr_from_records, unescape_string
from langchain_text_splitters import RecursiveCharacterTextSplitter
class RecursiveCharacterTextSplitterComponent(CustomComponent):

View file

@ -1,7 +1,10 @@
from pathlib import Path
import yaml
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
from langchain_community.tools.json.tool import JsonSpec
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class JsonToolkitComponent(CustomComponent):
@ -10,8 +13,17 @@ class JsonToolkitComponent(CustomComponent):
def build_config(self):
return {
"spec": {"display_name": "Spec", "type": JsonSpec},
"path": {
"display_name": "Path",
"field_type": "file",
"file_types": ["json", "yaml", "yml"],
},
}
def build(self, spec: JsonSpec) -> JsonToolkit:
def build(self, path: str) -> JsonToolkit:
if path.endswith("yaml") or path.endswith("yml"):
yaml_dict = yaml.load(open(path, "r"), Loader=yaml.FullLoader)
spec = JsonSpec(dict_=yaml_dict)
else:
spec = JsonSpec.from_file(Path(path))
return JsonToolkit(spec=spec)

View file

@ -1,9 +1,10 @@
from typing import List, Union
from metaphor_python import Metaphor # type: ignore
from langflow.interface.custom.custom_component import CustomComponent
from langchain_community.agent_toolkits.base import BaseToolkit
from langchain_core.tools import Tool, tool
from metaphor_python import Metaphor # type: ignore
from langflow.custom import CustomComponent
class MetaphorToolkit(CustomComponent):

View file

@ -1,8 +1,12 @@
from pathlib import Path
import yaml
from langchain_community.agent_toolkits.openapi.toolkit import BaseToolkit, OpenAPIToolkit
from langchain_community.tools.json.tool import JsonSpec
from langchain_community.utilities.requests import TextRequestsWrapper
from langflow.field_typing import AgentExecutor
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class OpenAPIToolkitComponent(CustomComponent):
@ -15,9 +19,16 @@ class OpenAPIToolkitComponent(CustomComponent):
"requests_wrapper": {"display_name": "Text Requests Wrapper"},
}
def build(
self,
json_agent: AgentExecutor,
requests_wrapper: TextRequestsWrapper,
) -> BaseToolkit:
return OpenAPIToolkit(json_agent=json_agent, requests_wrapper=requests_wrapper)
def build(self, llm: BaseLanguageModel, path: str, allow_dangerous_requests: bool = False) -> BaseToolkit:
if path.endswith("yaml") or path.endswith("yml"):
yaml_dict = yaml.load(open(path, "r"), Loader=yaml.FullLoader)
spec = JsonSpec(dict_=yaml_dict)
else:
spec = JsonSpec.from_file(Path(path))
requests_wrapper = TextRequestsWrapper()
return OpenAPIToolkit.from_llm(
llm=llm,
json_spec=spec,
requests_wrapper=requests_wrapper,
allow_dangerous_requests=allow_dangerous_requests,
)

View file

@ -1,8 +1,8 @@
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreInfo
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.vectorstores import VectorStore
from langflow.custom import CustomComponent
class VectorStoreInfoComponent(CustomComponent):
display_name = "VectorStoreInfo"

View file

@ -2,8 +2,8 @@ from typing import List, Union
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreInfo, VectorStoreRouterToolkit
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Tool
from langflow.interface.custom.custom_component import CustomComponent
class VectorStoreRouterToolkitComponent(CustomComponent):

View file

@ -2,8 +2,8 @@ from typing import Union
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreInfo, VectorStoreToolkit
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Tool
from langflow.interface.custom.custom_component import CustomComponent
class VectorStoreToolkitComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from langchain.tools.retriever import create_retriever_tool
from langflow.custom import CustomComponent
from langflow.field_typing import BaseRetriever, Tool
from langflow.interface.custom.custom_component import CustomComponent
class RetrieverToolComponent(CustomComponent):

View file

@ -9,7 +9,7 @@ from .SupabaseVectorStoreSearch import SupabaseSearchComponent
from .VectaraSearch import VectaraSearchComponent
from .WeaviateSearch import WeaviateSearchVectorStore
from .pgvectorSearch import PGVectorSearchComponent
from .Couchbase import CouchbaseSearchComponent # type: ignore
from .Couchbase import CouchbaseSearchComponent # type: ignore
__all__ = [
"AstraDBSearchComponent",

View file

@ -2,13 +2,13 @@ from typing import List, Optional, Union
import chromadb # type: ignore
from langchain_community.vectorstores.chroma import Chroma
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record
from langchain_core.embeddings import Embeddings
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
from langflow.custom import CustomComponent
from langflow.schema.schema import Record
class ChromaComponent(CustomComponent):
"""

View file

@ -1,12 +1,13 @@
from typing import List, Text, Union
from langchain_community.vectorstores.faiss import FAISS
from langflow.field_typing import Embeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record
from langchain_community.vectorstores.faiss import FAISS
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings
from langflow.schema.schema import Record
class FAISSComponent(CustomComponent):
display_name = "FAISS"

View file

@ -1,8 +1,9 @@
from typing import List, Optional
from langchain_community.vectorstores.mongodb_atlas import MongoDBAtlasVectorSearch
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record

View file

@ -1,13 +1,14 @@
from typing import List, Optional, Union
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
from langchain_pinecone._utilities import DistanceStrategy
from langchain_pinecone.vectorstores import PineconeVectorStore
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
class PineconeComponent(CustomComponent):

Some files were not shown because too many files have changed in this diff Show more