[Docs] - Example Components (#2022)
* Remove outdated pages from example folder * Repopulate with component-of-the-day pages with videos * Update Notion index image * Python version 3.10 -> Python >= 3.10
This commit is contained in:
commit
e22f0c2d9d
27 changed files with 129 additions and 692 deletions
|
|
@ -74,11 +74,6 @@ class DocumentProcessor(CustomComponent):
|
|||
|
||||
</div>
|
||||
|
||||
<Admonition type="tip">
|
||||
Check out [FlowRunner Component](../examples/flow-runner) for a more complex
|
||||
example.
|
||||
</Admonition>
|
||||
|
||||
---
|
||||
|
||||
## Rules
|
||||
|
|
|
|||
|
|
@ -100,7 +100,3 @@ The `CustomComponent` class also provides helpful methods for specific tasks (e.
|
|||
- `field_order`: Controls the display order of fields.
|
||||
- `icon`: Sets the canvas display icon.
|
||||
|
||||
<Admonition type="info" label="Tip">
|
||||
Check out the [FlowRunner](../examples/flow-runner) example to understand how to call a flow from a custom component.
|
||||
</Admonition>
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/buffer-memory.png",
|
||||
dark: "img/buffer-memory.png",
|
||||
}}
|
||||
style={{
|
||||
width: "80%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/Buffer_Memory.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`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)
|
||||
|
||||
</Admonition>
|
||||
17
docs/docs/examples/chat-memory.mdx
Normal file
17
docs/docs/examples/chat-memory.mdx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Chat Memory
|
||||
|
||||
The **Chat Memory** component restores previous messages given a Session ID, which can be any string.
|
||||
|
||||
This component is available under the **Helpers** tab of the Langflow preview.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/chat_memory.mp4" />
|
||||
</div>
|
||||
21
docs/docs/examples/combine-text.mdx
Normal file
21
docs/docs/examples/combine-text.mdx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Combine Text
|
||||
|
||||
With LLM pipelines, combining text from different sources may be as important as splitting text.
|
||||
|
||||
The **Combine Text** component concatenates two text inputs into a single chunk using a specified delimiter, such as whitespace or a newline.
|
||||
|
||||
Also, check out **Combine Texts (Unsorted)** as a similar alternative.
|
||||
|
||||
This component is available under the **Helpers** tab of the Langflow preview.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/combine_text.mp4" />
|
||||
</div>
|
||||
|
|
@ -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.
|
||||
|
||||
<Admonition type="info">
|
||||
|
||||
Make sure to always get the API key from the provider.
|
||||
|
||||
</Admonition>
|
||||
|
||||
## ⛓️ Langflow Example
|
||||
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/basic-chat.png",
|
||||
dark: "img/basic-chat.png",
|
||||
}}
|
||||
|
||||
style={{
|
||||
width: "80%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/Basic_Chat.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`ConversationChain`](https://python.langchain.com/docs/modules/chains/)
|
||||
- [`ChatOpenAI`](https://python.langchain.com/docs/modules/model_io/models/chat/integrations/openai)
|
||||
|
||||
</Admonition>
|
||||
17
docs/docs/examples/create-record.mdx
Normal file
17
docs/docs/examples/create-record.mdx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Create Record
|
||||
|
||||
In Langflow, a `Record` has a structure very similar to a Python dictionary. It is a key-value pair data structure.
|
||||
|
||||
The **Create Record** component allows you to dynamically create a `Record` from a specified number of inputs. You can add as many key-value pairs as you want (as long as it is less than 15 😅). Once you've chosen the number of `Records`, add keys and fill up values, or pass on values from other components to the component using the input handles.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/create_record.mp4" />
|
||||
</div>
|
||||
|
|
@ -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.
|
||||
|
||||
<Admonition type="info">
|
||||
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).
|
||||
</Admonition>
|
||||
|
||||
<Admonition type="tip">
|
||||
Once you build this flow, ask questions about the data in the chat interface
|
||||
(e.g., number of rows or columns).
|
||||
</Admonition>
|
||||
|
||||
## ⛓️ Langflow Example
|
||||
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/csv-loader.png",
|
||||
dark: "img/csv-loader.png",
|
||||
}}
|
||||
style={{
|
||||
width: "80%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/CSV_Loader.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`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)
|
||||
|
||||
</Admonition>
|
||||
|
|
@ -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".
|
||||
|
||||
<ZoomableImage
|
||||
alt="Document Processor Component"
|
||||
sources={{
|
||||
light: "img/flow_runner.png",
|
||||
dark: "img/flow_runner.png",
|
||||
}}
|
||||
style={{
|
||||
width: "30%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
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.
|
||||
|
||||
<details open>
|
||||
|
||||
<summary>Example Code</summary>
|
||||
|
||||
```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))
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<CH.Scrollycoding rows={20} className={""}>
|
||||
|
||||
```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).
|
||||
|
||||
<Admonition type="caution">
|
||||
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.
|
||||
</Admonition>
|
||||
|
||||
---
|
||||
|
||||
```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.
|
||||
|
||||
<Admonition type="caution">
|
||||
Make sure that the field type is _`str`_ and _`options`_ values are strings.
|
||||
</Admonition>
|
||||
|
||||
</CH.Scrollycoding>
|
||||
|
||||
Done! This is what our script and custom component looks like:
|
||||
|
||||
<div style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}>
|
||||
|
||||
<ZoomableImage
|
||||
alt="Document Processor Code"
|
||||
sources={{
|
||||
light: "img/flow_runner_code.png",
|
||||
dark: "img/flow_runner_code.png",
|
||||
}}
|
||||
style={{
|
||||
maxWidth: "100%",
|
||||
margin: "0 auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
|
||||
/>
|
||||
|
||||
<ZoomableImage
|
||||
alt="Document Processor Component"
|
||||
sources={{
|
||||
light: "img/flow_runner.png",
|
||||
dark: "img/flow_runner.png",
|
||||
}}
|
||||
style={{
|
||||
width: "40%",
|
||||
margin: "0 auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import Admonition from "@theme/Admonition";
|
||||
17
docs/docs/examples/pass.mdx
Normal file
17
docs/docs/examples/pass.mdx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Pass
|
||||
|
||||
Sometimes all you need to do is… nothing!
|
||||
|
||||
The **Pass** component enables you to ignore one input and move forward with another one. This is super helpful to swap routes for A/B testing!
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/pass.mp4" />
|
||||
</div>
|
||||
|
|
@ -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
|
||||
```
|
||||
|
||||
<Admonition type="tip">
|
||||
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.
|
||||
</Admonition>
|
||||
|
||||
The `AgentInitializer` component is a quick way to construct an agent from the model and tools.
|
||||
|
||||
<Admonition type="info">
|
||||
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).
|
||||
</Admonition>
|
||||
|
||||
## ⛓️ Langflow Example
|
||||
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/python-function.png",
|
||||
dark: "img/python-function.png",
|
||||
}}
|
||||
style={{
|
||||
width: "80%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/Python_Function.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`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/)
|
||||
|
||||
</Admonition>
|
||||
|
|
@ -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.
|
||||
|
||||
<Admonition type="info">
|
||||
To use the SearchApi, you must first obtain an API key by registering at [SearchApi's website](https://www.searchapi.io/).
|
||||
</Admonition>
|
||||
|
||||
In the given example, we specify `engine` as `youtube_transcripts` and provide a `video_id`.
|
||||
|
||||
<Admonition type="info">
|
||||
All engines and parameters can be found in [SearchApi documentation](https://www.searchapi.io/docs/google).
|
||||
</Admonition>
|
||||
|
||||
The `RetrievalQA` chain processes a `Document` along with a user's question to return an answer.
|
||||
|
||||
<Admonition type="tip">
|
||||
In this example, we used [`ChatOpenAI`](https://platform.openai.com/) as the
|
||||
LLM, but feel free to experiment with other Language Models!
|
||||
</Admonition>
|
||||
|
||||
The `RetrievalQA` takes `CombineDocsChain` and `SearchApi` tool as inputs, using the tool as a `Document` to answer questions.
|
||||
|
||||
<Admonition type="info">
|
||||
Learn more about the SearchApi
|
||||
[here](https://python.langchain.com/docs/integrations/tools/searchapi).
|
||||
</Admonition>
|
||||
|
||||
## ⛓️ Langflow Example
|
||||
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/searchapi-tool.png",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/SearchApi_Tool.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`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)
|
||||
|
||||
</Admonition>
|
||||
|
|
@ -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.
|
||||
|
||||
<Admonition type="info">
|
||||
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.
|
||||
</Admonition>
|
||||
|
||||
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.
|
||||
|
||||
<Admonition type="tip">
|
||||
In this example, we used [`ChatOpenAI`](https://platform.openai.com/) as the
|
||||
LLM, but feel free to experiment with other Language Models!
|
||||
</Admonition>
|
||||
|
||||
The `ZeroShotAgent` takes the `LLMChain` and the `Search` tool as inputs, using the tool to find information when necessary.
|
||||
|
||||
<Admonition type="info">
|
||||
Learn more about the Serp API
|
||||
[here](https://python.langchain.com/docs/integrations/providers/serpapi ).
|
||||
</Admonition>
|
||||
|
||||
## ⛓️ Langflow Example
|
||||
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
<ZoomableImage
|
||||
alt="Docusaurus themed image"
|
||||
sources={{
|
||||
light: "img/serp-api-tool.png",
|
||||
dark: "img/serp-api-tool.png",
|
||||
}}
|
||||
style={{
|
||||
width: "80%",
|
||||
margin: "20px auto",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/SerpAPI_Tool.json" download>Download Flow</a>
|
||||
|
||||
<Admonition type="note" title="LangChain Components 🦜🔗">
|
||||
|
||||
- [`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)
|
||||
|
||||
</Admonition>
|
||||
17
docs/docs/examples/store-message.mdx
Normal file
17
docs/docs/examples/store-message.mdx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Store Message
|
||||
|
||||
The **Store Message** component allows you to save information under a specified Session ID and sender type.
|
||||
|
||||
The **Message History** component can then be used to retrieve stored messages.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/store_message.mp4" />
|
||||
</div>
|
||||
15
docs/docs/examples/sub-flow.mdx
Normal file
15
docs/docs/examples/sub-flow.mdx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Sub Flow
|
||||
|
||||
The **Sub Flow** component enables a user to select a previously built flow and dynamically generate a component out of it.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/sub_flow.mp4" />
|
||||
</div>
|
||||
15
docs/docs/examples/text-operator.mdx
Normal file
15
docs/docs/examples/text-operator.mdx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
import ReactPlayer from "react-player";
|
||||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Text Operator
|
||||
|
||||
The **Text Operator** component simplifies logic. It evaluates the results from another component (for example, if the input text exactly equals `Tuna`) and runs another component based on the results. Basically, the text operator is an if/else component for your flow.
|
||||
|
||||
<div
|
||||
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
|
||||
>
|
||||
<ReactPlayer playing controls url="/videos/text_operator.mp4" />
|
||||
</div>
|
||||
|
|
@ -9,7 +9,7 @@ import Admonition from "@theme/Admonition";
|
|||
Langflow v1.0 alpha is also available in HuggingFace Spaces. [Clone the space using this link](https://huggingface.co/spaces/Langflow/Langflow-Preview?duplicate=true), to create your own Langflow workspace in minutes.
|
||||
</Admonition>
|
||||
|
||||
Langflow requires [Python 3.10](https://www.python.org/downloads/release/python-3100/) and [pip](https://pypi.org/project/pip/) or [pipx](https://pipx.pypa.io/stable/installation/) to be installed on your system.
|
||||
Langflow requires [Python >=3.10](https://www.python.org/downloads/release/python-3100/) and [pip](https://pypi.org/project/pip/) or [pipx](https://pipx.pypa.io/stable/installation/) to be installed on your system.
|
||||
|
||||
Install Langflow with pip:
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ The Notion integration in Langflow enables seamless connectivity with Notion dat
|
|||
<ZoomableImage
|
||||
alt="Notion Components in Langflow"
|
||||
sources={{
|
||||
light: "img/notion/notion_components_bundle.png",
|
||||
dark: "img/notion/notion_components_bundle_dark.png",
|
||||
light: "img/notion/notion_bundle.jpg",
|
||||
dark: "img/notion/notion_bundle.jpg",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@ module.exports = {
|
|||
label: "Example Components",
|
||||
collapsed: true,
|
||||
items: [
|
||||
"examples/flow-runner",
|
||||
"examples/conversation-chain",
|
||||
"examples/buffer-memory",
|
||||
"examples/csv-loader",
|
||||
"examples/searchapi-tool",
|
||||
"examples/serp-api-tool",
|
||||
"examples/python-function",
|
||||
"examples/chat-memory",
|
||||
"examples/combine-text",
|
||||
"examples/create-record",
|
||||
"examples/pass",
|
||||
"examples/store-message",
|
||||
"examples/sub-flow",
|
||||
"examples/text-operator",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
BIN
docs/static/img/notion/notion_bundle.jpg
vendored
Normal file
BIN
docs/static/img/notion/notion_bundle.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
docs/static/videos/chat_memory.mp4
vendored
Normal file
BIN
docs/static/videos/chat_memory.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/combine_text.mp4
vendored
Normal file
BIN
docs/static/videos/combine_text.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/create_record.mp4
vendored
Normal file
BIN
docs/static/videos/create_record.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/pass.mp4
vendored
Normal file
BIN
docs/static/videos/pass.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/store_message.mp4
vendored
Normal file
BIN
docs/static/videos/store_message.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/sub_flow.mp4
vendored
Normal file
BIN
docs/static/videos/sub_flow.mp4
vendored
Normal file
Binary file not shown.
BIN
docs/static/videos/text_operator.mp4
vendored
Normal file
BIN
docs/static/videos/text_operator.mp4
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue