Langflow is a powerful tool for building and deploying AI-powered agents and workflows. http://www.langflow.org
Find a file
Gabriel Luiz Freitas Almeida be87c9e43e
refactor(graph): add prepare method in Graph (#3124)
* refactor: update code references to use _code instead of code

* refactor: add backwards compatible attributes to Component class

* refactor: update Component constructor to pass config params with underscore

Refactored the `Component` class in `component.py` to handle inputs and outputs. Added a new method `map_outputs` to map a list of outputs to the component. Also updated the `__init__` method to properly initialize the inputs, outputs, and other attributes. This change improves the flexibility and extensibility of the `Component` class.

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* refactor: change attribute to use underscore

* refactor: update CustomComponent initialization parameters

Refactored the `instantiate_class` function in `loading.py` to update the initialization parameters for the `CustomComponent` class. Changed the parameter names from `user_id`, `parameters`, `vertex`, and `tracing_service` to `_user_id`, `_parameters`, `_vertex`, and `_tracing_service` respectively. This change ensures consistency and improves code readability.

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* refactor: update BaseComponent to accept UUID for _user_id

Updated the `BaseComponent` class in `base_component.py` to accept a `UUID` type for the `_user_id` attribute. This change improves the type safety and ensures consistency with the usage of `_user_id` throughout the codebase.

* refactor: import nanoid with type annotation

The `nanoid` import in `component.py` has been updated to include a type annotation `# type: ignore`. This change ensures that the type checker ignores any errors related to the `nanoid` import.

* fix(custom_component.py): convert _user_id to string before passing to functions to ensure compatibility with function signatures

* feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components

* refactor: extract method to get method return type in CustomComponent

* refactor(utils.py): refactor code to use _user_id instead of user_id for consistency and clarity

perf(utils.py): optimize code by reusing cc_instance instead of calling get_component_instance multiple times

* refactor(utils.py, base.py): change parameter name 'add_name' to 'keep_name' for clarity and consistency in codebase

* [autofix.ci] apply automated fixes

* refactor: update schema.py to include Edge related typres

The `schema.py` file in the `src/backend/base/langflow/graph/edge` directory has been updated to include the `TargetHandle` and `SourceHandle` models. These models define the structure and attributes of the target and source handles used in the edge data. This change improves the clarity and consistency of the codebase.

* refactor: update BaseInputMixin to handle invalid field types gracefully

The `BaseInputMixin` class in `input_mixin.py` has been updated to handle invalid field types gracefully. Instead of raising an exception, it now returns `FieldTypes.OTHER` for any invalid field type. This change improves the robustness and reliability of the codebase.

* refactor: update file_types field alias in FileMixin

The `file_types` field in the `FileMixin` class of `input_mixin.py` has been updated to use the `alias` parameter instead of `serialization_alias`. This change ensures consistency and improves the clarity of the codebase.

* refactor(inputs): update field_type declarations in various input classes to use SerializableFieldTypes enum for better type safety and clarity

* refactor(inputs): convert dict to Message object in _validate_value method

* refactor(inputs): convert dict to Message object in _validate_value method

* refactor(inputs): update model_config in BaseInputMixin to enable populating by name

The `model_config` attribute in the `BaseInputMixin` class of `input_mixin.py` has been updated to include the `populate_by_name=True` parameter. This change allows the model configuration to be populated by name, improving the flexibility and usability of the codebase.

* refactor: update _extract_return_type method in CustomComponent to accept Any type

The _extract_return_type method in CustomComponent has been updated to accept the Any type as the return_type parameter. This change improves the flexibility and compatibility of the method, allowing it to handle a wider range of return types.

* refactor(component): add get_input and get_output methods for easier access to input and output values

The `Component` class in `component.py` has been updated to include the `get_input` and `get_output` methods. These methods allow for easier retrieval of input and output values by name, improving the usability and readability of the codebase.

* refactor(vertex): add get_input and get_output methods for easier access to input and output values

* refactor(component): add set_output_value method for easier modification of output values

The `Component` class in `component.py` has been updated to include the `set_output_value` method. This method allows for easier modification of output values by name, improving the usability and flexibility of the codebase.

* feat: add run_until_complete and run_in_thread functions for handling asyncio tasks

The `async_helpers.py` file in the `src/backend/base/langflow/utils` directory has been added. This file includes the `run_until_complete` and `run_in_thread` functions, which provide a way to handle asyncio tasks in different scenarios. The `run_until_complete` function checks if an event loop is already running and either runs the coroutine in a separate event loop in a new thread or creates a new event loop and runs the coroutine. The `run_in_thread` function runs the coroutine in a separate thread and returns the result or raises an exception if one occurs. These functions improve the flexibility and usability of the codebase.

* refactor(component): add _edges attribute to Component class for managing edges

The `Component` class in `component.py` has been updated to include the `_edges` attribute. This attribute is a list of `EdgeData` objects and is used for managing edges in the component. This change improves the functionality and organization of the codebase.

* fix(component.py): fix conditional statement to check if self._vertex is not None before accessing its attributes

* refactor(component): add _get_fallback_input method for handling fallback input

The `Component` class in `component.py` has been updated to include the `_get_fallback_input` method. This method returns an `Input` object with the provided keyword arguments, which is used as a fallback input when needed. This change improves the flexibility and readability of the codebase.

* refactor(component): add TYPE_CHECKING import for Vertex in component.py

* refactor(component): add _map_parameters_on_frontend_node and _map_parameters_on_template and other methods

The `Component` class in `component.py` has been refactored to include the `_map_parameters_on_frontend_node` and `_map_parameters_on_template` methods. These methods are responsible for mapping the parameters of the component onto the frontend node and template, respectively. This change improves the organization and maintainability of the codebase.

* refactor(component): Add map_inputs and map_outputs methods for mapping inputs and outputs

The `Component` class in `component.py` has been updated to include the `map_inputs` and `map_outputs` methods. These methods allow for mapping the given inputs and outputs to the component, improving the functionality and organization of the codebase.

* refactor(component): Add Input, Output, and ComponentFrontendNode imports and run_until_complete function

This commit refactors the `component.py` file in the `src/backend/base/langflow/custom/custom_component` directory. It adds the `Input`, `Output`, and `ComponentFrontendNode` imports, as well as the `run_until_complete` function from the `async_helpers.py` file. These changes improve the functionality and organization of the codebase.

* refactor(component): Add map_inputs and map_outputs methods for mapping inputs and outputs

* refactor(component): Add _process_connection_or_parameter method for handling connections and parameters

The `Component` class in `component.py` has been updated to include the `_process_connection_or_parameter` method. This method is responsible for handling connections and parameters based on the provided key and value. It checks if the value is callable and connects it to the component, otherwise it sets the parameter or attribute. This change improves the functionality and organization of the codebase.

* refactor(frontend_node): Add set_field_value_in_template method for updating field values

The `FrontendNode` class in `base.py` has been updated to include the `set_field_value_in_template` method. This method allows for updating the value of a specific field in the template of the frontend node. It iterates through the fields and sets the value of the field with the provided name. This change improves the flexibility and functionality of the codebase.

* refactor(inputs): Add DefaultPromptField class for default prompt inputs

The `inputs.py` file in the `src/backend/base/langflow/inputs` directory has been refactored to include the `DefaultPromptField` class. This class represents a default prompt input with customizable properties such as name, display name, field type, advanced flag, multiline flag, input types, and value. This change improves the flexibility and functionality of the codebase.

* feat: Add Template.from_dict method for creating Template objects from dictionaries

This commit adds the `from_dict` class method to the `Template` class in `base.py`. This method allows for creating `Template` objects from dictionaries by converting the dictionary keys and values into the appropriate `Template` attributes. This change improves the flexibility and functionality of the codebase.

* refactor(frontend_node): Add from_dict method for creating FrontendNode objects from dictionaries

* refactor: update BaseComponent to use get_template_config method

Refactored the `BaseComponent` class in `base_component.py` to use the `get_template_config` method instead of duplicating the code. This change improves code readability and reduces redundancy.

* refactor(graph): Add EdgeData import and update add_nodes_and_edges method signature

The `Graph` class in `base.py` has been updated to include the `EdgeData` import and modify the signature of the `add_nodes_and_edges` method. The `add_nodes_and_edges` method now accepts a list of dictionaries representing `EdgeData` objects instead of a list of dictionaries with string keys and values. This change improves the type safety and clarity of the codebase.

* refactor(graph): Add first_layer property to Graph class

The `Graph` class in `base.py` has been updated to include the `first_layer` property. This property returns the first layer of the graph and throws a `ValueError` if the graph is not prepared. This change improves the functionality and organization of the codebase.

* refactor(graph): Update Graph class instantiation in base.py

The `Graph` class in `base.py` has been updated to use keyword arguments when instantiating the class. This change improves the readability and maintainability of the codebase.

* refactor(graph): Add prepare method to Graph class

The `Graph` class in `base.py` has been updated to include the `prepare` method. This method prepares the graph for execution by validating the stream, building edges, and sorting vertices. It also adds the first layer of vertices to the run manager and sets the run queue. This change improves the functionality and organization of the codebase.

* refactor(graph): Improve graph preparation in retrieve_vertices_order function

The `retrieve_vertices_order` function in `chat.py` has been updated to improve the graph preparation process. Instead of manually sorting vertices and adding them to the run manager, the function now calls the `prepare` method of the `Graph` class. This method validates the stream, builds edges, and sets the first layer of vertices. This change improves the functionality and organization of the codebase.

* feat: add BaseModel class with model_config attribute

A new `BaseModel` class has been added to the `base_model.py` file. This class extends the `PydanticBaseModel` and includes a `model_config` attribute of type `ConfigDict`. This change improves the codebase by providing a base model with a configuration dictionary for models.

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* refactor: update langflow.graph.edge.schema.py

Refactor the `langflow.graph.edge.schema.py` file to include the `TargetHandle` and `SourceHandle` models. This change improves the clarity and consistency of the codebase.

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* refactor: update build_custom_component_template to use add_name instead of keep_name

Refactor the `build_custom_component_template` function in `utils.py` to use the `add_name` parameter instead of the deprecated `keep_name` parameter. This change ensures consistency with the updated method signature and improves code clarity.

* feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components (#3115)

* feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components

* refactor: extract method to get method return type in CustomComponent

* refactor: update _extract_return_type method in CustomComponent to accept Any type

The _extract_return_type method in CustomComponent has been updated to accept the Any type as the return_type parameter. This change improves the flexibility and compatibility of the method, allowing it to handle a wider range of return types.

* refactor: add _template_config property to BaseComponent

Add a new `_template_config` property to the `BaseComponent` class in `base_component.py`. This property is used to store the template configuration for the custom component. If the `_template_config` property is empty, it is populated by calling the `build_template_config` method. This change improves the efficiency of accessing the template configuration and ensures that it is only built when needed.

* refactor: add type checking for Output types in add_types method

Improve type checking in the `add_types` method of the `Output` class in `base.py`. Check if the `type_` already exists in the `types` list before adding it. This change ensures that duplicate types are not added to the list.

* update starter projects

* refactor: optimize imports in base.py

Optimize imports in the `base.py` file by removing unused imports and organizing the remaining imports. This change improves code readability and reduces unnecessary clutter.

* fix(base.py): fix condition to check if self.types is not None before checking if type_ is in self.types

* refactor: update build_custom_component_template to use add_name instead of keep_name

* refactor(graph): update ContractEdge to use EdgeData for raw_edge parameter, enhancing type consistency across edges

* refactor(graph): update add_edge method to use EdgeData type, improving type safety and consistency in graph edges

* chore(dependencies): bump mypy version from 1.10.0 to 1.11.0 for improved type checking capabilities

* refactor: update Edge class to use EdgeData type for raw_edge parameter

The Edge class in base.py has been updated to use the EdgeData type for the raw_edge parameter in the __init__ method. This change improves type safety and consistency in graph edges.

* refactor: update follow_imports to "skip" in mypy configuration

* fix: add type ignore comment for return data in SelfQueryRetriever.py to resolve mypy warning

* chore: update mypy configuration to include namespace_packages and ignore missing imports in pyproject.toml files

* fix: add type ignore comment for target_param in base.py to resolve mypy warning about split method usage

* fix: add type ignore comments for various classes to resolve mypy warnings in input_mixin, database models, and cache service files

* refactor: add first layer attribute to Graph class

The Graph class in base.py has been updated to include a new attribute called `_first_layer`. This attribute is a list of strings and is initialized as an empty list. This change enhances the functionality of the Graph class by providing a way to store and access the first layer of vertices in the graph.

* refactor: store first layer in Graph class with _first_layer attribute for improved access to vertices being run

* fix: add type ignore comments to database model classes to resolve mypy type checking warnings

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-08-02 19:51:47 +00:00
.devcontainer Update Python base image to version 3.10 in devcontainer.json 2024-04-17 11:21:05 -03:00
.github build(deps):(deps): bump install-pinned/ruff from b52a71f70b28264686d57d1efef1ba845b9cec6c to 48a5818c5f7ce30e2822b67fb9c26d3e25d31fab (#3142) 2024-08-02 08:18:39 +00:00
.vscode feat: add opentelemetry utility functions and unit tests (#2570) 2024-07-10 15:01:38 -04:00
deploy fix: fix docker compose and add instructions (#2654) 2024-07-12 09:27:13 -07:00
docker fix: frontend image should forward /health_check to backend (#2887) 2024-07-23 15:08:43 +02:00
docker_example chore: simplify docker (#2526) 2024-07-04 11:14:52 -03:00
docs fix: deploy buttons images not appearing (#3092) 2024-07-31 04:26:22 -07:00
scripts chore: update makefile structure and functionality (#3000) 2024-07-30 06:43:13 -07:00
src refactor(graph): add prepare method in Graph (#3124) 2024-08-02 19:51:47 +00:00
.env.example fixing ThreadingInMemoryCache usage (#2604) 2024-07-10 04:52:37 -07:00
.eslintrc.json 🔧 (.pre-commit-config.yaml): Add eslint@9.1.1 as a dependency and enable autofix for pretty-format-json hook 2024-05-02 19:27:40 -03:00
.gitattributes refactor: Update .gitattributes to remove working-tree-encoding for .mdx and .json files 2024-06-10 14:30:27 -03:00
.gitignore fixing ThreadingInMemoryCache usage (#2604) 2024-07-10 04:52:37 -07:00
.pre-commit-config.yaml Update linting workflows for frontend and Python code (#2171) 2024-06-14 06:27:48 -07:00
CODE_OF_CONDUCT.md run codespell 2024-06-04 09:26:13 -03:00
CONTRIBUTING.md chore: improve contributors guidelines (#2784) 2024-07-18 12:31:58 -07:00
eslint.config.js 🔧 (.pre-commit-config.yaml): Add eslint@9.1.1 as a dependency and enable autofix for pretty-format-json hook 2024-05-02 19:27:40 -03:00
LICENSE Update organization name and URLs in configuration files 2024-04-18 11:58:19 -03:00
Makefile feat(Makefile): add build steps for frontend and langflow components when 'main' target is specified 2024-07-30 16:25:39 -03:00
poetry.lock refactor(graph): add prepare method in Graph (#3124) 2024-08-02 19:51:47 +00:00
pyproject.toml refactor(graph): add prepare method in Graph (#3124) 2024-08-02 19:51:47 +00:00
README.ja.md docs: add Korean README (#2883) 2024-07-24 23:27:39 +00:00
README.KR.md docs: update korean readme (#2970) 2024-07-26 05:56:15 -03:00
README.md docs(readme): fix toc (#3152) 2024-08-01 19:56:54 +00:00
README.PT.md docs: add Korean README (#2883) 2024-07-24 23:27:39 +00:00
README.zh_CN.md docs: add Korean README (#2883) 2024-07-24 23:27:39 +00:00
render.yaml fix: update render.yaml to being compatible with langflow 1.0 (#3071) 2024-07-30 15:22:03 +02:00

Langflow 1.0 is OUT! 🎉

Read all about it here!

Langflow

A visual framework for building multi-agent and RAG applications

Open-source, Python-powered, fully customizable, LLM and vector store agnostic

Docs - Join our Discord - Follow us on X - Live demo

README in English README in Portuguese README in Simplified Chinese README in Japanese README in KOREAN

Your GIF

📝 Content

📦 Get Started

You can install Langflow with pip:

# Make sure you have >=Python 3.10 installed on your system.
python -m pip install langflow -U

Then, run Langflow with:

python -m langflow run

Running Langflow from a Cloned Repository

If you prefer to run Langflow from a cloned repository rather than installing it via pip, follow these steps:

  1. Clone the Repository

First, clone the Langflow repository from GitHub:

git clone https://github.com/langflow-ai/langflow.git

Navigate into the cloned directory:

cd langflow
  1. Build and Install Dependencies

To build and install Langflows frontend and backend, use the following commands:

make install_frontend && make build_frontend && make install_backend
  1. Run Langflow

Once the installation is complete, you can run Langflow with:

poetry run python -m langflow run

🎨 Create Flows

Creating flows with Langflow is easy. Simply drag components from the sidebar onto the workspace and connect them to start building your application.

Explore by editing prompt parameters, grouping components into a single high-level component, and building your own Custom Components.

Once youre done, you can export your flow as a JSON file.

Load the flow with:

from langflow.load import run_flow_from_json

results = run_flow_from_json("path/to/flow.json", input_value="Hello, World!")

Deploy

DataStax Langflow

DataStax Langflow is a hosted version of Langflow integrated with AstraDB. Be up and running in minutes with no installation or setup required. Sign up for free.

Deploy Langflow on Hugging Face Spaces

You can also preview Langflow in HuggingFace Spaces. Clone the space using this link to create your own Langflow workspace in minutes.

Deploy Langflow on Google Cloud Platform

Follow our step-by-step guide to deploy Langflow on Google Cloud Platform (GCP) using Google Cloud Shell. The guide is available in the Langflow in Google Cloud Platform document.

Alternatively, click the "Open in Cloud Shell" button below to launch Google Cloud Shell, clone the Langflow repository, and start an interactive tutorial that will guide you through the process of setting up the necessary resources and deploying Langflow on your GCP project.

Open in Cloud Shell

Deploy on Railway

Use this template to deploy Langflow 1.0 on Railway:

Deploy on Railway

Deploy on Render

Deploy to Render

Deploy on Kubernetes

Follow our step-by-step guide to deploy Langflow on Kubernetes.

🖥️ Command Line Interface (CLI)

Langflow provides a command-line interface (CLI) for easy management and configuration.

Usage

You can run the Langflow using the following command:

langflow run [OPTIONS]

Each option is detailed below:

  • --help: Displays all available options.
  • --host: Defines the host to bind the server to. Can be set using the LANGFLOW_HOST environment variable. The default is 127.0.0.1.
  • --workers: Sets the number of worker processes. Can be set using the LANGFLOW_WORKERS environment variable. The default is 1.
  • --timeout: Sets the worker timeout in seconds. The default is 60.
  • --port: Sets the port to listen on. Can be set using the LANGFLOW_PORT environment variable. The default is 7860.
  • --env-file: Specifies the path to the .env file containing environment variables. The default is .env.
  • --log-level: Defines the logging level. Can be set using the LANGFLOW_LOG_LEVEL environment variable. The default is critical.
  • --components-path: Specifies the path to the directory containing custom components. Can be set using the LANGFLOW_COMPONENTS_PATH environment variable. The default is langflow/components.
  • --log-file: Specifies the path to the log file. Can be set using the LANGFLOW_LOG_FILE environment variable. The default is logs/langflow.log.
  • --cache: Selects the type of cache to use. Options are InMemoryCache and SQLiteCache. Can be set using the LANGFLOW_LANGCHAIN_CACHE environment variable. The default is SQLiteCache.
  • --dev/--no-dev: Toggles the development mode. The default is no-dev.
  • --path: Specifies the path to the frontend directory containing build files. This option is for development purposes only. Can be set using the LANGFLOW_FRONTEND_PATH environment variable.
  • --open-browser/--no-open-browser: Toggles the option to open the browser after starting the server. Can be set using the LANGFLOW_OPEN_BROWSER environment variable. The default is open-browser.
  • --remove-api-keys/--no-remove-api-keys: Toggles the option to remove API keys from the projects saved in the database. Can be set using the LANGFLOW_REMOVE_API_KEYS environment variable. The default is no-remove-api-keys.
  • --install-completion [bash|zsh|fish|powershell|pwsh]: Installs completion for the specified shell.
  • --show-completion [bash|zsh|fish|powershell|pwsh]: Shows completion for the specified shell, allowing you to copy it or customize the installation.
  • --backend-only: This parameter, with a default value of False, allows running only the backend server without the frontend. It can also be set using the LANGFLOW_BACKEND_ONLY environment variable.
  • --store: This parameter, with a default value of True, enables the store features, use --no-store to deactivate it. It can be configured using the LANGFLOW_STORE environment variable.

These parameters are important for users who need to customize the behavior of Langflow, especially in development or specialized deployment scenarios.

Environment Variables

You can configure many of the CLI options using environment variables. These can be exported in your operating system or added to a .env file and loaded using the --env-file option.

A sample .env file named .env.example is included with the project. Copy this file to a new file named .env and replace the example values with your actual settings. If you're setting values in both your OS and the .env file, the .env settings will take precedence.

👋 Contribute

We welcome contributions from developers of all levels to our open-source project on GitHub. If you'd like to contribute, please check our contributing guidelines and help make Langflow more accessible.


Star History Chart

🌟 Contributors

langflow contributors

📄 License

Langflow is released under the MIT License. See the LICENSE file for details.