Add broken components

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-09 00:30:23 -03:00
commit 4852b845b4
66 changed files with 2529 additions and 0 deletions

View file

@ -0,0 +1,22 @@
from langflow import CustomComponent
from langchain.field_typing import BaseLanguageModel, AgentExecutor
class CSVAgentComponent(CustomComponent):
display_name = "CSVAgent"
description = "Construct a CSV agent from a CSV and tools."
documentation = "https://python.langchain.com/docs/modules/agents/toolkits/csv"
def build_config(self):
return {
"llm": {"display_name": "LLM", "type": BaseLanguageModel},
"path": {"display_name": "Path", "type": "file", "suffixes": [".csv"], "file_types": ["csv"]},
}
def build(
self,
llm: BaseLanguageModel,
path: str,
) -> AgentExecutor:
# Instantiate and return the CSV agent class with the provided llm and path
return AgentExecutor(llm=llm, path=path)

View file

@ -0,0 +1,25 @@
from langflow import CustomComponent
from langchain.agents import AgentExecutor
from typing import Callable
from langflow.field_typing import (
BaseLanguageModel,
BaseToolkit,
)
class JsonAgentComponent(CustomComponent):
display_name = "JsonAgent"
description = "Construct a json agent from an LLM and tools."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"toolkit": {"display_name": "Toolkit"},
}
def build(
self,
llm: BaseLanguageModel,
toolkit: BaseToolkit,
) -> Callable:
return AgentExecutor(llm=llm, toolkit=toolkit)

View file

@ -0,0 +1,25 @@
from langflow import CustomComponent
from typing import Union, Callable
from langchain.agents import AgentExecutor
from langflow.field_typing import BaseLanguageModel
class SQLAgentComponent(CustomComponent):
display_name = "SQLAgent"
description = "Construct an SQL agent from an LLM and tools."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"database_uri": {"display_name": "Database URI"},
}
def build(
self,
llm: BaseLanguageModel,
database_uri: str,
) -> Union[AgentExecutor, Callable]:
# Assuming there is a constructor for SQLAgent that takes these parameters
# Since the actual implementation is not provided, this is a placeholder
# Replace SQLAgent with the actual class name if different
return SQLAgent(llm=llm, database_uri=database_uri)

View file

@ -0,0 +1,22 @@
from langflow import CustomComponent
from langchain.agents import AgentExecutor
from typing import Union, Callable
from langflow.field_typing import BaseLanguageModel, VectorStore
class VectorStoreAgentComponent(CustomComponent):
display_name = "VectorStoreAgent"
description = "Construct an agent from a Vector Store."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"vectorstoreinfo": {"display_name": "Vector Store Info"},
}
def build(
self,
llm: BaseLanguageModel,
vectorstoreinfo: VectorStore,
) -> Union[AgentExecutor, Callable]:
return AgentExecutor(llm=llm, vectorstore=vectorstoreinfo)

View file

@ -0,0 +1,23 @@
from langflow import CustomComponent
from langchain.llms import BaseLanguageModel
from langchain.vectorstores import VectorStoreRouterToolkit
from langchain.agents import AgentExecutor
from typing import Callable
class VectorStoreRouterAgentComponent(CustomComponent):
display_name = "VectorStoreRouterAgent"
description = "Construct an agent from a Vector Store Router."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"vectorstoreroutertoolkit": {"display_name": "Vector Store Router Toolkit"},
}
def build(
self,
llm: BaseLanguageModel,
vectorstoreroutertoolkit: VectorStoreRouterToolkit
) -> Callable:
return AgentExecutor(llm=llm, toolkit=vectorstoreroutertoolkit)

View file

@ -0,0 +1,29 @@
from langflow import CustomComponent
from langchain.agents import ZeroShotAgent
from typing import List, Optional
from langflow.field_typing import (
BaseLanguageModel,
BaseTool,
)
class ZeroShotAgentComponent(CustomComponent):
display_name = "ZeroShotAgent"
description = "Construct an agent from an LLM and tools."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"tools": {"display_name": "Tools"},
"prefix": {"display_name": "Prefix", "multiline": True},
"suffix": {"display_name": "Suffix", "multiline": True},
}
def build(
self,
llm: BaseLanguageModel,
tools: List[BaseTool],
prefix: Optional[str] = "Answer the following questions as best you can. You have access to the following tools:",
suffix: Optional[str] = "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}",
) -> ZeroShotAgent:
return ZeroShotAgent(llm=llm, tools=tools, prefix=prefix, suffix=suffix)

View file

@ -0,0 +1,37 @@
from langflow import CustomComponent
from langflow.field_typing import BaseLanguageModel, Chain
from typing import Union, Callable
class CombineDocsChainComponent(CustomComponent):
display_name = "CombineDocsChain"
description = "Load question answering chain."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"chain_type": {
"display_name": "Chain Type",
"options": ['stuff', 'map_reduce', 'map_rerank', 'refine'],
},
}
def build(
self,
llm: BaseLanguageModel,
chain_type: str,
) -> Union[Chain, Callable]:
if chain_type not in ['stuff', 'map_reduce', 'map_rerank', 'refine']:
raise ValueError(f"Invalid chain_type: {chain_type}")
# Implement the logic to create and return the appropriate chain based on the chain_type
# This could be a placeholder for now, as the specific chain loading function is not defined.
# Replace with actual implementation when available.
return load_qa_chain(llm=llm, chain_type=chain_type)
# Assuming there is a function or class `load_qa_chain` that creates the chain
# based on the `chain_type` and `llm`. This is a placeholder for the actual
# implementation which should be replaced with the correct function/class call.
def load_qa_chain(llm: BaseLanguageModel, chain_type: str) -> Union[Chain, Callable]:
# Implement the logic to create and return the appropriate chain based on the chain_type
pass

View file

@ -0,0 +1,24 @@
from langflow import CustomComponent
from langchain.chains import LLMCheckerChain
from typing import Union, Callable
from langflow.field_typing import (
BaseLanguageModel,
Chain,
)
class LLMCheckerChainComponent(CustomComponent):
display_name = "LLMCheckerChain"
description = ""
documentation = "https://python.langchain.com/docs/modules/chains/additional/llm_checker"
def build_config(self):
return {
"llm": {"display_name": "LLM"},
}
def build(
self,
llm: BaseLanguageModel,
) -> Union[Chain, Callable]:
return LLMCheckerChain(llm=llm)

View file

@ -0,0 +1,32 @@
from langflow import CustomComponent
from langchain.chains import LLMChain
from typing import Optional
from langflow.field_typing import (
BaseLanguageModel,
BaseMemory,
)
class LLMMathChainComponent(CustomComponent):
display_name = "LLMMathChain"
description = "Chain that interprets a prompt and executes python code to do math."
documentation = "https://python.langchain.com/docs/modules/chains/additional/llm_math"
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"llm_chain": {"display_name": "LLM Chain"},
"memory": {"display_name": "Memory"},
"input_key": {"display_name": "Input Key"},
"output_key": {"display_name": "Output Key"},
}
def build(
self,
llm: BaseLanguageModel,
llm_chain: LLMChain,
input_key: str,
output_key: str,
memory: Optional[BaseMemory] = None,
) -> LLMChain:
return LLMChain(llm=llm, prompt=llm_chain, input_key=input_key, output_key=output_key, memory=memory)

View file

@ -0,0 +1,41 @@
from langflow import CustomComponent
from langchain.chains import BaseRetrievalQA
from typing import Optional, Union, Callable
from langflow.field_typing import (
BaseCombineDocumentsChain,
BaseMemory,
BaseRetriever,
)
class RetrievalQAComponent(CustomComponent):
display_name = "RetrievalQA"
description = "Chain for question-answering against an index."
def build_config(self):
return {
"combine_documents_chain": {"display_name": "Combine Documents Chain"},
"retriever": {"display_name": "Retriever"},
"memory": {"display_name": "Memory", "required": False},
"input_key": {"display_name": "Input Key"},
"output_key": {"display_name": "Output Key"},
"return_source_documents": {"display_name": "Return Source Documents"},
}
def build(
self,
combine_documents_chain: BaseCombineDocumentsChain,
retriever: BaseRetriever,
memory: Optional[BaseMemory] = None,
input_key: str = "query",
output_key: str = "result",
return_source_documents: bool = True,
) -> Union[BaseRetrievalQA, Callable]:
return BaseRetrievalQA(
combine_documents_chain=combine_documents_chain,
retriever=retriever,
memory=memory,
input_key=input_key,
output_key=output_key,
return_source_documents=return_source_documents,
)

View file

@ -0,0 +1,35 @@
from langflow import CustomComponent
from langchain.chains import RetrievalQAWithSourcesChain
from typing import Optional
from langflow.field_typing import (
BaseMemory,
BaseRetriever,
Chain,
)
class RetrievalQAWithSourcesChainComponent(CustomComponent):
display_name = "RetrievalQAWithSourcesChain"
description = "Question-answering with sources over an index."
def build_config(self):
return {
"combine_documents_chain": {"display_name": "Combine Documents Chain"},
"retriever": {"display_name": "Retriever"},
"memory": {"display_name": "Memory", "optional": True},
"return_source_documents": {"display_name": "Return Source Documents", "default": True, "advanced": True},
}
def build(
self,
combine_documents_chain: Chain,
retriever: BaseRetriever,
memory: Optional[BaseMemory] = None,
return_source_documents: Optional[bool] = True,
) -> RetrievalQAWithSourcesChain:
return RetrievalQAWithSourcesChain(
combine_documents_chain=combine_documents_chain,
retriever=retriever,
memory=memory,
return_source_documents=return_source_documents
)

View file

@ -0,0 +1,33 @@
from langflow import CustomComponent
from langchain.chains import Chain
from typing import Callable, Union
from langflow.field_typing import (
BasePromptTemplate,
BaseLanguageModel,
)
# Placeholder SQLDatabase class. In practice, replace this with the actual class or import it if available.
class SQLDatabase:
pass
class SQLDatabaseChainComponent(CustomComponent):
display_name = "SQLDatabaseChain"
description = ""
def build_config(self):
return {
"db": {"display_name": "Database"},
"llm": {"display_name": "LLM"},
"prompt": {"display_name": "Prompt"},
}
def build(
self,
db: SQLDatabase,
llm: BaseLanguageModel,
prompt: BasePromptTemplate,
) -> Union[Chain, Callable]:
# Assuming there's a specific chain for SQLDatabase in the langchain library:
# Replace `Chain` with the specific chain class that interfaces with the SQLDatabase.
return Chain(db=db, llm=llm, prompt=prompt)

View file

@ -0,0 +1,31 @@
from langflow import CustomComponent
from langchain.field_typing import Document
from typing import Optional, Dict
class AZLyricsLoaderComponent(CustomComponent):
display_name = "AZLyricsLoader"
description = "Load `AZLyrics` webpages."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/azlyrics"
def build_config(self):
return {
"metadata": {
"display_name": "Metadata",
"type": "dict",
"default": {},
"show": True
},
"web_path": {
"display_name": "Web Page",
"type": "str",
"required": True,
"show": True
},
}
def build(self, metadata: Optional[Dict] = None, web_path: str = "") -> Document:
# Assuming there is a class AZLyricsLoader that takes metadata and web_path as parameters
# and returns a Document object. Replace AZLyricsLoader with the actual class name if different.
# The import statement for AZLyricsLoader is assumed to be added above.
return AZLyricsLoader(metadata=metadata, web_path=web_path)

View file

@ -0,0 +1,31 @@
from langflow import CustomComponent
from langchain.field_typing import Document
from typing import Optional, Dict
class AirbyteJSONLoaderComponent(CustomComponent):
display_name = "AirbyteJSONLoader"
description = "Load local `Airbyte` json files."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/airbyte_json"
def build_config(self):
return {
"file_path": {
"display_name": "File Path",
"type": "file",
"fileTypes": ["json"],
"required": True,
},
"metadata": {
"display_name": "Metadata",
"type": "dict",
"required": False,
},
}
def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document:
# Assuming there is a function or class named AirbyteJSONLoader that takes file_path and metadata as parameters
# and returns a Document object. Replace AirbyteJSONLoader with the actual class or function name.
# The actual implementation here is a placeholder and should be adapted to the real AirbyteJSONLoader class or function.
return AirbyteJSONLoader(file_path=file_path, metadata=metadata)

View file

@ -0,0 +1,33 @@
from langflow import CustomComponent
from langchain.field_typing import Document
from typing import Optional, Dict
class BSHTMLLoaderComponent(CustomComponent):
display_name = "BSHTMLLoader"
description = "Load `HTML` files and parse them with `beautiful soup`."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/how_to/html"
def build_config(self):
return {
"file_path": {
"display_name": "File Path",
"required": True,
"show": True,
"type": "file",
"suffixes": [".html"],
"file_types": ["html"],
},
"metadata": {
"display_name": "Metadata",
"required": False,
"show": True,
"type": "dict",
},
}
def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document:
# Assuming there is a class or function named BSHTMLLoader that takes a file path and optional metadata
# and returns a Document object after parsing HTML. Since the actual implementation of BSHTMLLoader is not provided,
# this is a placeholder and should be replaced with the actual logic.
raise NotImplementedError("The BSHTMLLoader function or class needs to be implemented.")

View file

@ -0,0 +1,30 @@
from langchain import CustomComponent
from typing import Optional, Dict, List
from langchain.loaders import CSVLoader
from langchain.documents import Document
class CSVLoaderComponent(CustomComponent):
display_name = "CSVLoader"
description = "Load a `CSV` file into a list of Documents."
def build_config(self):
return {
"file_path": {
"display_name": "File Path",
"required": True,
"suffixes": [".csv"],
"file_types": ["csv"],
},
"metadata": {
"display_name": "Metadata",
"required": False,
},
}
def build(
self,
file_path: str,
metadata: Optional[Dict[str, str]] = None,
) -> List[Document]:
return CSVLoader(file_path=file_path, metadata=metadata).load()

View file

@ -0,0 +1,33 @@
from langflow import CustomComponent
from langchain.documents import Document
from typing import Optional, Dict
from langchain.field_typing import TemplateField
class CoNLLULoaderComponent(CustomComponent):
display_name = "CoNLLULoader"
description = "Load `CoNLL-U` files."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/conll-u"
def build_config(self):
return {
"file_path": TemplateField(
display_name="File Path",
required=True,
type="file",
file_types=["conllu"],
suffixes=['.conllu'],
),
"metadata": TemplateField(
display_name="Metadata",
required=False,
type="dict",
),
}
def build(self, file_path: str, metadata: Optional[Dict[str, str]] = None) -> Document:
# Here, you would use the actual class that loads CoNLL-U files.
# As I don't have the specific class, I'm returning an instance of Document.
# In a real scenario, you should replace the below Document with the actual loader class.
return Document(file_path=file_path, metadata=metadata)

View file

@ -0,0 +1,24 @@
from langflow import CustomComponent
from langchain.document_loaders import Document
from typing import Optional, Dict
class CollegeConfidentialLoaderComponent(CustomComponent):
display_name = "CollegeConfidentialLoader"
description = "Load `College Confidential` webpages."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/college_confidential"
def build_config(self):
return {
"metadata": {"display_name": "Metadata", "default": {}},
"web_path": {"display_name": "Web Page", "required": True},
}
def build(
self,
web_path: str,
metadata: Optional[Dict] = None,
) -> Document:
# Assuming there is a loader class `CollegeConfidentialLoader` that takes `metadata` and `web_path` as arguments
# Replace `CollegeConfidentialLoader` with the actual class name if different
return CollegeConfidentialLoader(web_path=web_path, metadata=metadata)

View file

@ -0,0 +1,42 @@
from langflow import CustomComponent
from langchain.data_connections import Document
from typing import Optional, Dict, Any
class DirectoryLoaderComponent(CustomComponent):
display_name = "DirectoryLoader"
description = "Load from a directory."
def build_config(self) -> Dict[str, Any]:
return {
"glob": {"display_name": "Glob Pattern", "default": "**/*.txt"},
"load_hidden": {"display_name": "Load Hidden Files", "default": False, "advanced": True},
"max_concurrency": {"display_name": "Max Concurrency", "default": 10, "advanced": True},
"metadata": {"display_name": "Metadata", "default": {}},
"path": {"display_name": "Local Directory"},
"recursive": {"display_name": "Recursive", "default": True, "advanced": True},
"silent_errors": {"display_name": "Silent Errors", "default": False, "advanced": True},
"use_multithreading": {"display_name": "Use Multithreading", "default": True, "advanced": True},
}
def build(
self,
glob: str,
path: str,
load_hidden: Optional[bool] = False,
max_concurrency: Optional[int] = 10,
metadata: Optional[Dict[str, Any]] = None,
recursive: Optional[bool] = True,
silent_errors: Optional[bool] = False,
use_multithreading: Optional[bool] = True,
) -> Document:
return Document(
glob=glob,
path=path,
load_hidden=load_hidden,
max_concurrency=max_concurrency,
metadata=metadata,
recursive=recursive,
silent_errors=silent_errors,
use_multithreading=use_multithreading,
)

View file

@ -0,0 +1,32 @@
from langflow import CustomComponent
from langchain.field_typing import Document
from typing import Optional, Dict
class EverNoteLoaderComponent(CustomComponent):
display_name = "EverNoteLoader"
description = "Load from `EverNote`."
documentation = "https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/evernote"
def build_config(self):
return {
"file_path": {
"display_name": "File Path",
"required": True,
"suffixes": [".xml"],
"show": True,
"type": "file",
"file_types": ["xml"],
},
"metadata": {
"display_name": "Metadata",
"required": False,
"show": True,
"type": "dict",
},
}
def build(self, file_path: str, metadata: Optional[Dict] = None) -> Document:
# Assuming there is a function or class named `EverNoteLoader` that takes these parameters
# and returns a `Document` object. Replace `EverNoteLoader` with the actual implementation.
return EverNoteLoader(file_path=file_path, metadata=metadata)

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