Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reorganize memory components and enhance model inputs with improved documentation #4529

Merged
merged 16 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from langflow.base.models.model_input_constants import ALL_PROVIDER_FIELDS, MODEL_PROVIDERS_DICT
from langflow.base.models.model_utils import get_model_name
from langflow.components.helpers import CurrentDateComponent
from langflow.components.helpers.memory import MemoryComponent
from langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent
from langflow.components.memories.memory import MemoryComponent
from langflow.io import BoolInput, DropdownInput, MultilineInput, Output
from langflow.schema.dotdict import dotdict
from langflow.schema.message import Message
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/data/csv_to_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CSVToDataComponent(Component):
display_name = "Load CSV"
description = "Load a CSV file, CSV from a file path, or a valid CSV string and convert it to a list of Data"
icon = "file-spreadsheet"
beta = True
name = "CSVtoData"
legacy = True

inputs = [
FileInput(
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/data/json_to_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class JSONToDataComponent(Component):
"Convert a JSON file, JSON from a file path, or a JSON string to a Data object or a list of Data objects"
)
icon = "braces"
beta = True
name = "JSONtoData"
legacy = True

inputs = [
FileInput(
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/data/sql_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class SQLExecutorComponent(CustomComponent):
display_name = "SQL Executor"
display_name = "SQL Query"
description = "Execute SQL query."
name = "SQLExecutor"
beta: bool = True
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/data/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WebhookComponent(Component):
MultilineInput(
name="data",
display_name="Payload",
info="Use this field to quickly test the webhook component by providing a JSON payload.",
info="Receives a payload from external systems via HTTP POST.",
)
]
outputs = [
Expand Down
6 changes: 4 additions & 2 deletions src/backend/base/langflow/components/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from .create_list import CreateListComponent
from .current_date import CurrentDateComponent
from .id_generator import IDGeneratorComponent
from .memory import MemoryComponent
from .output_parser import OutputParserComponent
from .split_text import SplitTextComponent
from .store_message import StoreMessageComponent
from .structured_output import StructuredOutputComponent

__all__ = [
"CreateListComponent",
"CurrentDateComponent",
"IDGeneratorComponent",
"OutputParserComponent",
"SplitTextComponent",
"StructuredOutputComponent",
"StoreMessageComponent",
"MemoryComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class MemoryComponent(Component):
display_name = "Chat Memory"
display_name = "Message History"
description = "Retrieves stored chat messages from Langflow tables or an external memory."
icon = "message-square-more"
name = "Memory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OutputParserComponent(Component):
description = "Transforms the output of an LLM into a specified format."
icon = "type"
name = "OutputParser"
legacy = True

inputs = [
DropdownInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class StoreMessageComponent(Component):
display_name="Session ID",
info="The session ID of the chat. If empty, the current session ID parameter will be used.",
value="",
advanced=True,
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class LangChainHubPromptComponent(Component):
display_name: str = "LangChain Hub"
display_name: str = "Prompt Hub"
description: str = "Prompt Component that uses LangChain Hub prompts"
beta = True
icon = "LangChain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ConditionalRouterComponent(Component):
description = "Routes an input message to a corresponding output based on text comparison."
icon = "split"
name = "ConditionalRouter"
legacy = True

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DataConditionalRouterComponent(Component):
display_name = "Condition"
description = "Route Data object(s) based on a condition applied to a specified key, including boolean validation."
icon = "split"
beta = True
name = "DataConditionalRouter"
legacy = True

Expand Down
1 change: 0 additions & 1 deletion src/backend/base/langflow/components/logic/run_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class RunFlowComponent(Component):
display_name = "Run Flow"
description = "A component to run a flow."
name = "RunFlow"
beta: bool = True
legacy: bool = True
icon = "workflow"

Expand Down
5 changes: 0 additions & 5 deletions src/backend/base/langflow/components/mem0/__init__.py

This file was deleted.

6 changes: 2 additions & 4 deletions src/backend/base/langflow/components/memories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from .astra_db import AstraDBChatMemory
from .cassandra import CassandraChatMemory
from .memory import MemoryComponent
from .mem0_chat_memory import Mem0MemoryComponent
from .redis import RedisIndexChatMemory
from .store_message import StoreMessageComponent
from .zep import ZepChatMemory

__all__ = [
"AstraDBChatMemory",
"CassandraChatMemory",
"MemoryComponent",
"RedisIndexChatMemory",
"ZepChatMemory",
"StoreMessageComponent",
"Mem0MemoryComponent",
]
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/models/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def get_model(self, base_url_value: str) -> list[str]:
raise ValueError(msg) from e

inputs = [
*LCModelComponent._base_inputs,
StrInput(
name="base_url",
display_name="Base URL",
Expand Down Expand Up @@ -151,7 +150,7 @@ def get_model(self, base_url_value: str) -> list[str]:
name="top_k", display_name="Top K", info="Limits token selection to top K. (Default: 40)", advanced=True
),
FloatInput(name="top_p", display_name="Top P", info="Works together with top-k. (Default: 0.9)", advanced=True),
BoolInput(name="verbose", display_name="Verbose", info="Whether to print out response text."),
BoolInput(name="verbose", display_name="Verbose", info="Whether to print out response text.", advanced=True),
StrInput(
name="tags",
display_name="Tags",
Expand All @@ -173,6 +172,7 @@ def get_model(self, base_url_value: str) -> list[str]:
advanced=True,
input_types=["OutputParser"],
),
*LCModelComponent._base_inputs,
]

def build_model(self) -> LanguageModel: # type: ignore[type-var]
Expand Down
2 changes: 2 additions & 0 deletions src/backend/base/langflow/components/processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .parse_data import ParseDataComponent
from .parse_json_data import ParseJSONDataComponent
from .select_data import SelectDataComponent
from .split_text import SplitTextComponent
from .update_data import UpdateDataComponent

__all__ = [
Expand All @@ -22,4 +23,5 @@
"ParseJSONDataComponent",
"JSONCleaner",
"CombineTextComponent",
"SplitTextComponent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CreateDataComponent(Component):
description: str = "Dynamically create a Data with a specified number of fields."
name: str = "CreateData"
MAX_FIELDS = 15 # Define a constant for maximum number of fields
legacy = True

inputs = [
IntInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ExtractDataKeyComponent(Component):
"Data objects and return the extracted value(s) as Data object(s)."
)
icon = "key"
beta = True
name = "ExtractaKey"
legacy = True

inputs = [
DataInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SelectDataComponent(Component):
description: str = "Select a single data from a list of data."
name: str = "SelectData"
icon = "prototypes"
legacy = True

inputs = [
DataInput(
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/tools/astradb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class AstraDBToolComponent(LCToolComponent):
display_name: str = "Astra DB Tool"
display_name: str = "Astra DB"
description: str = "Create a tool to get data from DataStax Astra DB Collection"
documentation: str = "https://astra.datastax.com"
icon: str = "AstraDB"
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/tools/astradb_cql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class AstraDBCQLToolComponent(LCToolComponent):
display_name: str = "Astra DB CQL Tool"
display_name: str = "Astra DB CQL"
description: str = "Create a tool to get data from DataStax Astra DB CQL Table"
documentation: str = "https://astra.datastax.com"
icon: str = "AstraDB"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PythonCodeStructuredTool(LCToolComponent):
"_classes",
"_functions",
]
display_name = "Python Code Structured Tool"
display_name = "Python Code Structured"
description = "structuredtool dataclass code to tool"
documentation = "https://python.langchain.com/docs/modules/tools/custom_tools/#structuredtool-dataclass"
name = "PythonCodeStructuredTool"
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/tools/python_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class PythonREPLToolComponent(LCToolComponent):
display_name = "Python REPL Tool"
display_name = "Python REPL"
description = "A tool for running Python code in a REPL environment."
name = "PythonREPLTool"

Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/tools/searxng.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class SearXNGToolComponent(LCToolComponent):
search_headers: dict = {}
display_name = "SearXNG Search Tool"
display_name = "SearXNG Search"
description = "A component that searches for tools using SearXNG."
name = "SearXNGTool"
legacy: bool = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
class WolframAlphaAPIComponent(LCToolComponent):
display_name = "WolframAlpha API"
description = """Enables queries to Wolfram Alpha for computational data, facts, and calculations across various \
topics, delivering structured responses. Example query: 'What is the population of France?'"""
topics, delivering structured responses."""
name = "WolframAlphaAPI"

inputs = [
MultilineInput(
name="input_value",
display_name="Input Query",
name="input_value", display_name="Input Query", info="Example query: 'What is the population of France?'"
),
SecretStrInput(name="app_id", display_name="App ID", required=True),
]
Expand Down
3 changes: 2 additions & 1 deletion src/backend/base/langflow/components/tools/yahoo_finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class YahooFinanceSchema(BaseModel):

class YfinanceToolComponent(LCToolComponent):
display_name = "Yahoo Finance"
description = "Access financial data and market information using Yahoo Finance."
description = """Uses [yfinance](https://pypi.org/project/yfinance/) (unofficial package) \
to access financial data and market information from Yahoo Finance."""
icon = "trending-up"
name = "YahooFinanceTool"

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2956,7 +2956,7 @@
"show": true,
"title_case": false,
"type": "code",
"value": "import ast\nimport pprint\nfrom enum import Enum\n\nimport yfinance as yf\nfrom langchain.tools import StructuredTool\nfrom langchain_core.tools import ToolException\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import DropdownInput, IntInput, MessageTextInput\nfrom langflow.schema import Data\n\n\nclass YahooFinanceMethod(Enum):\n GET_INFO = \"get_info\"\n GET_NEWS = \"get_news\"\n GET_ACTIONS = \"get_actions\"\n GET_ANALYSIS = \"get_analysis\"\n GET_BALANCE_SHEET = \"get_balance_sheet\"\n GET_CALENDAR = \"get_calendar\"\n GET_CASHFLOW = \"get_cashflow\"\n GET_INSTITUTIONAL_HOLDERS = \"get_institutional_holders\"\n GET_RECOMMENDATIONS = \"get_recommendations\"\n GET_SUSTAINABILITY = \"get_sustainability\"\n GET_MAJOR_HOLDERS = \"get_major_holders\"\n GET_MUTUALFUND_HOLDERS = \"get_mutualfund_holders\"\n GET_INSIDER_PURCHASES = \"get_insider_purchases\"\n GET_INSIDER_TRANSACTIONS = \"get_insider_transactions\"\n GET_INSIDER_ROSTER_HOLDERS = \"get_insider_roster_holders\"\n GET_DIVIDENDS = \"get_dividends\"\n GET_CAPITAL_GAINS = \"get_capital_gains\"\n GET_SPLITS = \"get_splits\"\n GET_SHARES = \"get_shares\"\n GET_FAST_INFO = \"get_fast_info\"\n GET_SEC_FILINGS = \"get_sec_filings\"\n GET_RECOMMENDATIONS_SUMMARY = \"get_recommendations_summary\"\n GET_UPGRADES_DOWNGRADES = \"get_upgrades_downgrades\"\n GET_EARNINGS = \"get_earnings\"\n GET_INCOME_STMT = \"get_income_stmt\"\n\n\nclass YahooFinanceSchema(BaseModel):\n symbol: str = Field(..., description=\"The stock symbol to retrieve data for.\")\n method: YahooFinanceMethod = Field(YahooFinanceMethod.GET_INFO, description=\"The type of data to retrieve.\")\n num_news: int | None = Field(5, description=\"The number of news articles to retrieve.\")\n\n\nclass YfinanceToolComponent(LCToolComponent):\n display_name = \"Yahoo Finance\"\n description = \"Access financial data and market information using Yahoo Finance.\"\n icon = \"trending-up\"\n name = \"YahooFinanceTool\"\n\n inputs = [\n MessageTextInput(\n name=\"symbol\",\n display_name=\"Stock Symbol\",\n info=\"The stock symbol to retrieve data for (e.g., AAPL, GOOG).\",\n ),\n DropdownInput(\n name=\"method\",\n display_name=\"Data Method\",\n info=\"The type of data to retrieve.\",\n options=list(YahooFinanceMethod),\n value=\"get_news\",\n ),\n IntInput(\n name=\"num_news\",\n display_name=\"Number of News\",\n info=\"The number of news articles to retrieve (only applicable for get_news).\",\n value=5,\n ),\n ]\n\n def run_model(self) -> list[Data]:\n return self._yahoo_finance_tool(\n self.symbol,\n self.method,\n self.num_news,\n )\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"yahoo_finance\",\n description=\"Access financial data and market information from Yahoo Finance.\",\n func=self._yahoo_finance_tool,\n args_schema=YahooFinanceSchema,\n )\n\n def _yahoo_finance_tool(\n self,\n symbol: str,\n method: YahooFinanceMethod,\n num_news: int | None = 5,\n ) -> list[Data]:\n ticker = yf.Ticker(symbol)\n\n try:\n if method == YahooFinanceMethod.GET_INFO:\n result = ticker.info\n elif method == YahooFinanceMethod.GET_NEWS:\n result = ticker.news[:num_news]\n else:\n result = getattr(ticker, method.value)()\n\n result = pprint.pformat(result)\n\n if method == YahooFinanceMethod.GET_NEWS:\n data_list = [Data(data=article) for article in ast.literal_eval(result)]\n else:\n data_list = [Data(data={\"result\": result})]\n\n except Exception as e:\n error_message = f\"Error retrieving data: {e}\"\n logger.debug(error_message)\n self.status = error_message\n raise ToolException(error_message) from e\n\n return data_list\n"
"value": "import ast\nimport pprint\nfrom enum import Enum\n\nimport yfinance as yf\nfrom langchain.tools import StructuredTool\nfrom langchain_core.tools import ToolException\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import DropdownInput, IntInput, MessageTextInput\nfrom langflow.schema import Data\n\n\nclass YahooFinanceMethod(Enum):\n GET_INFO = \"get_info\"\n GET_NEWS = \"get_news\"\n GET_ACTIONS = \"get_actions\"\n GET_ANALYSIS = \"get_analysis\"\n GET_BALANCE_SHEET = \"get_balance_sheet\"\n GET_CALENDAR = \"get_calendar\"\n GET_CASHFLOW = \"get_cashflow\"\n GET_INSTITUTIONAL_HOLDERS = \"get_institutional_holders\"\n GET_RECOMMENDATIONS = \"get_recommendations\"\n GET_SUSTAINABILITY = \"get_sustainability\"\n GET_MAJOR_HOLDERS = \"get_major_holders\"\n GET_MUTUALFUND_HOLDERS = \"get_mutualfund_holders\"\n GET_INSIDER_PURCHASES = \"get_insider_purchases\"\n GET_INSIDER_TRANSACTIONS = \"get_insider_transactions\"\n GET_INSIDER_ROSTER_HOLDERS = \"get_insider_roster_holders\"\n GET_DIVIDENDS = \"get_dividends\"\n GET_CAPITAL_GAINS = \"get_capital_gains\"\n GET_SPLITS = \"get_splits\"\n GET_SHARES = \"get_shares\"\n GET_FAST_INFO = \"get_fast_info\"\n GET_SEC_FILINGS = \"get_sec_filings\"\n GET_RECOMMENDATIONS_SUMMARY = \"get_recommendations_summary\"\n GET_UPGRADES_DOWNGRADES = \"get_upgrades_downgrades\"\n GET_EARNINGS = \"get_earnings\"\n GET_INCOME_STMT = \"get_income_stmt\"\n\n\nclass YahooFinanceSchema(BaseModel):\n symbol: str = Field(..., description=\"The stock symbol to retrieve data for.\")\n method: YahooFinanceMethod = Field(YahooFinanceMethod.GET_INFO, description=\"The type of data to retrieve.\")\n num_news: int | None = Field(5, description=\"The number of news articles to retrieve.\")\n\n\nclass YfinanceToolComponent(LCToolComponent):\n display_name = \"Yahoo Finance\"\n description = \"\"\"Uses [yfinance](https://pypi.org/project/yfinance/) (unofficial package) \\\nto access financial data and market information from Yahoo Finance.\"\"\"\n icon = \"trending-up\"\n name = \"YahooFinanceTool\"\n\n inputs = [\n MessageTextInput(\n name=\"symbol\",\n display_name=\"Stock Symbol\",\n info=\"The stock symbol to retrieve data for (e.g., AAPL, GOOG).\",\n ),\n DropdownInput(\n name=\"method\",\n display_name=\"Data Method\",\n info=\"The type of data to retrieve.\",\n options=list(YahooFinanceMethod),\n value=\"get_news\",\n ),\n IntInput(\n name=\"num_news\",\n display_name=\"Number of News\",\n info=\"The number of news articles to retrieve (only applicable for get_news).\",\n value=5,\n ),\n ]\n\n def run_model(self) -> list[Data]:\n return self._yahoo_finance_tool(\n self.symbol,\n self.method,\n self.num_news,\n )\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"yahoo_finance\",\n description=\"Access financial data and market information from Yahoo Finance.\",\n func=self._yahoo_finance_tool,\n args_schema=YahooFinanceSchema,\n )\n\n def _yahoo_finance_tool(\n self,\n symbol: str,\n method: YahooFinanceMethod,\n num_news: int | None = 5,\n ) -> list[Data]:\n ticker = yf.Ticker(symbol)\n\n try:\n if method == YahooFinanceMethod.GET_INFO:\n result = ticker.info\n elif method == YahooFinanceMethod.GET_NEWS:\n result = ticker.news[:num_news]\n else:\n result = getattr(ticker, method.value)()\n\n result = pprint.pformat(result)\n\n if method == YahooFinanceMethod.GET_NEWS:\n data_list = [Data(data=article) for article in ast.literal_eval(result)]\n else:\n data_list = [Data(data={\"result\": result})]\n\n except Exception as e:\n error_message = f\"Error retrieving data: {e}\"\n logger.debug(error_message)\n self.status = error_message\n raise ToolException(error_message) from e\n\n return data_list\n"
},
"method": {
"_input_type": "DropdownInput",
Expand Down
Loading
Loading