Split Langflow into Langflow and Langflow Base (#1562)

* Initial Restructure

* Replace import langflow for import langflow_base

* Fix dependencies

* 🔧 chore(Makefile): refactor build process to separate base and frontend builds for better organization and maintainability

* 🚀 chore(Makefile): update build_frontend command to copy frontend build to the correct directory
🔖 chore(pyproject.toml): update python and httpx dependencies versions
🔧 chore(__init__.py): update import statement for load_flow_from_json function

* 🔖 chore(pyproject.toml): update package version from 0.0.6 to 0.0.8 to reflect changes in the codebase

* 🚀 feat(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics
🚀 feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port

* 🐛 fix(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics
✨ feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port
🚚 chore(pyproject.toml): update langflow-base version from 0.0.8 to 0.0.10
✨ feat(server.ts): add new agent component LCAgentComponent to langflow_base
✨ feat(server.ts): add new model component LCModelComponent to langflow_base
✨ feat(server.ts): add new helper functions docs_to_records and records_to_text to langflow_base
✨ feat(server.ts): add new flow helper functions list_flows, load_flow, run_flow, generate_function_for_flow, get_flow_inputs, build_schema_from_inputs to langflow_base
✨ feat(server.ts): add new prompt component PromptComponent to langflow_base
✨ feat(server.ts): add new chat components ChatInput and ChatOutput to langflow_base
✨ feat(server.ts): add new model component OpenAIModelComponent to langflow_base
🚚 chore(main.py): update import path from langflow.main to langflow_base.main
🚚 chore(service.py): update import path from langflow.services.database.manager to langflow_base.services.database.manager
🚚 chore(factory.py): update import path from langflow.services to langflow_base.services
🚚 chore(service.py): update import path from langflow.services.plugins to langflow_base.services.plugins
🚚 chore(utils.py): update import path from langflow.services to langflow_base.services
🚚 chore(validate.py): update import path from langflow.field_typing to langflow_base.field_typing
🚚 chore(pyproject.toml): update langflow-base version from 0.0.8 to 0.0.10

* Update Makefile to install backend dependencies and build langflow

* Add langflow main module and update __init__.py

* Update langflow install process to use implicit namespace

* Add langflow-base as a local dependency

* Add setup_poetry target to Makefile

* Update Poetry version and add poetry-monorepo-dependency-plugin

* Refactor code to improve performance and readability

* Update imports to custom and load

* Update content-hash in poetry.lock

---------

Co-authored-by: Matheus <jacquesmats@gmail.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@logspace.ai>
This commit is contained in:
Matheus Jacques 2024-03-26 13:26:30 +01:00 • committed by GitHub
commit 8172e62236
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
466 changed files with 5418 additions and 1144 deletions

View file

@ -35,7 +35,7 @@ We will cover how to:
<summary>Example Code</summary>
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class FlowRunner(CustomComponent):
@ -75,7 +75,7 @@ class FlowRunner(CustomComponent):
<CH.Scrollycoding rows={20} className={""}>
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
class MyComponent(CustomComponent):
@ -95,7 +95,7 @@ The typical structure of a Custom Component is composed of _`display_name`_ and
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
# focus
@ -118,7 +118,7 @@ Let's start by defining our component's _`display_name`_ and _`description`_.
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
# focus
from langchain.schema import Document
@ -140,7 +140,7 @@ Second, we will import _`Document`_ from the [_langchain.schema_](https://docs.l
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
# focus
from langchain.schema import Document
@ -167,7 +167,7 @@ Now, let's add the [parameters](focus://11[20:55]) and the [return type](focus:/
---
```python focus=13:14
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
@ -189,7 +189,7 @@ We can now start writing the _`build`_ method. Let's list available flows in "My
---
```python focus=15:18
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
@ -222,7 +222,7 @@ And retrieve a flow that matches the selected name (we'll make a dropdown input
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
@ -250,7 +250,7 @@ You can load this flow using _`get_flow`_ and set a _`tweaks`_ dictionary to cus
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
@ -287,7 +287,7 @@ The content of a document can be extracted using the _`page_content`_ attribute,
---
```python focus=9:16
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
@ -365,4 +365,6 @@ Done! This is what our script and custom component looks like:
}}
/>
</div>
</div>import ZoomableImage from "/src/theme/ZoomableImage.js";
import Admonition from "@theme/Admonition";

View file

@ -30,7 +30,7 @@ Here is an example:
<CH.Code linuNumbers={false}>
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class DocumentProcessor(CustomComponent):
@ -92,7 +92,7 @@ The Python script for every Custom Component should follow a set of rules. Let's
The script must contain a **single class** that inherits from _`CustomComponent`_.
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class MyComponent(CustomComponent):
@ -113,7 +113,7 @@ class MyComponent(CustomComponent):
This class requires a _`build`_ method used to run the component and define its fields.
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class MyComponent(CustomComponent):
@ -134,7 +134,7 @@ class MyComponent(CustomComponent):
The [Return Type Annotation](https://docs.python.org/3/library/typing.html) of the _`build`_ method defines the component type (e.g., Chain, BaseLLM, or basic Python types). Check out all supported types in the [component reference](../components/custom).
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class MyComponent(CustomComponent):
@ -153,7 +153,7 @@ class MyComponent(CustomComponent):
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class MyComponent(CustomComponent):
@ -179,7 +179,7 @@ Check out the [component reference](../components/custom) for more details on th
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class MyComponent(CustomComponent):
@ -204,7 +204,7 @@ Let's create a custom component that processes a document (_`langchain.schema.Do
To start, let's choose a name for our component by adding a _`display_name`_ attribute. This name will appear on the canvas. The name of the class is not relevant, but let's call it _`DocumentProcessor`_.
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
# focus
@ -227,7 +227,7 @@ class DocumentProcessor(CustomComponent):
We can also write a description for it using a _`description`_ attribute.
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class DocumentProcessor(CustomComponent):
@ -244,7 +244,7 @@ class DocumentProcessor(CustomComponent):
---
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class DocumentProcessor(CustomComponent):
@ -287,7 +287,7 @@ The _`build_config`_ method is here defined to customize the component fields.
- _`display_name`_ is the name of the field to be displayed.
```python
from langflow import CustomComponent
from langflow.custom import CustomComponent
from langchain.schema import Document
class DocumentProcessor(CustomComponent):
@ -406,4 +406,6 @@ Langflow will attempt to load all of the components found in the specified direc
Once your custom components have been loaded successfully, they will appear in Langflow's sidebar. From there, you can add them to your Langflow canvas for use. However, please note that components with errors will not be available for addition to the canvas. Always ensure your code is error-free before attempting to load components.
Remember, creating custom components allows you to extend the functionality of Langflow to better suit your unique needs. Happy coding!
Remember, creating custom components allows you to extend the functionality of Langflow to better suit your unique needs. Happy coding!import ZoomableImage from "/src/theme/ZoomableImage.js";
import Admonition from "@theme/Admonition";

View file

@ -49,7 +49,7 @@ The Code button shows snippets to use your flow as a Python object or an API.
Through the Langflow package, you can load a flow from a JSON file and use it as a LangChain object.
```py
from langflow import load_flow_from_json
from langflow.load import load_flow_from_json
flow = load_flow_from_json("path/to/flow.json")
# Now you can use it like any chain
@ -66,4 +66,9 @@ The example below shows a Python script making a POST request to a local API end
style={{ marginBottom: "20px", display: "flex", justifyContent: "center" }}
>
<ReactPlayer playing controls url="/videos/langflow_api.mp4" />
</div>
</div>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";