diff --git a/docs/docs/examples/buffer-memory.mdx b/docs/docs/examples/buffer-memory.mdx deleted file mode 100644 index b196f9031..000000000 --- a/docs/docs/examples/buffer-memory.mdx +++ /dev/null @@ -1,35 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# Buffer Memory - -For certain applications, retaining past interactions is crucial. For that, chains and agents may accept a memory component as one of their input parameters. The `ConversationBufferMemory` component is one of them. It stores messages and extracts them into variables. - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`ConversationBufferMemory`](https://python.langchain.com/docs/modules/memory/types/buffer) -- [`ConversationChain`](https://python.langchain.com/docs/modules/chains/) -- [`ChatOpenAI`](https://python.langchain.com/docs/modules/model_io/models/chat/integrations/openai) - - diff --git a/docs/docs/examples/conversation-chain.mdx b/docs/docs/examples/conversation-chain.mdx deleted file mode 100644 index 294d1b440..000000000 --- a/docs/docs/examples/conversation-chain.mdx +++ /dev/null @@ -1,41 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# Conversation Chain - -This example shows how to instantiate a simple `ConversationChain` component using a Language Model (LLM). Once the Node Status turns green 🟢, the chat will be ready to take in user messages. Here, we used `ChatOpenAI` to act as the required LLM input, but you can use any LLM for this purpose. - - - -Make sure to always get the API key from the provider. - - - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`ConversationChain`](https://python.langchain.com/docs/modules/chains/) -- [`ChatOpenAI`](https://python.langchain.com/docs/modules/model_io/models/chat/integrations/openai) - - diff --git a/docs/docs/examples/csv-loader.mdx b/docs/docs/examples/csv-loader.mdx deleted file mode 100644 index 25f3bb444..000000000 --- a/docs/docs/examples/csv-loader.mdx +++ /dev/null @@ -1,57 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# CSV Loader - -The `VectoStoreAgent` component retrieves information from one or more vector stores. This example shows a `VectoStoreAgent` connected to a CSV file through the `Chroma` vector store. Process description: - -- The `CSVLoader` loads a CSV file into a list of documents. -- The extracted data is then processed by the `CharacterTextSplitter`, which splits the text into small, meaningful chunks (usually sentences). -- These chunks feed the `Chroma` vector store, which converts them into vectors and stores them for fast indexing. -- Finally, the agent accesses the information of the vector store through the `VectorStoreInfo` tool. - - - The vector store is used for efficient semantic search, while - `VectorStoreInfo` carries information about it, such as its name and - description. Embeddings are a way to represent words, phrases, or any entities - in a vector space. Learn more about them - [here](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings). - - - - Once you build this flow, ask questions about the data in the chat interface - (e.g., number of rows or columns). - - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`CSVLoader`](https://python.langchain.com/docs/integrations/document_loaders/csv) -- [`CharacterTextSplitter`](https://python.langchain.com/docs/modules/data_connection/document_transformers/text_splitters/character_text_splitter) -- [`OpenAIEmbedding`](https://python.langchain.com/docs/integrations/text_embedding/openai) -- [`Chroma`](https://python.langchain.com/docs/integrations/vectorstores/chroma) -- [`VectorStoreInfo`](https://python.langchain.com/docs/modules/data_connection/vectorstores/) -- [`OpenAI`](https://python.langchain.com/docs/modules/model_io/models/llms/integrations/openai) -- [`VectorStoreAgent`](https://js.langchain.com/docs/modules/agents/tools/how_to/agents_with_vectorstores) - - diff --git a/docs/docs/examples/flow-runner.mdx b/docs/docs/examples/flow-runner.mdx deleted file mode 100644 index fda7a8d39..000000000 --- a/docs/docs/examples/flow-runner.mdx +++ /dev/null @@ -1,368 +0,0 @@ ---- -description: Custom Components -hide_table_of_contents: true ---- - -# FlowRunner Component - -The CustomComponent class allows us to create components that interact with Langflow itself. In this example, we will make a component that runs other flows available in "My Collection". - - - -We will cover how to: - -- List Collection flows using the _`list_flows`_ method. -- Load a flow using the _`load_flow`_ method. -- Configure a dropdown input field using the _`options`_ parameter. - -
- -Example Code - -```python -from langflow.custom import CustomComponent -from langchain.schema import Document - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - flows = self.list_flows() - flow_names = [f.name for f in flows] - return {"flow_name": {"options": flow_names, - "display_name": "Flow Name", - }, - "document": {"display_name": "Document"} - } - - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - # Get the flow that matches the selected name - # You can also get the flow by id - # using self.get_flow(flow_id=flow_id) - tweaks = {} - flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) - # Get the page_content from the document - if document and isinstance(document, list): - document = document[0] - page_content = document.page_content - # Use it in the flow - result = flow(page_content) - return Document(page_content=str(result)) - -``` - -
- - - -```python -from langflow.custom import CustomComponent - - -class MyComponent(CustomComponent): - display_name = "Custom Component" - description = "This is a custom component" - - def build_config(self): - ... - - def build(self): - ... - -``` - -The typical structure of a Custom Component is composed of _`display_name`_ and _`description`_ attributes, _`build`_ and _`build_config`_ methods. - ---- - -```python -from langflow.custom import CustomComponent - - -# focus -class FlowRunner(CustomComponent): - # focus - display_name = "Flow Runner" - # focus - description = "Run other flows" - - def build_config(self): - ... - - def build(self): - ... - -``` - -Let's start by defining our component's _`display_name`_ and _`description`_. - ---- - -```python -from langflow.custom import CustomComponent -# focus -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self): - ... - -``` - -Second, we will import _`Document`_ from the [_langchain.schema_](https://docs.langchain.com/docs/components/schema/) module. This will be the return type of the _`build`_ method. - ---- - -```python -from langflow.custom import CustomComponent -# focus -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - # focus - def build(self, flow_name: str, document: Document) -> Document: - ... - -``` - -Now, let's add the [parameters](focus://11[20:55]) and the [return type](focus://11[60:69]) to the _`build`_ method. The parameters added are: - -- _`flow_name`_ is the name of the flow we want to run. -- _`document`_ is the input document to be passed to that flow. - - Since _`Document`_ is a Langchain type, it will add an input [handle](../administration/components) to the component ([see more](../components/custom)). - ---- - -```python focus=13:14 -from langflow.custom import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - -``` - -We can now start writing the _`build`_ method. Let's list available flows in "My Collection" using the _`list_flows`_ method. - ---- - -```python focus=15:18 -from langflow.custom import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - # Get the flow that matches the selected name - # You can also get the flow by id - # using self.get_flow(flow_id=flow_id) - tweaks = {} - flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) - -``` - -And retrieve a flow that matches the selected name (we'll make a dropdown input field for the user to choose among flow names). - - - From version 0.4.0, names are unique, which was not the case in previous - versions. This might lead to unexpected results if using flows with the same - name. - - ---- - -```python -from langflow.custom import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - # Get the flow that matches the selected name - # You can also get the flow by id - # using self.get_flow(flow_id=flow_id) - tweaks = {} - flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) - - -``` - -You can load this flow using _`get_flow`_ and set a _`tweaks`_ dictionary to customize it. Find more about tweaks in our [features guidelines](../administration/features#code). - ---- - -```python -from langflow.custom import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - # Get the flow that matches the selected name - # You can also get the flow by id - # using self.get_flow(flow_id=flow_id) - tweaks = {} - flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) - # Get the page_content from the document - if document and isinstance(document, list): - document = document[0] - page_content = document.page_content - # Use it in the flow - result = flow(page_content) - return Document(page_content=str(result)) -``` - -We are using a _`Document`_ as input because it is a straightforward way to pass text data in Langflow (specifically because you can connect it to many [loaders](../components/loaders)). -Generally, a flow will take a string or a dictionary as input because that's what LangChain components expect. -In case you are passing a dictionary, you need to build it according to the needs of the flow you are using. - -The content of a document can be extracted using the _`page_content`_ attribute, which is a string, and passed as an argument to the selected flow. - ---- - -```python focus=9:16 -from langflow.custom import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - flows = self.list_flows() - flow_names = [f.name for f in flows] - return {"flow_name": {"options": flow_names, - "display_name": "Flow Name", - }, - "document": {"display_name": "Document"} - } - - def build(self, flow_name: str, document: Document) -> Document: - # List the flows - flows = self.list_flows() - # Get the flow that matches the selected name - # You can also get the flow by id - # using self.get_flow(flow_id=flow_id) - tweaks = {} - flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) - # Get the page_content from the document - if document and isinstance(document, list): - document = document[0] - page_content = document.page_content - # Use it in the flow - result = flow(page_content) - return Document(page_content=str(result)) -``` - -Finally, we can add field customizations through the _`build_config`_ method. Here we added the _`options`_ key to make the _`flow_name`_ field a dropdown menu. Check out the [custom component reference](../components/custom) for a list of available keys. - - - Make sure that the field type is _`str`_ and _`options`_ values are strings. - - - - -Done! This is what our script and custom component looks like: - -
- - - - - -
- -import ZoomableImage from "/src/theme/ZoomableImage.js"; -import Admonition from "@theme/Admonition"; diff --git a/docs/docs/examples/python-function.mdx b/docs/docs/examples/python-function.mdx deleted file mode 100644 index 2bb4b93e1..000000000 --- a/docs/docs/examples/python-function.mdx +++ /dev/null @@ -1,62 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# Python Function - -Langflow allows you to create a customized tool using the `PythonFunction` connected to a `Tool` component. In this example, Regex is used in Python to validate a pattern. - -```python -import re - -def is_brazilian_zipcode(zipcode: str) -> bool: - pattern = r"\d{5}-?\d{3}" - - # Check if the zip code matches the pattern - if re.match(pattern, zipcode): - return True - - return False -``` - - - When a tool is called, it is often desirable to have its output returned - directly to the user. You can do this by setting the **return_direct** flag - for a tool to be True. - - -The `AgentInitializer` component is a quick way to construct an agent from the model and tools. - - - The `PythonFunction` is a custom component that uses the LangChain 🦜🔗 tool - decorator. Learn more about it - [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools). - - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`PythonFunctionTool`](https://python.langchain.com/docs/modules/agents/tools/custom_tools) -- [`ChatOpenAI`](https://python.langchain.com/docs/modules/model_io/models/chat/integrations/openai) -- [`AgentInitializer`](https://python.langchain.com/docs/modules/agents/) - - diff --git a/docs/docs/examples/searchapi-tool.mdx b/docs/docs/examples/searchapi-tool.mdx deleted file mode 100644 index d3cb4734a..000000000 --- a/docs/docs/examples/searchapi-tool.mdx +++ /dev/null @@ -1,52 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# SearchApi Tool - -The [SearchApi](https://www.searchapi.io/) allows developers to retrieve results from search engines such as Google, Google Scholar, YouTube, YouTube transcripts, and more, and can be used as in Langflow through the `SearchApi` tool. - - - To use the SearchApi, you must first obtain an API key by registering at [SearchApi's website](https://www.searchapi.io/). - - -In the given example, we specify `engine` as `youtube_transcripts` and provide a `video_id`. - - - All engines and parameters can be found in [SearchApi documentation](https://www.searchapi.io/docs/google). - - -The `RetrievalQA` chain processes a `Document` along with a user's question to return an answer. - - - In this example, we used [`ChatOpenAI`](https://platform.openai.com/) as the - LLM, but feel free to experiment with other Language Models! - - -The `RetrievalQA` takes `CombineDocsChain` and `SearchApi` tool as inputs, using the tool as a `Document` to answer questions. - - - Learn more about the SearchApi - [here](https://python.langchain.com/docs/integrations/tools/searchapi). - - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`OpenAI`](https://python.langchain.com/docs/modules/model_io/models/llms/integrations/openai) -- [`SearchApiAPIWrapper`](https://python.langchain.com/docs/integrations/providers/searchapi#wrappers) -- [`ZeroShotAgent`](https://python.langchain.com/docs/modules/agents/how_to/custom_mrkl_agent) - - \ No newline at end of file diff --git a/docs/docs/examples/serp-api-tool.mdx b/docs/docs/examples/serp-api-tool.mdx deleted file mode 100644 index 175b6f1be..000000000 --- a/docs/docs/examples/serp-api-tool.mdx +++ /dev/null @@ -1,58 +0,0 @@ -import Admonition from "@theme/Admonition"; - -# Serp API Tool - -The [Serp API](https://serpapi.com/) (Search Engine Results Page) allows developers to scrape results from search engines such as Google, Bing and Yahoo, and can be used as in Langflow through the `Search` component. - - - To use the Serp API, you first need to sign up [Serp - API](https://serpapi.com/) for an API key on the provider's website. - - -Here, the `ZeroShotPrompt` component specifies a prompt template for the `ZeroShotAgent`. Set a _Prefix_ and _Suffix_ with rules for the agent to obey. In the example, we used default templates. - -The `LLMChain` is a simple chain that takes in a prompt template, formats it with the user input, and returns the response from an LLM. - - - In this example, we used [`ChatOpenAI`](https://platform.openai.com/) as the - LLM, but feel free to experiment with other Language Models! - - -The `ZeroShotAgent` takes the `LLMChain` and the `Search` tool as inputs, using the tool to find information when necessary. - - - Learn more about the Serp API - [here](https://python.langchain.com/docs/integrations/providers/serpapi ). - - -## ⛓️ Langflow Example - -import ThemedImage from "@theme/ThemedImage"; -import useBaseUrl from "@docusaurus/useBaseUrl"; -import ZoomableImage from "/src/theme/ZoomableImage.js"; - - - -#### Download Flow - - - -- [`ZeroShotPrompt`](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) -- [`OpenAI`](https://python.langchain.com/docs/modules/model_io/models/llms/integrations/openai) -- [`LLMChain`](https://python.langchain.com/docs/modules/chains/foundational/llm_chain) -- [`Search`](https://python.langchain.com/docs/integrations/providers/serpapi) -- [`ZeroShotAgent`](https://python.langchain.com/docs/modules/agents/how_to/custom_mrkl_agent) - -