diff --git a/.gitattributes b/.gitattributes index 4b878819c..379b21be8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -32,3 +32,4 @@ Dockerfile text *.mp4 binary *.svg binary *.csv binary + diff --git a/.vscode/launch.json b/.vscode/launch.json index 40a60f354..82e39fcc9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,7 @@ "configurations": [ { "name": "Debug Backend", - "type": "python", + "type": "debugpy", "request": "launch", "module": "uvicorn", "args": [ @@ -26,7 +26,7 @@ }, { "name": "Debug CLI", - "type": "python", + "type": "debugpy", "request": "launch", "module": "langflow", "args": [ @@ -43,7 +43,7 @@ }, { "name": "Python: Remote Attach", - "type": "python", + "type": "debugpy", "request": "attach", "justMyCode": true, "connect": { @@ -65,7 +65,7 @@ }, { "name": "Python: Debug Tests", - "type": "python", + "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], diff --git a/Makefile b/Makefile index abf3e67ec..4592caf9b 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,8 @@ coverage: poetry run pytest --cov \ --cov-config=.coveragerc \ --cov-report xml \ - --cov-report term-missing:skip-covered + --cov-report term-missing:skip-covered \ + --cov-report lcov:coverage/lcov-pytest.info # allow passing arguments to pytest tests: diff --git a/docs/docs/administration/chat-widget.mdx b/docs/docs/administration/chat-widget.mdx index e73804673..0a6669cdd 100644 --- a/docs/docs/administration/chat-widget.mdx +++ b/docs/docs/administration/chat-widget.mdx @@ -181,9 +181,8 @@ Use the widget API to customize your Chat Widget: format {"key":"value"}. - | Prop | Type | Required | Description | -|-----------------------|---------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| --------------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | bot_message_style | JSON | No | Applies custom formatting to bot messages. | | chat_input_field | String | Yes | Defines the type of the input field for chat messages. | | chat_inputs | JSON | Yes | Determines the chat input elements and their respective values. | @@ -207,4 +206,3 @@ Use the widget API to customize your Chat Widget: | user_message_style | JSON | No | Determines the formatting for user messages in the chat window. | | width | Number | No | Sets the width of the chat window in pixels. | | window_title | String | No | Sets the title displayed in the chat window's header or title bar. | - diff --git a/docs/docs/administration/cli.mdx b/docs/docs/administration/cli.mdx index 634b944a5..9be0a3453 100644 --- a/docs/docs/administration/cli.mdx +++ b/docs/docs/administration/cli.mdx @@ -4,12 +4,12 @@ Langflow's Command Line Interface (CLI) is a powerful tool that allows you to in The available commands are below. Navigate to their individual sections of this page to see the parameters. -* [langflow](#overview) -* [langflow api-key](#langflow-api-key) -* [langflow copy-db](#langflow-copy-db) -* [langflow migration](#langflow-migration) -* [langflow run](#langflow-run) -* [langflow superuser](#langflow-superuser) +- [langflow](#overview) +- [langflow api-key](#langflow-api-key) +- [langflow copy-db](#langflow-copy-db) +- [langflow migration](#langflow-migration) +- [langflow run](#langflow-run) +- [langflow superuser](#langflow-superuser) ## Overview @@ -23,21 +23,21 @@ langflow --help python -m langflow ``` -| Command | Description | -| ------- | ----------- | -| `api-key` | Creates an API key for the default superuser if AUTO_LOGIN is enabled. | -| `copy-db` | Copy the database files to the current directory (`which langflow`). | -| `migration` | Run or test migrations. | -| `run` | Run the Langflow. | -| `superuser` | Create a superuser. | +| Command | Description | +| ----------- | ---------------------------------------------------------------------- | +| `api-key` | Creates an API key for the default superuser if AUTO_LOGIN is enabled. | +| `copy-db` | Copy the database files to the current directory (`which langflow`). | +| `migration` | Run or test migrations. | +| `run` | Run the Langflow. | +| `superuser` | Create a superuser. | ### Options -| Option | Description | -| ------ | ----------- | -| `--install-completion` | Install completion for the current shell. | -| `--show-completion` | Show completion for the current shell, to copy it or customize the installation. | -| `--help` | Show this message and exit. | +| Option | Description | +| ---------------------- | -------------------------------------------------------------------------------- | +| `--install-completion` | Install completion for the current shell. | +| `--show-completion` | Show completion for the current shell, to copy it or customize the installation. | +| `--help` | Show this message and exit. | ## langflow api-key @@ -61,10 +61,10 @@ python -m langflow api-key ### Options -| Option | Type | Description | -|------------------|------|-------------------------------------------------------------| -| --log-level | TEXT | Logging level. [env var: LANGFLOW_LOG_LEVEL] [default: error] | -| --help | | Show this message and exit. | +| Option | Type | Description | +| ----------- | ---- | ------------------------------------------------------------- | +| --log-level | TEXT | Logging level. [env var: LANGFLOW_LOG_LEVEL] [default: error] | +| --help | | Show this message and exit. | ## langflow copy-db @@ -87,12 +87,12 @@ python -m langflow migration ``` ### Options -| Option | Description | -|-----------------|-------------------------------------------------------------| -| `--test, --no-test` | Run migrations in test mode. [default: test] | -| `--fix, --no-fix` | Fix migrations. This is a destructive operation, and should only be used if you know what you are doing. [default: no-fix] | -| `--help` | Show this message and exit. | +| Option | Description | +| ------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| `--test, --no-test` | Run migrations in test mode. [default: test] | +| `--fix, --no-fix` | Fix migrations. This is a destructive operation, and should only be used if you know what you are doing. [default: no-fix] | +| `--help` | Show this message and exit. | ## langflow run @@ -106,26 +106,26 @@ python -m langflow run ### Options -| Option | Description | -|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `--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` | Select 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. For more, see [Backend-only](../deployment/backend-only.md).| -| `--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. | +| Option | Description | +| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--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` | Select 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. For more, see [Backend-only](../deployment/backend-only.md). | +| `--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. | #### CLI environment variables @@ -145,10 +145,9 @@ python -m langflow superuser ### Options -| Option | Type | Description | -|----------------|-------|-------------------------------------------------------------| -| `--username` | TEXT | Username for the superuser. [default: None] [required] | -| `--password` | TEXT | Password for the superuser. [default: None] [required] | -| `--log-level` | TEXT | Logging level. [env var: LANGFLOW_LOG_LEVEL] [default: error] | -| `--help` | | Show this message and exit. | - +| Option | Type | Description | +| ------------- | ---- | ------------------------------------------------------------- | +| `--username` | TEXT | Username for the superuser. [default: None] [required] | +| `--password` | TEXT | Password for the superuser. [default: None] [required] | +| `--log-level` | TEXT | Logging level. [env var: LANGFLOW_LOG_LEVEL] [default: error] | +| `--help` | | Show this message and exit. | diff --git a/docs/docs/administration/login.mdx b/docs/docs/administration/login.mdx index 20386aebb..9f3c12cf9 100644 --- a/docs/docs/administration/login.mdx +++ b/docs/docs/administration/login.mdx @@ -86,7 +86,7 @@ With _`LANGFLOW_AUTO_LOGIN`_ set to _`False`_, Langflow requires users to sign u light: useBaseUrl("img/sign-up.png"), dark: useBaseUrl("img/sign-up.png"), }} - style={{ width: "40%", margin: "20px auto" }} + style={{ width: "40%", margin: "20px auto" }} /> ## Profile settings diff --git a/docs/docs/administration/playground.mdx b/docs/docs/administration/playground.mdx index 7bc0c8db7..b0e9d8bad 100644 --- a/docs/docs/administration/playground.mdx +++ b/docs/docs/administration/playground.mdx @@ -40,14 +40,13 @@ The Playground's appearance changes depending on what components are in your can Adding or removing any of the below components modifies your Playground so you can monitor the inputs and outputs. -* Chat Input -* Text Input -* Chat Output -* Text Output -* Records Output -* Inspect Memory +- Chat Input +- Text Input +- Chat Output +- Text Output +- Records Output +- Inspect Memory You can also select **Options** > **Logs** to see your flow's logs. For more information, see [Inputs and Outputs](../components/inputs-and-outputs.mdx). - diff --git a/docs/docs/components/agents.mdx b/docs/docs/components/agents.mdx index 51ada9f2f..00d597804 100644 --- a/docs/docs/components/agents.mdx +++ b/docs/docs/components/agents.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Agents @@ -81,4 +81,4 @@ The `ZeroShotAgent` uses the ReAct framework to decide which tool to use based o **Parameters**: - **Allowed Tools:** The tools accessible to the agent. -- **LLM Chain:** The LLM Chain used by the agent. \ No newline at end of file +- **LLM Chain:** The LLM Chain used by the agent. diff --git a/docs/docs/components/data.mdx b/docs/docs/components/data.mdx index ca81bd225..d7f525d7d 100644 --- a/docs/docs/components/data.mdx +++ b/docs/docs/components/data.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Data diff --git a/docs/docs/components/embeddings.mdx b/docs/docs/components/embeddings.mdx index 4978ff354..200e0ccf3 100644 --- a/docs/docs/components/embeddings.mdx +++ b/docs/docs/components/embeddings.mdx @@ -4,113 +4,113 @@ Used to load embedding models from [Amazon Bedrock](https://aws.amazon.com/bedrock/). -| **Parameter** | **Type** | **Description** | **Default** | -|-----------------------------|-------------------|------------------------------------------------------------------------------------------------------------------------------------|-------------| -| `credentials_profile_name` | `str` | Name of the AWS credentials profile in ~/.aws/credentials or ~/.aws/config, which has access keys or role information. | | -| `model_id` | `str` | ID of the model to call, e.g., `amazon.titan-embed-text-v1`. This is equivalent to the `modelId` property in the `list-foundation-models` API. | | -| `endpoint_url` | `str` | URL to set a specific service endpoint other than the default AWS endpoint. | | -| `region_name` | `str` | AWS region to use, e.g., `us-west-2`. Falls back to `AWS_DEFAULT_REGION` environment variable or region specified in ~/.aws/config if not provided. | | +| **Parameter** | **Type** | **Description** | **Default** | +| -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | +| `credentials_profile_name` | `str` | Name of the AWS credentials profile in ~/.aws/credentials or ~/.aws/config, which has access keys or role information. | | +| `model_id` | `str` | ID of the model to call, e.g., `amazon.titan-embed-text-v1`. This is equivalent to the `modelId` property in the `list-foundation-models` API. | | +| `endpoint_url` | `str` | URL to set a specific service endpoint other than the default AWS endpoint. | | +| `region_name` | `str` | AWS region to use, e.g., `us-west-2`. Falls back to `AWS_DEFAULT_REGION` environment variable or region specified in ~/.aws/config if not provided. | | ## Cohere Embeddings Used to load embedding models from [Cohere](https://cohere.com/). -| **Parameter** | **Type** | **Description** | **Default** | -|---------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------------| -| `cohere_api_key` | `str` | API key required to authenticate with the Cohere service. | | -| `model` | `str` | Language model used for embedding text documents and performing queries. | `embed-english-v2.0` | -| `truncate` | `bool` | Whether to truncate the input text to fit within the model's constraints. | `False` | +| **Parameter** | **Type** | **Description** | **Default** | +| ---------------- | -------- | ------------------------------------------------------------------------- | -------------------- | +| `cohere_api_key` | `str` | API key required to authenticate with the Cohere service. | | +| `model` | `str` | Language model used for embedding text documents and performing queries. | `embed-english-v2.0` | +| `truncate` | `bool` | Whether to truncate the input text to fit within the model's constraints. | `False` | ## Azure OpenAI Embeddings Generate embeddings using Azure OpenAI models. -| **Parameter** | **Type** | **Description** | **Default** | -|---------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------------| -| `Azure Endpoint` | `str` | Your Azure endpoint, including the resource. Example: `https://example-resource.azure.openai.com/` | | -| `Deployment Name` | `str` | The name of the deployment. | | -| `API Version` | `str` | The API version to use, options include various dates. | | -| `API Key` | `str` | The API key to access the Azure OpenAI service. | | +| **Parameter** | **Type** | **Description** | **Default** | +| ----------------- | -------- | -------------------------------------------------------------------------------------------------- | ----------- | +| `Azure Endpoint` | `str` | Your Azure endpoint, including the resource. Example: `https://example-resource.azure.openai.com/` | | +| `Deployment Name` | `str` | The name of the deployment. | | +| `API Version` | `str` | The API version to use, options include various dates. | | +| `API Key` | `str` | The API key to access the Azure OpenAI service. | | ## Hugging Face API Embeddings Generate embeddings using Hugging Face Inference API models. -| **Parameter** | **Type** | **Description** | **Default** | -|---------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------------| -| `API Key` | `str` | API key for accessing the Hugging Face Inference API. | | -| `API URL` | `str` | URL of the Hugging Face Inference API. | `http://localhost:8080` | -| `Model Name` | `str` | Name of the model to use for embeddings. | `BAAI/bge-large-en-v1.5` | -| `Cache Folder` | `str` | Folder path to cache Hugging Face models. | | -| `Encode Kwargs` | `dict` | Additional arguments for the encoding process. | | -| `Model Kwargs` | `dict` | Additional arguments for the model. | | -| `Multi Process` | `bool` | Whether to use multiple processes. | `False` | +| **Parameter** | **Type** | **Description** | **Default** | +| --------------- | -------- | ----------------------------------------------------- | ------------------------ | +| `API Key` | `str` | API key for accessing the Hugging Face Inference API. | | +| `API URL` | `str` | URL of the Hugging Face Inference API. | `http://localhost:8080` | +| `Model Name` | `str` | Name of the model to use for embeddings. | `BAAI/bge-large-en-v1.5` | +| `Cache Folder` | `str` | Folder path to cache Hugging Face models. | | +| `Encode Kwargs` | `dict` | Additional arguments for the encoding process. | | +| `Model Kwargs` | `dict` | Additional arguments for the model. | | +| `Multi Process` | `bool` | Whether to use multiple processes. | `False` | ## Hugging Face Embeddings Used to load embedding models from [HuggingFace](https://huggingface.co). -| **Parameter** | **Type** | **Description** | **Default** | -|---------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------------| -| `Cache Folder` | `str` | Folder path to cache HuggingFace models. | | -| `Encode Kwargs` | `dict` | Additional arguments for the encoding process. | | -| `Model Kwargs` | `dict` | Additional arguments for the model. | | -| `Model Name` | `str` | Name of the HuggingFace model to use. | `sentence-transformers/all-mpnet-base-v2` | -| `Multi Process` | `bool` | Whether to use multiple processes. | `False` | +| **Parameter** | **Type** | **Description** | **Default** | +| --------------- | -------- | ---------------------------------------------- | ----------------------------------------- | +| `Cache Folder` | `str` | Folder path to cache HuggingFace models. | | +| `Encode Kwargs` | `dict` | Additional arguments for the encoding process. | | +| `Model Kwargs` | `dict` | Additional arguments for the model. | | +| `Model Name` | `str` | Name of the HuggingFace model to use. | `sentence-transformers/all-mpnet-base-v2` | +| `Multi Process` | `bool` | Whether to use multiple processes. | `False` | ## OpenAI Embeddings Used to load embedding models from [OpenAI](https://openai.com/). -| **Parameter** | **Type** | **Description** | **Default** | -|-----------------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------| -| `OpenAI API Key` | `str` | The API key to use for accessing the OpenAI API. | | -| `Default Headers` | `Dict[str, str]` | Default headers for the HTTP requests. | | -| `Default Query` | `NestedDict` | Default query parameters for the HTTP requests. | | -| `Allowed Special` | `List[str]` | Special tokens allowed for processing. | `[]` | -| `Disallowed Special` | `List[str]` | Special tokens disallowed for processing. | `["all"]` | -| `Chunk Size` | `int` | Chunk size for processing. | `1000` | -| `Client` | `Any` | HTTP client for making requests. | | -| `Deployment` | `str` | Deployment name for the model. | `text-embedding-3-small` | -| `Embedding Context Length` | `int` | Length of embedding context. | `8191` | -| `Max Retries` | `int` | Maximum number of retries for failed requests. | `6` | -| `Model` | `str` | Name of the model to use. | `text-embedding-3-small` | -| `Model Kwargs` | `NestedDict` | Additional keyword arguments for the model. | | -| `OpenAI API Base` | `str` | Base URL of the OpenAI API. | | -| `OpenAI API Type` | `str` | Type of the OpenAI API. | | -| `OpenAI API Version` | `str` | Version of the OpenAI API. | | -| `OpenAI Organization` | `str` | Organization associated with the API key. | | -| `OpenAI Proxy` | `str` | Proxy server for the requests. | | -| `Request Timeout` | `float` | Timeout for the HTTP requests. | | -| `Show Progress Bar` | `bool` | Whether to show a progress bar for processing. | `False` | -| `Skip Empty` | `bool` | Whether to skip empty inputs. | `False` | -| `TikToken Enable` | `bool` | Whether to enable TikToken. | `True` | -| `TikToken Model Name` | `str` | Name of the TikToken model. | | +| **Parameter** | **Type** | **Description** | **Default** | +| -------------------------- | ---------------- | ------------------------------------------------ | ------------------------ | +| `OpenAI API Key` | `str` | The API key to use for accessing the OpenAI API. | | +| `Default Headers` | `Dict[str, str]` | Default headers for the HTTP requests. | | +| `Default Query` | `NestedDict` | Default query parameters for the HTTP requests. | | +| `Allowed Special` | `List[str]` | Special tokens allowed for processing. | `[]` | +| `Disallowed Special` | `List[str]` | Special tokens disallowed for processing. | `["all"]` | +| `Chunk Size` | `int` | Chunk size for processing. | `1000` | +| `Client` | `Any` | HTTP client for making requests. | | +| `Deployment` | `str` | Deployment name for the model. | `text-embedding-3-small` | +| `Embedding Context Length` | `int` | Length of embedding context. | `8191` | +| `Max Retries` | `int` | Maximum number of retries for failed requests. | `6` | +| `Model` | `str` | Name of the model to use. | `text-embedding-3-small` | +| `Model Kwargs` | `NestedDict` | Additional keyword arguments for the model. | | +| `OpenAI API Base` | `str` | Base URL of the OpenAI API. | | +| `OpenAI API Type` | `str` | Type of the OpenAI API. | | +| `OpenAI API Version` | `str` | Version of the OpenAI API. | | +| `OpenAI Organization` | `str` | Organization associated with the API key. | | +| `OpenAI Proxy` | `str` | Proxy server for the requests. | | +| `Request Timeout` | `float` | Timeout for the HTTP requests. | | +| `Show Progress Bar` | `bool` | Whether to show a progress bar for processing. | `False` | +| `Skip Empty` | `bool` | Whether to skip empty inputs. | `False` | +| `TikToken Enable` | `bool` | Whether to enable TikToken. | `True` | +| `TikToken Model Name` | `str` | Name of the TikToken model. | | ## Ollama Embeddings Generate embeddings using Ollama models. -| **Parameter** | **Type** | **Description** | **Default** | -|---------------------|-------------------|--------------------------------------------------------------------------------------------------------------------|---------------------------| -| `Ollama Model` | `str` | Name of the Ollama model to use. | `llama2` | -| `Ollama Base URL` | `str` | Base URL of the Ollama API. | `http://localhost:11434` | -| `Model Temperature` | `float` | Temperature parameter for the model. Adjusts the randomness in the generated embeddings. | | +| **Parameter** | **Type** | **Description** | **Default** | +| ------------------- | -------- | ---------------------------------------------------------------------------------------- | ------------------------ | +| `Ollama Model` | `str` | Name of the Ollama model to use. | `llama2` | +| `Ollama Base URL` | `str` | Base URL of the Ollama API. | `http://localhost:11434` | +| `Model Temperature` | `float` | Temperature parameter for the model. Adjusts the randomness in the generated embeddings. | | ## VertexAI Embeddings Wrapper around [Google Vertex AI](https://cloud.google.com/vertex-ai) [Embeddings API](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings). -| **Parameter** | **Type** | **Description** | **Default** | -|-----------------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------| -| `credentials` | `Credentials` | The default custom credentials to use. | | -| `location` | `str` | The default location to use when making API calls. | `us-central1`| -| `max_output_tokens` | `int` | Token limit determines the maximum amount of text output from one prompt. | `128` | -| `model_name` | `str` | The name of the Vertex AI large language model. | `text-bison`| -| `project` | `str` | The default GCP project to use when making Vertex API calls. | | -| `request_parallelism` | `int` | The amount of parallelism allowed for requests issued to VertexAI models. | `5` | -| `temperature` | `float` | Tunes the degree of randomness in text generations. Should be a non-negative value. | `0` | -| `top_k` | `int` | How the model selects tokens for output, the next token is selected from the top `k` tokens. | `40` | -| `top_p` | `float` | Tokens are selected from the most probable to least until the sum of their probabilities exceeds the top `p` value. | `0.95` | -| `tuned_model_name` | `str` | The name of a tuned model. If provided, `model_name` is ignored. | | -| `verbose` | `bool` | This parameter controls the level of detail in the output. When set to `True`, it prints internal states of the chain to help debug. | `False` | +| **Parameter** | **Type** | **Description** | **Default** | +| --------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------- | +| `credentials` | `Credentials` | The default custom credentials to use. | | +| `location` | `str` | The default location to use when making API calls. | `us-central1` | +| `max_output_tokens` | `int` | Token limit determines the maximum amount of text output from one prompt. | `128` | +| `model_name` | `str` | The name of the Vertex AI large language model. | `text-bison` | +| `project` | `str` | The default GCP project to use when making Vertex API calls. | | +| `request_parallelism` | `int` | The amount of parallelism allowed for requests issued to VertexAI models. | `5` | +| `temperature` | `float` | Tunes the degree of randomness in text generations. Should be a non-negative value. | `0` | +| `top_k` | `int` | How the model selects tokens for output, the next token is selected from the top `k` tokens. | `40` | +| `top_p` | `float` | Tokens are selected from the most probable to least until the sum of their probabilities exceeds the top `p` value. | `0.95` | +| `tuned_model_name` | `str` | The name of a tuned model. If provided, `model_name` is ignored. | | +| `verbose` | `bool` | This parameter controls the level of detail in the output. When set to `True`, it prints internal states of the chain to help debug. | `False` | diff --git a/docs/docs/components/experimental.mdx b/docs/docs/components/experimental.mdx index 5902b849e..036fa334c 100644 --- a/docs/docs/components/experimental.mdx +++ b/docs/docs/components/experimental.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Experimental @@ -31,10 +31,12 @@ This component extracts specified keys from a record. **Parameters** - **Record:** + - **Display Name:** Record - **Info:** The record from which to extract keys. - **Keys:** + - **Display Name:** Keys - **Info:** The keys to be extracted. @@ -56,6 +58,7 @@ This component turns a function running a flow into a Tool. **Parameters** - **Flow Name:** + - **Display Name:** Flow Name - **Info:** Select the flow to run. - **Options:** List of available flows. @@ -63,10 +66,12 @@ This component turns a function running a flow into a Tool. - **Refresh Button:** True - **Name:** + - **Display Name:** Name - **Description:** The tool's name. - **Description:** + - **Display Name:** Description - **Description:** Describes the tool. @@ -129,10 +134,12 @@ This component generates a notification. **Parameters** - **Name:** + - **Display Name:** Name - **Info:** The notification's name. - **Record:** + - **Display Name:** Record - **Info:** Optionally, a record to store in the notification. @@ -153,10 +160,12 @@ This component runs a specified flow. **Parameters** - **Input Value:** + - **Display Name:** Input Value - **Multiline:** True - **Flow Name:** + - **Display Name:** Flow Name - **Info:** Select the flow to run. - **Options:** List of available flows. @@ -179,14 +188,17 @@ This component executes a specified runnable. **Parameters** - **Input Key:** + - **Display Name:** Input Key - **Info:** The input key. - **Inputs:** + - **Display Name:** Inputs - **Info:** Inputs for the runnable. - **Runnable:** + - **Display Name:** Runnable - **Info:** The runnable to execute. @@ -207,14 +219,17 @@ This component executes an SQL query. **Parameters** - **Database URL:** + - **Display Name:** Database URL - **Info:** The database's URL. - **Include Columns:** + - **Display Name:** Include Columns - **Info:** Whether to include columns in the result. - **Passthrough:** + - **Display Name:** Passthrough - **Info:** Returns the query instead of raising an exception if an error occurs. @@ -235,10 +250,12 @@ This component dynamically generates a tool from a flow. **Parameters** - **Input Value:** + - **Display Name:** Input Value - **Multiline:** True - **Flow Name:** + - **Display Name:** Flow Name - **Info:** Select the flow to run. - **Options:** List of available flows. diff --git a/docs/docs/components/helpers.mdx b/docs/docs/components/helpers.mdx index ff95eab7e..f95c43b9d 100644 --- a/docs/docs/components/helpers.mdx +++ b/docs/docs/components/helpers.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Helpers @@ -49,9 +49,10 @@ Use this component as a template to create your custom component. - **Parameter:** Describe the purpose of this parameter. -

- Customize the build_config and build methods according to your requirements. -

+

+ Customize the build_config and build methods + according to your requirements. +

Learn more about creating custom components at [Custom Component](http://docs.langflow.org/components/custom). diff --git a/docs/docs/components/inputs-and-outputs.mdx b/docs/docs/components/inputs-and-outputs.mdx index bd804ea5f..484afc6b9 100644 --- a/docs/docs/components/inputs-and-outputs.mdx +++ b/docs/docs/components/inputs-and-outputs.mdx @@ -48,8 +48,8 @@ One significant capability of the Chat Input component is its ability to transfo diff --git a/docs/docs/components/memories.mdx b/docs/docs/components/memories.mdx index f4002844e..a133c6a6a 100644 --- a/docs/docs/components/memories.mdx +++ b/docs/docs/components/memories.mdx @@ -1,11 +1,13 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Memories -

- Thanks for your patience as we improve our documentation—it might have some rough edges. Share your feedback or report issues to help us enhance it! 🛠️📝 -

+

+ Thanks for your patience as we improve our documentation—it might have some + rough edges. Share your feedback or report issues to help us enhance it! + 🛠️📝 +

Memory is a concept in chat-based applications that allows the system to remember previous interactions. This capability helps maintain the context of the conversation and enables the system to understand new messages in light of past messages. @@ -24,9 +26,13 @@ This component retrieves stored messages using various filters such as sender ty - **number_of_messages**: Specifies the number of messages to retrieve. Defaults to `5`. Determines the number of recent messages from the chat history to fetch. -

- The component retrieves messages based on the provided criteria, including the specific file path for stored messages. If no specific criteria are provided, it returns the most recent messages up to the specified limit. This component can be used to review past interactions and analyze conversation flows. -

+

+ The component retrieves messages based on the provided criteria, including + the specific file path for stored messages. If no specific criteria are + provided, it returns the most recent messages up to the specified limit. + This component can be used to review past interactions and analyze + conversation flows. +

### ConversationBufferMemory @@ -84,7 +90,8 @@ The `ConversationKGMemory` utilizes a knowledge graph to enhance memory capabili - **memory_key**: Specifies the prompt variable name where the memory stores and retrieves chat messages. Defaults to `chat_history`. - **output_key**: Identifies the key under which the generated response - is stored, enabling retrieval using this key. +is stored, enabling retrieval using this key. + - **return_messages**: Controls whether the history is returned as a string or as a list of messages. Defaults to `False`. --- @@ -124,4 +131,4 @@ The `VectorRetrieverMemory` retrieves vectors based on queries, facilitating vec - **Retriever**: The tool used to fetch documents. - **input_key**: Identifies where input messages are stored in the memory object, facilitating their retrieval and manipulation. - **memory_key**: Specifies the prompt variable name where the memory stores and retrieves chat messages. Defaults to `chat_history`. -- **return_messages**: Controls whether the history is returned as a string or as a list of messages. Defaults to `False`. \ No newline at end of file +- **return_messages**: Controls whether the history is returned as a string or as a list of messages. Defaults to `False`. diff --git a/docs/docs/components/model_specs.mdx b/docs/docs/components/model_specs.mdx index ad45edf45..21ee1849b 100644 --- a/docs/docs/components/model_specs.mdx +++ b/docs/docs/components/model_specs.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Large Language Models (LLMs) @@ -31,7 +31,9 @@ This is a wrapper for Anthropic's large language model designed for chat-based i `CTransformers` provides access to Transformer models implemented in C/C++ using the [GGML](https://github.com/ggerganov/ggml) library. -Ensure the `ctransformers` Python package is installed. Discover more about installation, supported models, and usage [here](https://github.com/marella/ctransformers). + Ensure the `ctransformers` Python package is installed. Discover more about + installation, supported models, and usage + [here](https://github.com/marella/ctransformers). - **config:** This configuration is for the Transformer models. Check the default settings and possible configurations at [config](https://github.com/marella/ctransformers#config). @@ -122,7 +124,8 @@ This component integrates with [Google Vertex AI](https://cloud.google.com/verte - **credentials**: Custom - credentials used for API interactions. +credentials used for API interactions. + - **location**: The default location for API calls, defaulting to `us-central1`. - **max_output_tokens**: Limits the output tokens per prompt, defaulting to `128`. - **model_name**: The name of the Vertex AI model in use, defaulting to `text-bison`. @@ -134,4 +137,4 @@ This component integrates with [Google Vertex AI](https://cloud.google.com/verte - **tuned_model_name**: Specifies a tuned model name, which overrides the default model name if provided. - **verbose**: Controls the output verbosity to assist in debugging and understanding the operational details, defaulting to `False`. ---- \ No newline at end of file +--- diff --git a/docs/docs/components/retrievers.mdx b/docs/docs/components/retrievers.mdx index baf8d6813..792b9e20b 100644 --- a/docs/docs/components/retrievers.mdx +++ b/docs/docs/components/retrievers.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Retrievers diff --git a/docs/docs/components/toolkits.mdx b/docs/docs/components/toolkits.mdx index ea6758aee..3ba7ed7c7 100644 --- a/docs/docs/components/toolkits.mdx +++ b/docs/docs/components/toolkits.mdx @@ -1,9 +1,11 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Toolkits -

- We appreciate your understanding as we polish our documentation – it may contain some rough edges. Share your feedback or report issues to help us improve! 🛠️📝 -

-
\ No newline at end of file +

+ We appreciate your understanding as we polish our documentation - it may + contain some rough edges. Share your feedback or report issues to help us + improve! 🛠️📝 +

+ diff --git a/docs/docs/components/tools.mdx b/docs/docs/components/tools.mdx index 251d3b016..6460db860 100644 --- a/docs/docs/components/tools.mdx +++ b/docs/docs/components/tools.mdx @@ -1,4 +1,4 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Tools diff --git a/docs/docs/components/utilities.mdx b/docs/docs/components/utilities.mdx index 99af76810..44263f583 100644 --- a/docs/docs/components/utilities.mdx +++ b/docs/docs/components/utilities.mdx @@ -80,7 +80,11 @@ Generates a unique identifier (UUID) for each instance it is invoked, providing - Returns a unique identifier (UUID) as a string. This UUID is generated using Python's `uuid` module, ensuring that each identifier is unique and can be used as a reliable reference in your application. - The Unique ID Generator is crucial for scenarios requiring distinct identifiers, such as session management, transaction tracking, or any context where different instances or entities must be uniquely identified. The generated UUID is provided as a hexadecimal string, offering a high level of uniqueness and security for identification purposes. + The Unique ID Generator is crucial for scenarios requiring distinct + identifiers, such as session management, transaction tracking, or any context + where different instances or entities must be uniquely identified. The + generated UUID is provided as a hexadecimal string, offering a high level of + uniqueness and security for identification purposes. For additional information and examples, please consult the [Langflow Components Custom Documentation](http://docs.langflow.org/components/custom). diff --git a/docs/docs/deployment/backend-only.md b/docs/docs/deployment/backend-only.md index c82e55aa6..fb5efdfdb 100644 --- a/docs/docs/deployment/backend-only.md +++ b/docs/docs/deployment/backend-only.md @@ -1,24 +1,26 @@ # Backend-only + You can run Langflow in `--backend-only` mode to expose your Langflow app as an API, without running the frontend UI. Start langflow in backend-only mode with `python3 -m langflow run --backend-only`. -The terminal prints ` Welcome to ⛓ Langflow `, and a blank window opens at `http://127.0.0.1:7864/all`. +The terminal prints `Welcome to ⛓ Langflow`, and a blank window opens at `http://127.0.0.1:7864/all`. Langflow will now serve requests to its API without the frontend running. ## Prerequisites -* [Langflow installed](../getting-started/install-langflow.mdx) +- [Langflow installed](../getting-started/install-langflow.mdx) -* [OpenAI API key](https://platform.openai.com) +- [OpenAI API key](https://platform.openai.com) -* [A Langflow flow created](../starter-projects/basic-prompting.mdx) +- [A Langflow flow created](../starter-projects/basic-prompting.mdx) ## Download your flow's curl call 1. Click API. 2. Click **curl** > **Copy code** and save the code to your local machine. -It will look something like this: + It will look something like this: + ```curl curl -X POST \ "http://127.0.0.1:7864/api/v1/run/ef7e0554-69e5-4e3e-ab29-ee83bcd8d9ef?stream=false" \ @@ -33,19 +35,22 @@ curl -X POST \ "ChatInput-xXC4F": {} }}' ``` + Note the flow ID of `ef7e0554-69e5-4e3e-ab29-ee83bcd8d9ef`. You can find this ID in the UI as well to ensure you're querying the right flow. ## Start Langflow in backend-only mode 1. Stop Langflow with Ctrl+C. 2. Start langflow in backend-only mode with `python3 -m langflow run --backend-only`. -The terminal prints ` Welcome to ⛓ Langflow `, and a blank window opens at `http://127.0.0.1:7864/all`. -Langflow will now serve requests to its API. + The terminal prints `Welcome to ⛓ Langflow`, and a blank window opens at `http://127.0.0.1:7864/all`. + Langflow will now serve requests to its API. 3. Run the curl code you copied from the UI. -You should get a result like this: + You should get a result like this: + ```bash {"session_id":"ef7e0554-69e5-4e3e-ab29-ee83bcd8d9ef:bf81d898868ac87e1b4edbd96c131c5dee801ea2971122cc91352d144a45b880","outputs":[{"inputs":{"input_value":"hi, are you there?"},"outputs":[{"results":{"result":"Arrr, ahoy matey! Aye, I be here. What be ye needin', me hearty?"},"artifacts":{"message":"Arrr, ahoy matey! Aye, I be here. What be ye needin', me hearty?","sender":"Machine","sender_name":"AI"},"messages":[{"message":"Arrr, ahoy matey! Aye, I be here. What be ye needin', me hearty?","sender":"Machine","sender_name":"AI","component_id":"ChatOutput-ktwdw"}],"component_display_name":"Chat Output","component_id":"ChatOutput-ktwdw","used_frozen_result":false}]}]}% ``` + Again, note that the flow ID matches. Langflow is receiving your POST request, running the flow, and returning the result, all without running the frontend. Cool! @@ -55,7 +60,8 @@ Instead of using curl, you can download your flow as a Python API call instead. 1. Click API. 2. Click **Python API** > **Copy code** and save the code to your local machine. -The code will look something like this: + The code will look something like this: + ```python import requests from typing import Optional @@ -99,15 +105,19 @@ message = "message" print(run_flow(message=message, flow_id=FLOW_ID)) ``` + 3. Run your Python app: + ```python python3 app.py ``` The result is similar to the curl call: + ```bash {'session_id': 'ef7e0554-69e5-4e3e-ab29-ee83bcd8d9ef:bf81d898868ac87e1b4edbd96c131c5dee801ea2971122cc91352d144a45b880', 'outputs': [{'inputs': {'input_value': 'message'}, 'outputs': [{'results': {'result': "Arrr matey! What be yer message for this ol' pirate? Speak up or walk the plank!"}, 'artifacts': {'message': "Arrr matey! What be yer message for this ol' pirate? Speak up or walk the plank!", 'sender': 'Machine', 'sender_name': 'AI'}, 'messages': [{'message': "Arrr matey! What be yer message for this ol' pirate? Speak up or walk the plank!", 'sender': 'Machine', 'sender_name': 'AI', 'component_id': 'ChatOutput-ktwdw'}], 'component_display_name': 'Chat Output', 'component_id': 'ChatOutput-ktwdw', 'used_frozen_result': False}]}]} ``` + Your Python app POSTs to your Langflow server, and the server runs the flow and returns the result. -See [API](../administration/api.mdx) for more ways to interact with your headless Langflow server. \ No newline at end of file +See [API](../administration/api.mdx) for more ways to interact with your headless Langflow server. diff --git a/docs/docs/getting-started/canvas.mdx b/docs/docs/getting-started/canvas.mdx index 2f7d20cf3..d54ffeeb4 100644 --- a/docs/docs/getting-started/canvas.mdx +++ b/docs/docs/getting-started/canvas.mdx @@ -38,7 +38,6 @@ For example, the [Basic prompting](../starter-projects/basic-prompting.mdx) flow style={{ width: "100%", maxWidth: "800px", margin: "0 auto" }} /> - In this flow, the **OpenAI LLM component** receives input (left side) and produces output (right side) - in this case, receiving input from the **Chat Input** and **Prompt** components and producing output to the **Chat Output** component. ## Component diff --git a/docs/docs/getting-started/install-langflow.mdx b/docs/docs/getting-started/install-langflow.mdx index 09a4f46dc..643938beb 100644 --- a/docs/docs/getting-started/install-langflow.mdx +++ b/docs/docs/getting-started/install-langflow.mdx @@ -86,7 +86,7 @@ You'll be presented with the following screen: light: "img/duplicate-space.png", dark: "img/duplicate-space.png", }} - style={{ width: "80%", maxWidth: "800px", margin: "0 auto" }} + style={{ width: "80%", maxWidth: "800px", margin: "0 auto" }} /> Name your Space, define the visibility (Public or Private), and click on **Duplicate Space** to start the installation process. When installation is finished, you'll be redirected to the Space's main page to start using Langflow right away! diff --git a/docs/docs/migration/possible-installation-issues.mdx b/docs/docs/migration/possible-installation-issues.mdx index feeddab48..203996f39 100644 --- a/docs/docs/migration/possible-installation-issues.mdx +++ b/docs/docs/migration/possible-installation-issues.mdx @@ -32,8 +32,9 @@ There are two possible reasons for this error: Clear the cache by deleting the contents of the cache folder. This folder can be found at: - - **Linux or WSL2 on Windows**: `home//.cache/langflow/` - - **MacOS**: `/Users//Library/Caches/langflow/` + +- **Linux or WSL2 on Windows**: `home//.cache/langflow/` +- **MacOS**: `/Users//Library/Caches/langflow/` This error can occur during Langflow upgrades when the new version can't override `langflow-pre.db` in `.cache/langflow/`. Clearing the cache removes this file but will also erase your settings. diff --git a/docs/docs/starter-projects/document-qa.mdx b/docs/docs/starter-projects/document-qa.mdx index b48e8c35d..f3c4f0a0a 100644 --- a/docs/docs/starter-projects/document-qa.mdx +++ b/docs/docs/starter-projects/document-qa.mdx @@ -33,7 +33,7 @@ Build a question-and-answer chatbot with a document loaded from local memory. light: "img/document-qa.png", dark: "img/document-qa.png", }} - style={{ width: "100%", maxWidth: "800px", margin: "0 auto" }} + style={{ width: "100%", maxWidth: "800px", margin: "0 auto" }} /> This flow creates a basic chatbot with the **Chat Input**, **Prompt**, **OpenAI**, and **Chat Output** components. diff --git a/docs/docs/tutorials/rag-with-astradb.mdx b/docs/docs/tutorials/rag-with-astradb.mdx index d8dc38a50..54c63cfa1 100644 --- a/docs/docs/tutorials/rag-with-astradb.mdx +++ b/docs/docs/tutorials/rag-with-astradb.mdx @@ -13,7 +13,8 @@ In this guide, we will use Astra DB as a vector store to store and retrieve the This guide assumes that you have Langflow up and running. If you are new to - Langflow, you can check out the [Getting Started](../getting-started/install-langflow.mdx) guide. + Langflow, you can check out the [Getting + Started](../getting-started/install-langflow.mdx) guide. TLDR; diff --git a/docs/sidebars.js b/docs/sidebars.js index c409266c3..a0d9e2d7d 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -114,7 +114,8 @@ module.exports = { type: "category", label: "Deployment", collapsed: true, - items: ["deployment/docker", + items: [ + "deployment/docker", "deployment/backend-only", "deployment/gcp-deployment", ], diff --git a/poetry.lock b/poetry.lock index 61c0dac1b..9590d45ce 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1608,6 +1608,23 @@ files = [ [package.dependencies] packaging = "*" +[[package]] +name = "dictdiffer" +version = "0.9.0" +description = "Dictdiffer is a library that helps you to diff and patch dictionaries." +optional = false +python-versions = "*" +files = [ + {file = "dictdiffer-0.9.0-py2.py3-none-any.whl", hash = "sha256:442bfc693cfcadaf46674575d2eba1c53b42f5e404218ca2c2ff549f2df56595"}, + {file = "dictdiffer-0.9.0.tar.gz", hash = "sha256:17bacf5fbfe613ccf1b6d512bd766e6b21fb798822a133aa86098b8ac9997578"}, +] + +[package.extras] +all = ["Sphinx (>=3)", "check-manifest (>=0.42)", "mock (>=1.3.0)", "numpy (>=1.13.0)", "numpy (>=1.15.0)", "numpy (>=1.18.0)", "numpy (>=1.20.0)", "pytest (==5.4.3)", "pytest (>=6)", "pytest-cov (>=2.10.1)", "pytest-isort (>=1.2.0)", "pytest-pycodestyle (>=2)", "pytest-pycodestyle (>=2.2.0)", "pytest-pydocstyle (>=2)", "pytest-pydocstyle (>=2.2.0)", "sphinx (>=3)", "sphinx-rtd-theme (>=0.2)", "tox (>=3.7.0)"] +docs = ["Sphinx (>=3)", "sphinx-rtd-theme (>=0.2)"] +numpy = ["numpy (>=1.13.0)", "numpy (>=1.15.0)", "numpy (>=1.18.0)", "numpy (>=1.20.0)"] +tests = ["check-manifest (>=0.42)", "mock (>=1.3.0)", "pytest (==5.4.3)", "pytest (>=6)", "pytest-cov (>=2.10.1)", "pytest-isort (>=1.2.0)", "pytest-pycodestyle (>=2)", "pytest-pycodestyle (>=2.2.0)", "pytest-pydocstyle (>=2)", "pytest-pydocstyle (>=2.2.0)", "sphinx (>=3)", "tox (>=3.7.0)"] + [[package]] name = "dill" version = "0.3.7" @@ -10445,6 +10462,7 @@ test = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [extras] +cassio = ["cassio"] couchbase = ["couchbase"] deploy = ["celery", "flower", "redis"] local = ["ctransformers", "llama-cpp-python", "sentence-transformers"] @@ -10452,4 +10470,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "4e16ddf83311fa2c894623b76832a9dda98eec2b88975c087297364954dbdac6" +content-hash = "6cfa9f164710bf283b50a8e12e9d0c91c58f5d0176bbb277b5f5d3630ec8b2cb" diff --git a/pyproject.toml b/pyproject.toml index 091e0d47a..7408344f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ youtube-transcript-api = "^0.6.2" markdown = "^3.6" langchain-chroma = "^0.1.1" upstash-vector = "^0.4.0" -cassio = "^0.1.7" +cassio = { extras = ["cassio"], version = "^0.1.7", optional = true } unstructured = {extras = ["docx", "md", "pptx"], version = "^0.14.4"} @@ -117,10 +117,12 @@ pytest-asyncio = "^0.23.0" pytest-profiling = "^1.7.0" pre-commit = "^3.7.0" vulture = "^2.11" +dictdiffer = "^0.9.0" [tool.poetry.extras] deploy = ["celery", "redis", "flower"] couchbase = ["couchbase"] +cassio = ["cassio"] local = ["llama-cpp-python", "sentence-transformers", "ctransformers"] diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index cc38b474a..82bd32165 100644 --- a/src/backend/base/langflow/api/utils.py +++ b/src/backend/base/langflow/api/utils.py @@ -86,6 +86,10 @@ def update_frontend_node_with_template_values(frontend_node, raw_frontend_node): update_template_values(frontend_node["template"], raw_frontend_node["template"]) + old_code = raw_frontend_node["template"]["code"]["value"] + new_code = frontend_node["template"]["code"]["value"] + frontend_node["edited"] = old_code != new_code + return frontend_node @@ -204,16 +208,18 @@ def format_elapsed_time(elapsed_time: float) -> str: return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}" -async def build_and_cache_graph_from_db( - flow_id: str, - session: Session, - chat_service: "ChatService", -): +async def build_and_cache_graph_from_db(flow_id: str, session: Session, chat_service: "ChatService"): """Build and cache the graph.""" flow: Optional[Flow] = session.get(Flow, flow_id) if not flow or not flow.data: raise ValueError("Invalid flow ID") graph = Graph.from_payload(flow.data, flow_id) + for vertex_id in graph._has_session_id_vertices: + vertex = graph.get_vertex(vertex_id) + if vertex is None: + raise ValueError(f"Vertex {vertex_id} not found") + if not vertex._raw_params.get("session_id"): + vertex.update_raw_params({"session_id": flow_id}, overwrite=True) await chat_service.set_cache(flow_id, graph) return graph @@ -317,3 +323,4 @@ def parse_exception(exc): if hasattr(exc, "body"): return exc.body["message"] return str(exc) + return str(exc) diff --git a/src/backend/base/langflow/api/v1/chat.py b/src/backend/base/langflow/api/v1/chat.py index fbb763e8d..004517575 100644 --- a/src/backend/base/langflow/api/v1/chat.py +++ b/src/backend/base/langflow/api/v1/chat.py @@ -22,6 +22,7 @@ from langflow.api.v1.schemas import ( VertexBuildResponse, VerticesOrderResponse, ) +from langflow.schema.schema import Log from langflow.services.auth.utils import get_current_active_user from langflow.services.chat.service import ChatService from langflow.services.deps import get_chat_service, get_session, get_session_service @@ -123,6 +124,7 @@ async def build_vertex( vertex_id: str, background_tasks: BackgroundTasks, inputs: Annotated[Optional[InputValueRequest], Body(embed=True)] = None, + files: Optional[list[str]] = None, chat_service: "ChatService" = Depends(get_chat_service), current_user=Depends(get_current_active_user), ): @@ -159,6 +161,7 @@ async def build_vertex( else: graph = cache.get("result") vertex = graph.get_vertex(vertex_id) + try: lock = chat_service._cache_locks[flow_id_str] ( @@ -175,19 +178,25 @@ async def build_vertex( vertex_id=vertex_id, user_id=current_user.id, inputs_dict=inputs.model_dump() if inputs else {}, + files=files, ) + log_obj = Log(message=vertex.artifacts_raw, type=vertex.artifacts_type) result_data_response = ResultDataResponse(**result_dict.model_dump()) except Exception as exc: logger.exception(f"Error building vertex: {exc}") params = format_exception_message(exc) valid = False + log_obj = Log(message=params, type="error") result_data_response = ResultDataResponse(results={}) artifacts = {} # If there's an error building the vertex # we need to clear the cache await chat_service.clear_cache(flow_id_str) + result_data_response.message = artifacts + result_data_response.logs.append(log_obj) + # Log the vertex build if not vertex.will_stream: background_tasks.add_task( diff --git a/src/backend/base/langflow/api/v1/files.py b/src/backend/base/langflow/api/v1/files.py index bbe97f81a..a72ee7711 100644 --- a/src/backend/base/langflow/api/v1/files.py +++ b/src/backend/base/langflow/api/v1/files.py @@ -2,6 +2,7 @@ import hashlib from http import HTTPStatus from io import BytesIO from uuid import UUID +from pathlib import Path from fastapi import APIRouter, Depends, HTTPException, UploadFile from fastapi.responses import StreamingResponse @@ -99,6 +100,46 @@ async def download_image(file_name: str, flow_id: UUID, storage_service: Storage raise HTTPException(status_code=500, detail=str(e)) +@router.get("/profile_pictures/{folder_name}/{file_name}") +async def download_profile_picture( + folder_name: str, + file_name: str, + storage_service: StorageService = Depends(get_storage_service), +): + try: + extension = file_name.split(".")[-1] + config_dir = get_storage_service().settings_service.settings.config_dir + config_path = Path(config_dir) + folder_path = config_path / "profile_pictures" / folder_name + content_type = build_content_type_from_extension(extension) + file_content = await storage_service.get_file(flow_id=folder_path, file_name=file_name) + return StreamingResponse(BytesIO(file_content), media_type=content_type) + + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + +@router.get("/profile_pictures/list") +async def list_profile_pictures(storage_service: StorageService = Depends(get_storage_service)): + try: + config_dir = get_storage_service().settings_service.settings.config_dir + config_path = Path(config_dir) + + people_path = config_path / "profile_pictures/People" + space_path = config_path / "profile_pictures/Space" + + people = await storage_service.list_files(flow_id=people_path) + space = await storage_service.list_files(flow_id=space_path) + + files = [Path("People") / i for i in people] + files += [Path("Space") / i for i in space] + + return {"files": files} + + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + @router.get("/list/{flow_id}") async def list_files( flow_id: UUID = Depends(get_flow_id), storage_service: StorageService = Depends(get_storage_service) diff --git a/src/backend/base/langflow/api/v1/flows.py b/src/backend/base/langflow/api/v1/flows.py index c1ccf68db..08957e502 100644 --- a/src/backend/base/langflow/api/v1/flows.py +++ b/src/backend/base/langflow/api/v1/flows.py @@ -31,25 +31,60 @@ def create_flow( flow: FlowCreate, current_user: User = Depends(get_current_active_user), ): - """Create a new flow.""" - if flow.user_id is None: - flow.user_id = current_user.id + try: + """Create a new flow.""" + if flow.user_id is None: + flow.user_id = current_user.id - db_flow = Flow.model_validate(flow, from_attributes=True) - db_flow.updated_at = datetime.now(timezone.utc) + # First check if the flow.name is unique + # there might be flows with name like: "MyFlow", "MyFlow (1)", "MyFlow (2)" + # so we need to check if the name is unique with `like` operator + # if we find a flow with the same name, we add a number to the end of the name + # based on the highest number found + if session.exec(select(Flow).where(Flow.name == flow.name).where(Flow.user_id == current_user.id)).first(): + flows = session.exec( + select(Flow).where(Flow.name.like(f"{flow.name} (%")).where(Flow.user_id == current_user.id) + ).all() + if flows: + numbers = [int(flow.name.split("(")[1].split(")")[0]) for flow in flows] + flow.name = f"{flow.name} ({max(numbers) + 1})" + else: + flow.name = f"{flow.name} (1)" - if db_flow.folder_id is None: - # Make sure flows always have a folder - default_folder = session.exec( - select(Folder).where(Folder.name == DEFAULT_FOLDER_NAME, Folder.user_id == current_user.id) - ).first() - if default_folder: - db_flow.folder_id = default_folder.id + db_flow = Flow.model_validate(flow, from_attributes=True) + db_flow.updated_at = datetime.now(timezone.utc) - session.add(db_flow) - session.commit() - session.refresh(db_flow) - return db_flow + if db_flow.folder_id is None: + # Make sure flows always have a folder + default_folder = session.exec( + select(Folder).where(Folder.name == DEFAULT_FOLDER_NAME, Folder.user_id == current_user.id) + ).first() + if default_folder: + db_flow.folder_id = default_folder.id + + session.add(db_flow) + session.commit() + session.refresh(db_flow) + return db_flow + except Exception as e: + # If it is a validation error, return the error message + if hasattr(e, "errors"): + raise HTTPException(status_code=400, detail=str(e)) from e + elif "UNIQUE constraint failed" in str(e): + # Get the name of the column that failed + columns = str(e).split("UNIQUE constraint failed: ")[1].split(".")[1].split("\n")[0] + # UNIQUE constraint failed: flow.user_id, flow.name + # or UNIQUE constraint failed: flow.name + # if the column has id in it, we want the other column + column = columns.split(",")[1] if "id" in columns.split(",")[0] else columns.split(",")[0] + + raise HTTPException( + status_code=400, detail=f"{column.capitalize().replace('_', ' ')} must be unique" + ) from e + elif isinstance(e, HTTPException): + raise e + else: + raise HTTPException(status_code=500, detail=str(e)) from e @router.get("/", response_model=list[FlowRead], status_code=200) diff --git a/src/backend/base/langflow/api/v1/folders.py b/src/backend/base/langflow/api/v1/folders.py index 7402881c7..c9d2c0b31 100644 --- a/src/backend/base/langflow/api/v1/folders.py +++ b/src/backend/base/langflow/api/v1/folders.py @@ -7,6 +7,8 @@ from sqlmodel import Session, select from langflow.api.v1.flows import create_flows from langflow.api.v1.schemas import FlowListCreate, FlowListReadWithFolderName +from langflow.helpers.flow import generate_unique_flow_name +from langflow.helpers.folders import generate_unique_folder_name from langflow.services.auth.utils import get_current_active_user from langflow.services.database.models.flow.model import Flow, FlowCreate, FlowRead from langflow.services.database.models.folder.constants import DEFAULT_FOLDER_NAME @@ -33,17 +35,27 @@ def create_folder( try: new_folder = Folder.model_validate(folder, from_attributes=True) new_folder.user_id = current_user.id - - folder_results = session.exec( - select(Folder).where( - Folder.name.like(f"{new_folder.name}%"), # type: ignore - Folder.user_id == current_user.id, + # First check if the folder.name is unique + # there might be flows with name like: "MyFlow", "MyFlow (1)", "MyFlow (2)" + # so we need to check if the name is unique with `like` operator + # if we find a flow with the same name, we add a number to the end of the name + # based on the highest number found + if session.exec( + statement=select(Folder).where(Folder.name == new_folder.name).where(Folder.user_id == current_user.id) + ).first(): + folder_results = session.exec( + select(Folder).where( + Folder.name.like(f"{new_folder.name}%"), # type: ignore + Folder.user_id == current_user.id, + ) ) - ) - existing_folder_names = [folder.name for folder in folder_results] - - if existing_folder_names: - new_folder.name = f"{new_folder.name} ({len(existing_folder_names) + 1})" + if folder_results: + folder_names = [folder.name for folder in folder_results] + folder_numbers = [int(name.split("(")[-1].split(")")[0]) for name in folder_names if "(" in name] + if folder_numbers: + new_folder.name = f"{new_folder.name} ({max(folder_numbers) + 1})" + else: + new_folder.name = f"{new_folder.name} (1)" session.add(new_folder) session.commit() @@ -203,16 +215,9 @@ async def upload_file( if not data: raise HTTPException(status_code=400, detail="No flows found in the file") - folder_results = session.exec( - select(Folder).where( - Folder.name == data["folder_name"], - Folder.user_id == current_user.id, - ) - ) - existing_folder_names = [folder.name for folder in folder_results] + folder_name = generate_unique_folder_name(data["folder_name"], current_user.id, session) - if existing_folder_names: - data["folder_name"] = f"{data['folder_name']} ({len(existing_folder_names) + 1})" + data["folder_name"] = folder_name folder = FolderCreate(name=data["folder_name"], description=data["folder_description"]) @@ -232,6 +237,8 @@ async def upload_file( raise HTTPException(status_code=400, detail="No flows found in the data") # Now we set the user_id for all flows for flow in flow_list.flows: + flow_name = generate_unique_flow_name(flow.name, current_user.id, session) + flow.name = flow_name flow.user_id = current_user.id flow.folder_id = new_folder.id diff --git a/src/backend/base/langflow/api/v1/monitor.py b/src/backend/base/langflow/api/v1/monitor.py index ffd01b470..9714e4592 100644 --- a/src/backend/base/langflow/api/v1/monitor.py +++ b/src/backend/base/langflow/api/v1/monitor.py @@ -1,4 +1,5 @@ from typing import List, Optional + from fastapi import APIRouter, Depends, HTTPException, Query from langflow.services.deps import get_monitor_service @@ -79,7 +80,7 @@ async def delete_messages( @router.post("/messages/{message_id}", response_model=MessageModelResponse) async def update_message( - message_id: str, + message_id: int, message: MessageModelRequest, monitor_service: MonitorService = Depends(get_monitor_service), ): @@ -117,6 +118,22 @@ async def get_transactions( dicts = monitor_service.get_transactions( source=source, target=target, status=status, order_by=order_by, flow_id=flow_id ) - return [TransactionModelResponse(**d) for d in dicts] + result = [] + for d in dicts: + d = TransactionModelResponse( + index=d["index"], + timestamp=d["timestamp"], + vertex_id=d["vertex_id"], + inputs=d["inputs"], + outputs=d["outputs"], + status=d["status"], + error=d["error"], + flow_id=d["flow_id"], + source=d["vertex_id"], + target=d["target_id"], + ) + result.append(d) + return result except Exception as e: raise HTTPException(status_code=500, detail=str(e)) + raise HTTPException(status_code=500, detail=str(e)) diff --git a/src/backend/base/langflow/api/v1/schemas.py b/src/backend/base/langflow/api/v1/schemas.py index 9ccdb0085..1e0308bd5 100644 --- a/src/backend/base/langflow/api/v1/schemas.py +++ b/src/backend/base/langflow/api/v1/schemas.py @@ -9,7 +9,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_serial from langflow.graph.schema import RunOutputs from langflow.schema import dotdict from langflow.schema.graph import Tweaks -from langflow.schema.schema import InputType, OutputType +from langflow.schema.schema import InputType, Log, OutputType from langflow.services.database.models.api_key.model import ApiKeyRead from langflow.services.database.models.base import orjson_dumps from langflow.services.database.models.flow import FlowCreate, FlowRead @@ -245,6 +245,8 @@ class VerticesOrderResponse(BaseModel): class ResultDataResponse(BaseModel): results: Optional[Any] = Field(default_factory=dict) + logs: List[Log | None] = Field(default_factory=list) + message: Optional[Any] = Field(default_factory=dict) artifacts: Optional[Any] = Field(default_factory=dict) timedelta: Optional[float] = None duration: Optional[str] = None diff --git a/src/backend/base/langflow/base/agents/agent.py b/src/backend/base/langflow/base/agents/agent.py index ce40f1f51..d4328032d 100644 --- a/src/backend/base/langflow/base/agents/agent.py +++ b/src/backend/base/langflow/base/agents/agent.py @@ -7,7 +7,7 @@ from langchain_core.runnables import Runnable from langflow.base.agents.utils import get_agents_list, records_to_messages from langflow.custom import CustomComponent from langflow.field_typing import Text, Tool -from langflow.schema.schema import Record +from langflow.schema import Record class LCAgentComponent(CustomComponent): diff --git a/src/backend/base/langflow/base/agents/utils.py b/src/backend/base/langflow/base/agents/utils.py index cb34d1cea..781fa2362 100644 --- a/src/backend/base/langflow/base/agents/utils.py +++ b/src/backend/base/langflow/base/agents/utils.py @@ -13,7 +13,7 @@ from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate from langchain_core.tools import BaseTool from pydantic import BaseModel -from langflow.schema.schema import Record +from langflow.schema import Record from .default_prompts import XML_AGENT_PROMPT diff --git a/src/backend/base/langflow/base/constants.py b/src/backend/base/langflow/base/constants.py index 498b46f65..cb520a835 100644 --- a/src/backend/base/langflow/base/constants.py +++ b/src/backend/base/langflow/base/constants.py @@ -7,9 +7,11 @@ Constants: - FIELD_FORMAT_ATTRIBUTES: A list of attributes used for formatting fields. """ +import orjson + STREAM_INFO_TEXT = "Stream the response from the model. Streaming works only in Chat." -NODE_FORMAT_ATTRIBUTES = ["beta", "icon", "display_name", "description"] +NODE_FORMAT_ATTRIBUTES = ["beta", "icon", "display_name", "description", "output_types"] FIELD_FORMAT_ATTRIBUTES = [ @@ -27,3 +29,5 @@ FIELD_FORMAT_ATTRIBUTES = [ "refresh_button_text", "options", ] + +ORJSON_OPTIONS = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS | orjson.OPT_OMIT_MICROSECONDS diff --git a/src/backend/base/langflow/base/data/utils.py b/src/backend/base/langflow/base/data/utils.py index 0c7cc3fef..9bad1dabf 100644 --- a/src/backend/base/langflow/base/data/utils.py +++ b/src/backend/base/langflow/base/data/utils.py @@ -1,13 +1,14 @@ -import json +import unicodedata import xml.etree.ElementTree as ET from concurrent import futures from pathlib import Path from typing import Callable, List, Optional, Text import chardet +import orjson import yaml -from langflow.schema.schema import Record +from langflow.schema import Record # Types of files that can be read simply by file.read() # and have 100% to be completely readable @@ -32,6 +33,17 @@ TEXT_FILE_TYPES = [ "tsx", ] +IMG_FILE_TYPES = [ + "jpg", + "jpeg", + "png", + "bmp", +] + + +def normalize_text(text): + return unicodedata.normalize("NFKD", text) + def is_hidden(path: Path) -> bool: return path.name.startswith(".") @@ -125,9 +137,15 @@ def parse_text_file_to_record(file_path: str, silent_errors: bool) -> Optional[R text = read_docx_file(file_path) else: text = read_text_file(file_path) + # if file is json, yaml, or xml, we can parse it if file_path.endswith(".json"): - text = json.loads(text) + text = orjson.loads(text) + if isinstance(text, dict): + text = {k: normalize_text(v) if isinstance(v, str) else v for k, v in text.items()} + elif isinstance(text, list): + text = [normalize_text(item) if isinstance(item, str) else item for item in text] + elif file_path.endswith(".yaml") or file_path.endswith(".yml"): text = yaml.safe_load(text) elif file_path.endswith(".xml"): diff --git a/src/backend/base/langflow/base/flow_processing/utils.py b/src/backend/base/langflow/base/flow_processing/utils.py index 4e121f128..1f756a1db 100644 --- a/src/backend/base/langflow/base/flow_processing/utils.py +++ b/src/backend/base/langflow/base/flow_processing/utils.py @@ -1,7 +1,7 @@ from typing import List from langflow.graph.schema import ResultData, RunOutputs -from langflow.schema.schema import Record +from langflow.schema import Record def build_records_from_run_outputs(run_outputs: RunOutputs) -> List[Record]: diff --git a/src/backend/base/langflow/base/io/chat.py b/src/backend/base/langflow/base/io/chat.py index 6089f19ea..b722c16ab 100644 --- a/src/backend/base/langflow/base/io/chat.py +++ b/src/backend/base/langflow/base/io/chat.py @@ -1,10 +1,10 @@ from typing import Optional, Union +from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES from langflow.custom import CustomComponent -from langflow.field_typing import Text -from langflow.helpers.record import records_to_text from langflow.memory import store_message from langflow.schema import Record +from langflow.schema.message import Message class ChatComponent(CustomComponent): @@ -15,7 +15,7 @@ class ChatComponent(CustomComponent): return { "input_value": { "input_types": ["Text"], - "display_name": "Message", + "display_name": "Text", "multiline": True, }, "sender": { @@ -23,7 +23,7 @@ class ChatComponent(CustomComponent): "display_name": "Sender Type", "advanced": True, }, - "sender_name": {"display_name": "Sender Name"}, + "sender_name": {"display_name": "Sender Name", "advanced": True}, "session_id": { "display_name": "Session ID", "info": "If provided, the message will be stored in the memory.", @@ -40,98 +40,45 @@ class ChatComponent(CustomComponent): "info": "In case of Message being a Record, this template will be used to convert it to text.", "advanced": True, }, + "files": { + "field_type": "file", + "display_name": "Files", + "file_types": TEXT_FILE_TYPES + IMG_FILE_TYPES, + "info": "Files to be sent with the message.", + "advanced": True, + }, } def store_message( self, - message: Union[str, Text, Record], - session_id: Optional[str] = None, - sender: Optional[str] = None, - sender_name: Optional[str] = None, - ) -> list[Record]: - records = store_message( + message: Message, + ) -> list[Message]: + messages = store_message( message, - session_id=session_id, - sender=sender, - sender_name=sender_name, flow_id=self.graph.flow_id, ) - self.status = records - return records + self.status = messages + return messages def build_with_record( self, sender: Optional[str] = "User", sender_name: Optional[str] = "User", - input_value: Optional[Union[str, Record]] = None, + input_value: Optional[Union[str, Record, Message]] = None, + files: Optional[list[str]] = None, session_id: Optional[str] = None, - return_record: Optional[bool] = False, - record_template: str = "Text: {text}\nData: {data}", - ) -> Union[Text, Record]: - input_value_record: Optional[Record] = None - if return_record: - if isinstance(input_value, Record): - # Update the data of the record - input_value.data["sender"] = sender - input_value.data["sender_name"] = sender_name - input_value.data["session_id"] = session_id - else: - input_value_record = Record( - text=input_value, - data={ - "sender": sender, - "sender_name": sender_name, - "session_id": session_id, - }, - ) - elif isinstance(input_value, Record): - input_value = records_to_text(template=record_template, records=input_value) - if not input_value: - input_value = "" - if return_record and input_value_record: - result: Union[Text, Record] = input_value_record - else: - result = input_value - self.status = result - if session_id and isinstance(result, (Record, str)): - self.store_message(result, session_id, sender, sender_name) - return result + ) -> Message: + message: Message | None = None - def build_no_record( - self, - sender: Optional[str] = "User", - sender_name: Optional[str] = "User", - input_value: Optional[str] = None, - session_id: Optional[str] = None, - return_record: Optional[bool] = False, - record_template: str = "Text: {text}\nData: {data}", - ) -> Union[Text, Record]: - input_value_record: Optional[Record] = None - if return_record: - if isinstance(input_value, Record): - # Update the data of the record - input_value.data["sender"] = sender - input_value.data["sender_name"] = sender_name - input_value.data["session_id"] = session_id - else: - input_value_record = Record( - text=input_value, - data={ - "sender": sender, - "sender_name": sender_name, - "session_id": session_id, - }, - ) - elif isinstance(input_value, Record): - input_value = records_to_text(template=record_template, records=input_value) - if not input_value: - input_value = "" - if return_record and input_value_record: - result: Union[Text, Record] = input_value_record + if isinstance(input_value, Record): + # Update the data of the record + message = Message.from_record(input_value) else: - result = input_value - self.status = result - if session_id and isinstance(result, (Record, str)): - self.store_message(result, session_id, sender, sender_name) - return result + message = Message( + text=input_value, sender=sender, sender_name=sender_name, files=files, session_id=session_id + ) + self.status = message + if session_id and isinstance(message, Message) and isinstance(message.text, str): + self.store_message(message) + return message diff --git a/src/backend/base/langflow/base/io/text.py b/src/backend/base/langflow/base/io/text.py index 5ecfea11a..5b6ece996 100644 --- a/src/backend/base/langflow/base/io/text.py +++ b/src/backend/base/langflow/base/io/text.py @@ -3,7 +3,7 @@ from typing import Optional from langflow.custom import CustomComponent from langflow.field_typing import Text from langflow.helpers.record import records_to_text -from langflow.schema.schema import Record +from langflow.schema import Record class TextComponent(CustomComponent): diff --git a/src/backend/base/langflow/base/memory/memory.py b/src/backend/base/langflow/base/memory/memory.py index 0fb8cf209..fe372a96b 100644 --- a/src/backend/base/langflow/base/memory/memory.py +++ b/src/backend/base/langflow/base/memory/memory.py @@ -1,7 +1,7 @@ from typing import Optional from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class BaseMemoryComponent(CustomComponent): diff --git a/src/backend/base/langflow/base/models/model.py b/src/backend/base/langflow/base/models/model.py index b38d275f9..74d350446 100644 --- a/src/backend/base/langflow/base/models/model.py +++ b/src/backend/base/langflow/base/models/model.py @@ -1,3 +1,4 @@ +import warnings from typing import Optional, Union from langchain_core.language_models.chat_models import BaseChatModel @@ -5,6 +6,7 @@ from langchain_core.language_models.llms import LLM from langchain_core.messages import AIMessage, HumanMessage, SystemMessage from langflow.custom import CustomComponent +from langflow.field_typing.prompt import Prompt class LCModelComponent(CustomComponent): @@ -53,19 +55,28 @@ class LCModelComponent(CustomComponent): key in response_metadata["token_usage"] for key in inner_openai_keys ): token_usage = response_metadata["token_usage"] - completion_tokens = token_usage["completion_tokens"] - prompt_tokens = token_usage["prompt_tokens"] - total_tokens = token_usage["total_tokens"] - finish_reason = response_metadata["finish_reason"] - status_message = f"Tokens:\nInput: {prompt_tokens}\nOutput: {completion_tokens}\nTotal Tokens: {total_tokens}\nStop Reason: {finish_reason}\nResponse: {content}" + status_message = { + "tokens": { + "input": token_usage["prompt_tokens"], + "output": token_usage["completion_tokens"], + "total": token_usage["total_tokens"], + "stop_reason": response_metadata["finish_reason"], + "response": content, + } + } + elif all(key in response_metadata for key in anthropic_keys) and all( key in response_metadata["usage"] for key in inner_anthropic_keys ): usage = response_metadata["usage"] - input_tokens = usage["input_tokens"] - output_tokens = usage["output_tokens"] - stop_reason = response_metadata["stop_reason"] - status_message = f"Tokens:\nInput: {input_tokens}\nOutput: {output_tokens}\nStop Reason: {stop_reason}\nResponse: {content}" + status_message = { + "tokens": { + "input": usage["input_tokens"], + "output": usage["output_tokens"], + "stop_reason": response_metadata["stop_reason"], + "response": content, + } + } else: status_message = f"Response: {content}" else: @@ -73,7 +84,7 @@ class LCModelComponent(CustomComponent): return status_message def get_chat_result( - self, runnable: BaseChatModel, stream: bool, input_value: str, system_message: Optional[str] = None + self, runnable: BaseChatModel, stream: bool, input_value: str | Prompt, system_message: Optional[str] = None ): messages: list[Union[HumanMessage, SystemMessage]] = [] if not input_value and not system_message: @@ -81,11 +92,21 @@ class LCModelComponent(CustomComponent): if system_message: messages.append(SystemMessage(content=system_message)) if input_value: - messages.append(HumanMessage(content=input_value)) + if isinstance(input_value, Prompt): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + if "prompt" in input_value: + prompt = input_value.load_lc_prompt() + runnable = prompt | runnable + else: + messages.append(input_value.to_lc_message()) + else: + messages.append(HumanMessage(content=input_value)) + inputs = messages or {} if stream: - return runnable.stream(messages) + return runnable.stream(inputs) else: - message = runnable.invoke(messages) + message = runnable.invoke(inputs) result = message.content if isinstance(message, AIMessage): status_message = self.build_status_message(message) diff --git a/src/backend/base/langflow/base/prompts/utils.py b/src/backend/base/langflow/base/prompts/utils.py index 2270035af..0fa62ea3b 100644 --- a/src/backend/base/langflow/base/prompts/utils.py +++ b/src/backend/base/langflow/base/prompts/utils.py @@ -1,9 +1,9 @@ from copy import deepcopy - from langchain_core.documents import Document from langflow.schema import Record +from langflow.schema.message import Message def record_to_string(record: Record) -> str: @@ -35,10 +35,14 @@ def dict_values_to_string(d: dict) -> dict: # it could be a list of records or documents or strings if isinstance(value, list): for i, item in enumerate(value): - if isinstance(item, Record): + if isinstance(item, Message): + d_copy[key][i] = item.text + elif isinstance(item, Record): d_copy[key][i] = record_to_string(item) elif isinstance(item, Document): d_copy[key][i] = document_to_string(item) + elif isinstance(value, Message): + d_copy[key] = value.text elif isinstance(value, Record): d_copy[key] = record_to_string(value) elif isinstance(value, Document): diff --git a/src/backend/base/langflow/base/vectorstores/__init__.py b/src/backend/base/langflow/base/vectorstores/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/backend/base/langflow/base/vectorstores/utils.py b/src/backend/base/langflow/base/vectorstores/utils.py new file mode 100644 index 000000000..739181600 --- /dev/null +++ b/src/backend/base/langflow/base/vectorstores/utils.py @@ -0,0 +1,24 @@ +from langflow.schema import Record + + +def chroma_collection_to_records(collection_dict: dict): + """ + Converts a collection of chroma vectors into a list of records. + + Args: + collection_dict (dict): A dictionary containing the collection of chroma vectors. + + Returns: + list: A list of records, where each record represents a document in the collection. + """ + records = [] + for i, doc in enumerate(collection_dict["documents"]): + record_dict = { + "id": collection_dict["ids"][i], + "text": doc, + } + if "metadatas" in collection_dict: + for key, value in collection_dict["metadatas"][i].items(): + record_dict[key] = value + records.append(Record(**record_dict)) + return records diff --git a/src/backend/base/langflow/components/agents/ToolCallingAgent.py b/src/backend/base/langflow/components/agents/ToolCallingAgent.py index b4a319e2f..91fcb1132 100644 --- a/src/backend/base/langflow/components/agents/ToolCallingAgent.py +++ b/src/backend/base/langflow/components/agents/ToolCallingAgent.py @@ -5,7 +5,7 @@ from langchain_core.prompts import ChatPromptTemplate from langflow.base.agents.agent import LCAgentComponent from langflow.field_typing import BaseLanguageModel, Text, Tool -from langflow.schema.schema import Record +from langflow.schema import Record class ToolCallingAgentComponent(LCAgentComponent): diff --git a/src/backend/base/langflow/components/agents/XMLAgent.py b/src/backend/base/langflow/components/agents/XMLAgent.py index 76f96da53..47f823ba4 100644 --- a/src/backend/base/langflow/components/agents/XMLAgent.py +++ b/src/backend/base/langflow/components/agents/XMLAgent.py @@ -3,10 +3,9 @@ from typing import List, Optional from langchain.agents import create_xml_agent from langchain_core.prompts import ChatPromptTemplate - from langflow.base.agents.agent import LCAgentComponent from langflow.field_typing import BaseLanguageModel, Text, Tool -from langflow.schema.schema import Record +from langflow.schema import Record class XMLAgentComponent(LCAgentComponent): diff --git a/src/backend/base/langflow/components/chains/RetrievalQA.py b/src/backend/base/langflow/components/chains/RetrievalQA.py index da77f89d4..ca9910279 100644 --- a/src/backend/base/langflow/components/chains/RetrievalQA.py +++ b/src/backend/base/langflow/components/chains/RetrievalQA.py @@ -5,7 +5,7 @@ from langchain_core.documents import Document from langflow.custom import CustomComponent from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever, Text -from langflow.schema.schema import Record +from langflow.schema import Record class RetrievalQAComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/data/URL.py b/src/backend/base/langflow/components/data/URL.py index f9e515205..32ebc91ee 100644 --- a/src/backend/base/langflow/components/data/URL.py +++ b/src/backend/base/langflow/components/data/URL.py @@ -20,7 +20,7 @@ class URLComponent(CustomComponent): self, urls: list[str], ) -> list[Record]: - loader = WebBaseLoader(web_paths=urls) + loader = WebBaseLoader(web_paths=[url for url in urls if url]) docs = loader.load() records = self.to_records(docs) self.status = records diff --git a/src/backend/base/langflow/components/data/Webhook.py b/src/backend/base/langflow/components/data/Webhook.py index cf82e07d2..a1989cd49 100644 --- a/src/backend/base/langflow/components/data/Webhook.py +++ b/src/backend/base/langflow/components/data/Webhook.py @@ -3,8 +3,8 @@ import uuid from typing import Any, Optional from langflow.custom import CustomComponent +from langflow.schema import Record from langflow.schema.dotdict import dotdict -from langflow.schema.schema import Record class WebhookComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/experimental/AgentComponent.py b/src/backend/base/langflow/components/experimental/AgentComponent.py index 9a6840a41..abd8826d4 100644 --- a/src/backend/base/langflow/components/experimental/AgentComponent.py +++ b/src/backend/base/langflow/components/experimental/AgentComponent.py @@ -6,8 +6,8 @@ from langchain_core.prompts.chat import HumanMessagePromptTemplate, SystemMessag from langflow.base.agents.agent import LCAgentComponent from langflow.base.agents.utils import AGENTS, AgentSpec, get_agents_list from langflow.field_typing import BaseLanguageModel, Text, Tool +from langflow.schema import Record from langflow.schema.dotdict import dotdict -from langflow.schema.schema import Record class AgentComponent(LCAgentComponent): diff --git a/src/backend/base/langflow/components/experimental/Embed.py b/src/backend/base/langflow/components/experimental/Embed.py new file mode 100644 index 000000000..88de23486 --- /dev/null +++ b/src/backend/base/langflow/components/experimental/Embed.py @@ -0,0 +1,15 @@ +from langflow.custom import CustomComponent +from langflow.schema import Record +from langflow.field_typing import Embeddings + + +class EmbedComponent(CustomComponent): + display_name = "Embed Texts" + + def build_config(self): + return {"texts": {"display_name": "Texts"}, "embbedings": {"display_name": "Embeddings"}} + + def build(self, texts: list[str], embbedings: Embeddings) -> Embeddings: + vectors = Record(vector=embbedings.embed_documents(texts)) + self.status = vectors + return vectors diff --git a/src/backend/base/langflow/components/experimental/FlowTool.py b/src/backend/base/langflow/components/experimental/FlowTool.py index fa81f6351..eaebb0c6e 100644 --- a/src/backend/base/langflow/components/experimental/FlowTool.py +++ b/src/backend/base/langflow/components/experimental/FlowTool.py @@ -7,8 +7,8 @@ from langflow.custom import CustomComponent from langflow.field_typing import Tool from langflow.graph.graph.base import Graph from langflow.helpers.flow import get_flow_inputs +from langflow.schema import Record from langflow.schema.dotdict import dotdict -from langflow.schema.schema import Record class FlowToolComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/experimental/Message.py b/src/backend/base/langflow/components/experimental/Message.py new file mode 100644 index 000000000..9fdd8a0da --- /dev/null +++ b/src/backend/base/langflow/components/experimental/Message.py @@ -0,0 +1,38 @@ +from typing import Optional + +from langflow.custom import CustomComponent +from langflow.schema.message import Message + + +class MessageComponent(CustomComponent): + display_name = "Message" + description = "Creates a Message object given a Session ID." + + def build_config(self): + return { + "sender": { + "options": ["Machine", "User"], + "display_name": "Sender Type", + }, + "sender_name": {"display_name": "Sender Name"}, + "text": {"display_name": "Text"}, + "session_id": { + "display_name": "Session ID", + "info": "Session ID of the chat history.", + "input_types": ["Text"], + }, + } + + def build( + self, + sender: str = "User", + sender_name: Optional[str] = None, + session_id: Optional[str] = None, + text: str = "", + ) -> Message: + message = Message( + text=text, sender=sender, sender_name=sender_name, flow_id=self.graph.flow_id, session_id=session_id + ) + + self.status = message + return message diff --git a/src/backend/base/langflow/components/experimental/StoreMessage.py b/src/backend/base/langflow/components/experimental/StoreMessage.py index 761646188..5d0abfbb9 100644 --- a/src/backend/base/langflow/components/experimental/StoreMessage.py +++ b/src/backend/base/langflow/components/experimental/StoreMessage.py @@ -1,43 +1,22 @@ -from typing import List, Optional - from langflow.custom import CustomComponent from langflow.memory import get_messages, store_message -from langflow.schema import Record +from langflow.schema.message import Message class StoreMessageComponent(CustomComponent): display_name = "Store Message" - description = "Stores a chat message given a Session ID." - beta: bool = True + description = "Stores a chat message." def build_config(self): return { - "sender": { - "options": ["Machine", "User"], - "display_name": "Sender Type", - }, - "sender_name": {"display_name": "Sender Name"}, "message": {"display_name": "Message"}, - "session_id": { - "display_name": "Session ID", - "info": "Session ID of the chat history.", - "input_types": ["Text"], - }, } def build( self, - sender: str = "User", - sender_name: Optional[str] = None, - session_id: Optional[str] = None, - message: str = "", - ) -> List[Record]: - store_message( - sender=sender, - sender_name=sender_name, - session_id=session_id, - message=message, - ) + message: Message, + ) -> Message: + store_message(message, flow_id=self.graph.flow_id) + self.status = get_messages() - self.status = get_messages(session_id=session_id) - return get_messages(session_id=session_id) + return message diff --git a/src/backend/base/langflow/components/helpers/MemoryComponent.py b/src/backend/base/langflow/components/helpers/MemoryComponent.py index 6d19bfd59..96e82da1e 100644 --- a/src/backend/base/langflow/components/helpers/MemoryComponent.py +++ b/src/backend/base/langflow/components/helpers/MemoryComponent.py @@ -2,9 +2,9 @@ from typing import Optional from langflow.base.memory.memory import BaseMemoryComponent from langflow.field_typing import Text -from langflow.helpers.record import records_to_text +from langflow.helpers.record import messages_to_text from langflow.memory import get_messages -from langflow.schema.schema import Record +from langflow.schema.message import Message class MemoryComponent(BaseMemoryComponent): @@ -43,7 +43,7 @@ class MemoryComponent(BaseMemoryComponent): }, } - def get_messages(self, **kwargs) -> list[Record]: + def get_messages(self, **kwargs) -> list[Message]: # Validate kwargs by checking if it contains the correct keys if "sender" not in kwargs: kwargs["sender"] = None @@ -77,6 +77,6 @@ class MemoryComponent(BaseMemoryComponent): limit=n_messages, order=order, ) - messages_str = records_to_text(template=record_template or "", records=messages) + messages_str = messages_to_text(template=record_template or "", messages=messages) self.status = messages_str return messages_str diff --git a/src/backend/base/langflow/components/helpers/MessageHistory.py b/src/backend/base/langflow/components/helpers/MessageHistory.py index 221d90c4e..90191e7d0 100644 --- a/src/backend/base/langflow/components/helpers/MessageHistory.py +++ b/src/backend/base/langflow/components/helpers/MessageHistory.py @@ -6,25 +6,27 @@ from langflow.schema import Record class MessageHistoryComponent(CustomComponent): - display_name = "Message History" - description = "Retrieves stored chat messages given a specific Session ID." - beta: bool = True + display_name = "Memory" + description = "Retrieves stored chat messages." def build_config(self): return { "sender": { "options": ["Machine", "User", "Machine and User"], "display_name": "Sender Type", + "advanced": True, }, "sender_name": {"display_name": "Sender Name", "advanced": True}, "n_messages": { "display_name": "Number of Messages", "info": "Number of messages to retrieve.", + "advanced": True, }, "session_id": { "display_name": "Session ID", "info": "Session ID of the chat history.", "input_types": ["Text"], + "advanced": True, }, "order": { "options": ["Ascending", "Descending"], @@ -39,7 +41,7 @@ class MessageHistoryComponent(CustomComponent): sender: Optional[str] = "Machine and User", sender_name: Optional[str] = None, session_id: Optional[str] = None, - n_messages: int = 5, + n_messages: int = 100, order: Optional[str] = "Descending", ) -> List[Record]: order = "DESC" if order == "Descending" else "ASC" diff --git a/src/backend/base/langflow/components/helpers/RecordsToText.py b/src/backend/base/langflow/components/helpers/RecordsToText.py index d3e418792..049c99243 100644 --- a/src/backend/base/langflow/components/helpers/RecordsToText.py +++ b/src/backend/base/langflow/components/helpers/RecordsToText.py @@ -17,6 +17,7 @@ class RecordsToTextComponent(CustomComponent): "template": { "display_name": "Template", "info": "The template to use for formatting the records. It can contain the keys {text}, {data} or any other key in the Record.", + "multiline": True, }, } diff --git a/src/backend/base/langflow/components/inputs/ChatInput.py b/src/backend/base/langflow/components/inputs/ChatInput.py index 40203851f..150d5f2af 100644 --- a/src/backend/base/langflow/components/inputs/ChatInput.py +++ b/src/backend/base/langflow/components/inputs/ChatInput.py @@ -1,8 +1,7 @@ -from typing import Optional, Union +from typing import Optional from langflow.base.io.chat import ChatComponent -from langflow.field_typing import Text -from langflow.schema import Record +from langflow.schema.message import Message class ChatInput(ChatComponent): @@ -14,7 +13,7 @@ class ChatInput(ChatComponent): build_config = super().build_config() build_config["input_value"] = { "input_types": [], - "display_name": "Message", + "display_name": "Text", "multiline": True, } @@ -25,13 +24,13 @@ class ChatInput(ChatComponent): sender: Optional[str] = "User", sender_name: Optional[str] = "User", input_value: Optional[str] = None, + files: Optional[list[str]] = None, session_id: Optional[str] = None, - return_record: Optional[bool] = False, - ) -> Union[Text, Record]: - return super().build_no_record( + ) -> Message: + return super().build_with_record( sender=sender, sender_name=sender_name, input_value=input_value, + files=files, session_id=session_id, - return_record=return_record, ) diff --git a/src/backend/base/langflow/components/inputs/Prompt.py b/src/backend/base/langflow/components/inputs/Prompt.py index 2c76e6132..e65d27576 100644 --- a/src/backend/base/langflow/components/inputs/Prompt.py +++ b/src/backend/base/langflow/components/inputs/Prompt.py @@ -1,7 +1,6 @@ -from langchain_core.prompts import PromptTemplate - from langflow.custom import CustomComponent -from langflow.field_typing import Prompt, TemplateField, Text +from langflow.field_typing import TemplateField +from langflow.field_typing.prompt import Prompt class PromptComponent(CustomComponent): @@ -15,19 +14,11 @@ class PromptComponent(CustomComponent): "code": TemplateField(advanced=True), } - def build( + async def build( self, template: Prompt, **kwargs, - ) -> Text: - from langflow.base.prompts.utils import dict_values_to_string - - prompt_template = PromptTemplate.from_template(Text(template)) - kwargs = dict_values_to_string(kwargs) - kwargs = {k: "\n".join(v) if isinstance(v, list) else v for k, v in kwargs.items()} - try: - formated_prompt = prompt_template.format(**kwargs) - except Exception as exc: - raise ValueError(f"Error formatting prompt: {exc}") from exc - self.status = f'Prompt:\n"{formated_prompt}"' - return formated_prompt + ) -> Prompt: + prompt = await Prompt.from_template_and_variables(template, kwargs) + self.status = prompt.format_text() + return prompt diff --git a/src/backend/base/langflow/components/inputs/TextInput.py b/src/backend/base/langflow/components/inputs/TextInput.py index b2317678e..4edf21723 100644 --- a/src/backend/base/langflow/components/inputs/TextInput.py +++ b/src/backend/base/langflow/components/inputs/TextInput.py @@ -12,7 +12,7 @@ class TextInput(TextComponent): def build_config(self): return { "input_value": { - "display_name": "Value", + "display_name": "Text", "input_types": ["Record", "Text"], "info": "Text or Record to be passed as input.", }, diff --git a/src/backend/base/langflow/components/langchain_utilities/SearchApi.py b/src/backend/base/langflow/components/langchain_utilities/SearchApi.py index 3dcd48d9f..3e6721fd6 100644 --- a/src/backend/base/langflow/components/langchain_utilities/SearchApi.py +++ b/src/backend/base/langflow/components/langchain_utilities/SearchApi.py @@ -3,7 +3,7 @@ from typing import Optional from langchain_community.utilities.searchapi import SearchApiAPIWrapper from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record from langflow.services.database.models.base import orjson_dumps diff --git a/src/backend/base/langflow/components/memories/AstraDBMessageReader.py b/src/backend/base/langflow/components/memories/AstraDBMessageReader.py index c61909887..8d845be73 100644 --- a/src/backend/base/langflow/components/memories/AstraDBMessageReader.py +++ b/src/backend/base/langflow/components/memories/AstraDBMessageReader.py @@ -1,8 +1,7 @@ from typing import Optional, cast - from langflow.base.memory.memory import BaseMemoryComponent -from langflow.schema.schema import Record +from langflow.schema.record import Record class AstraDBMessageReaderComponent(BaseMemoryComponent): diff --git a/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py b/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py index 30c98e16c..7aae7009b 100644 --- a/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py +++ b/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py @@ -1,10 +1,10 @@ from typing import Optional -from langflow.base.memory.memory import BaseMemoryComponent -from langflow.schema.schema import Record - from langchain_core.messages import BaseMessage +from langflow.base.memory.memory import BaseMemoryComponent +from langflow.schema.record import Record + class AstraDBMessageWriterComponent(BaseMemoryComponent): display_name = "Astra DB Message Writer" diff --git a/src/backend/base/langflow/components/memories/CassandraMessageReader.py b/src/backend/base/langflow/components/memories/CassandraMessageReader.py index 3545d444a..3fd11d772 100644 --- a/src/backend/base/langflow/components/memories/CassandraMessageReader.py +++ b/src/backend/base/langflow/components/memories/CassandraMessageReader.py @@ -3,7 +3,7 @@ from typing import Optional, cast from langchain_community.chat_message_histories import CassandraChatMessageHistory from langflow.base.memory.memory import BaseMemoryComponent -from langflow.schema.schema import Record +from langflow.schema.record import Record class CassandraMessageReaderComponent(BaseMemoryComponent): diff --git a/src/backend/base/langflow/components/memories/CassandraMessageWriter.py b/src/backend/base/langflow/components/memories/CassandraMessageWriter.py index 716364b64..c8e3831a5 100644 --- a/src/backend/base/langflow/components/memories/CassandraMessageWriter.py +++ b/src/backend/base/langflow/components/memories/CassandraMessageWriter.py @@ -1,10 +1,10 @@ from typing import Optional -from langflow.base.memory.memory import BaseMemoryComponent -from langflow.schema.schema import Record - -from langchain_core.messages import BaseMessage from langchain_community.chat_message_histories import CassandraChatMessageHistory +from langchain_core.messages import BaseMessage + +from langflow.base.memory.memory import BaseMemoryComponent +from langflow.schema.record import Record class CassandraMessageWriterComponent(BaseMemoryComponent): diff --git a/src/backend/base/langflow/components/memories/ZepMessageReader.py b/src/backend/base/langflow/components/memories/ZepMessageReader.py index 75b27091f..feef017a6 100644 --- a/src/backend/base/langflow/components/memories/ZepMessageReader.py +++ b/src/backend/base/langflow/components/memories/ZepMessageReader.py @@ -4,7 +4,7 @@ from langchain_community.chat_message_histories.zep import SearchScope, SearchTy from langflow.base.memory.memory import BaseMemoryComponent from langflow.field_typing import Text -from langflow.schema.schema import Record +from langflow.schema import Record class ZepMessageReaderComponent(BaseMemoryComponent): diff --git a/src/backend/base/langflow/components/memories/ZepMessageWriter.py b/src/backend/base/langflow/components/memories/ZepMessageWriter.py index b062f66bf..c3d55a721 100644 --- a/src/backend/base/langflow/components/memories/ZepMessageWriter.py +++ b/src/backend/base/langflow/components/memories/ZepMessageWriter.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Optional from langflow.base.memory.memory import BaseMemoryComponent from langflow.field_typing import Text -from langflow.schema.schema import Record +from langflow.schema import Record if TYPE_CHECKING: from zep_python.langchain import ZepChatMessageHistory diff --git a/src/backend/base/langflow/components/models/AmazonBedrockModel.py b/src/backend/base/langflow/components/models/AmazonBedrockModel.py index 1015f1684..99229deb2 100644 --- a/src/backend/base/langflow/components/models/AmazonBedrockModel.py +++ b/src/backend/base/langflow/components/models/AmazonBedrockModel.py @@ -58,7 +58,7 @@ class AmazonBedrockComponent(LCModelComponent): "advanced": True, }, "cache": {"display_name": "Cache"}, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "system_message": { "display_name": "System Message", "info": "System message to pass to the model.", diff --git a/src/backend/base/langflow/components/models/AnthropicModel.py b/src/backend/base/langflow/components/models/AnthropicModel.py index cfe9ed900..bac7708d4 100644 --- a/src/backend/base/langflow/components/models/AnthropicModel.py +++ b/src/backend/base/langflow/components/models/AnthropicModel.py @@ -63,7 +63,7 @@ class AnthropicLLM(LCModelComponent): "info": "Endpoint of the Anthropic API. Defaults to 'https://api.anthropic.com' if not specified.", }, "code": {"show": False}, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "advanced": True, diff --git a/src/backend/base/langflow/components/models/AzureOpenAIModel.py b/src/backend/base/langflow/components/models/AzureOpenAIModel.py index c296a8fae..97ee88920 100644 --- a/src/backend/base/langflow/components/models/AzureOpenAIModel.py +++ b/src/backend/base/langflow/components/models/AzureOpenAIModel.py @@ -78,7 +78,7 @@ class AzureChatOpenAIComponent(LCModelComponent): "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", }, "code": {"show": False}, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, diff --git a/src/backend/base/langflow/components/models/BaiduQianfanChatModel.py b/src/backend/base/langflow/components/models/BaiduQianfanChatModel.py index f5e6497d0..aaae3112f 100644 --- a/src/backend/base/langflow/components/models/BaiduQianfanChatModel.py +++ b/src/backend/base/langflow/components/models/BaiduQianfanChatModel.py @@ -81,7 +81,7 @@ class QianfanChatEndpointComponent(LCModelComponent): "info": "Endpoint of the Qianfan LLM, required if custom model used.", }, "code": {"show": False}, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, diff --git a/src/backend/base/langflow/components/models/ChatLiteLLMModel.py b/src/backend/base/langflow/components/models/ChatLiteLLMModel.py index 054b59d12..aa3cf6976 100644 --- a/src/backend/base/langflow/components/models/ChatLiteLLMModel.py +++ b/src/backend/base/langflow/components/models/ChatLiteLLMModel.py @@ -111,7 +111,7 @@ class ChatLiteLLMModelComponent(LCModelComponent): "required": False, "default": False, }, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, diff --git a/src/backend/base/langflow/components/models/CohereModel.py b/src/backend/base/langflow/components/models/CohereModel.py index 3bd12c095..b5ecbab9f 100644 --- a/src/backend/base/langflow/components/models/CohereModel.py +++ b/src/backend/base/langflow/components/models/CohereModel.py @@ -1,10 +1,11 @@ from typing import Optional +from langchain_cohere import ChatCohere from pydantic.v1 import SecretStr -from langflow.field_typing import Text + from langflow.base.constants import STREAM_INFO_TEXT from langflow.base.models.model import LCModelComponent -from langchain_cohere import ChatCohere +from langflow.field_typing import Text class CohereComponent(LCModelComponent): @@ -42,7 +43,7 @@ class CohereComponent(LCModelComponent): "type": "float", "show": True, }, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, @@ -69,3 +70,4 @@ class CohereComponent(LCModelComponent): temperature=temperature, ) return self.get_chat_result(output, stream, input_value, system_message) + return self.get_chat_result(output, stream, input_value, system_message) diff --git a/src/backend/base/langflow/components/models/HuggingFaceModel.py b/src/backend/base/langflow/components/models/HuggingFaceModel.py index 19750ef9f..949598b2d 100644 --- a/src/backend/base/langflow/components/models/HuggingFaceModel.py +++ b/src/backend/base/langflow/components/models/HuggingFaceModel.py @@ -2,9 +2,10 @@ from typing import Optional from langchain_community.chat_models.huggingface import ChatHuggingFace from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint -from langflow.field_typing import Text + from langflow.base.constants import STREAM_INFO_TEXT from langflow.base.models.model import LCModelComponent +from langflow.field_typing import Text class HuggingFaceEndpointsComponent(LCModelComponent): @@ -36,7 +37,7 @@ class HuggingFaceEndpointsComponent(LCModelComponent): "advanced": True, }, "code": {"show": False}, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, @@ -72,3 +73,4 @@ class HuggingFaceEndpointsComponent(LCModelComponent): raise ValueError("Could not connect to HuggingFace Endpoints API.") from e output = ChatHuggingFace(llm=llm) return self.get_chat_result(output, stream, input_value, system_message) + return self.get_chat_result(output, stream, input_value, system_message) diff --git a/src/backend/base/langflow/components/models/MistralModel.py b/src/backend/base/langflow/components/models/MistralModel.py index 305a45e4b..75937e70d 100644 --- a/src/backend/base/langflow/components/models/MistralModel.py +++ b/src/backend/base/langflow/components/models/MistralModel.py @@ -27,7 +27,7 @@ class MistralAIModelComponent(LCModelComponent): def build_config(self): return { - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "max_tokens": { "display_name": "Max Tokens", "advanced": True, diff --git a/src/backend/base/langflow/components/models/OllamaModel.py b/src/backend/base/langflow/components/models/OllamaModel.py index f591e4a5c..cca2a0f48 100644 --- a/src/backend/base/langflow/components/models/OllamaModel.py +++ b/src/backend/base/langflow/components/models/OllamaModel.py @@ -194,7 +194,7 @@ class ChatOllamaComponent(LCModelComponent): "info": "Template to use for generating text.", "advanced": True, }, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, diff --git a/src/backend/base/langflow/components/models/OpenAIModel.py b/src/backend/base/langflow/components/models/OpenAIModel.py index 0aedce495..329b0357f 100644 --- a/src/backend/base/langflow/components/models/OpenAIModel.py +++ b/src/backend/base/langflow/components/models/OpenAIModel.py @@ -28,7 +28,7 @@ class OpenAIModelComponent(LCModelComponent): def build_config(self): return { - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "max_tokens": { "display_name": "Max Tokens", "advanced": True, @@ -79,7 +79,7 @@ class OpenAIModelComponent(LCModelComponent): input_value: Text, openai_api_key: str, temperature: float = 0.1, - model_name: str = "gpt-4o", + model_name: str = "gpt-3.5-turbo", max_tokens: Optional[int] = 256, model_kwargs: NestedDict = {}, openai_api_base: Optional[str] = None, diff --git a/src/backend/base/langflow/components/models/VertexAiModel.py b/src/backend/base/langflow/components/models/VertexAiModel.py index a992447f4..33bbbbc46 100644 --- a/src/backend/base/langflow/components/models/VertexAiModel.py +++ b/src/backend/base/langflow/components/models/VertexAiModel.py @@ -1,6 +1,5 @@ from typing import Optional - from langflow.base.constants import STREAM_INFO_TEXT from langflow.base.models.model import LCModelComponent from langflow.field_typing import Text @@ -74,7 +73,7 @@ class ChatVertexAIComponent(LCModelComponent): "value": False, "advanced": True, }, - "input_value": {"display_name": "Input"}, + "input_value": {"display_name": "Input", "input_types": ["Text", "Record", "Prompt"]}, "stream": { "display_name": "Stream", "info": STREAM_INFO_TEXT, diff --git a/src/backend/base/langflow/components/outputs/ChatOutput.py b/src/backend/base/langflow/components/outputs/ChatOutput.py index 7994c9ded..9a118f37e 100644 --- a/src/backend/base/langflow/components/outputs/ChatOutput.py +++ b/src/backend/base/langflow/components/outputs/ChatOutput.py @@ -1,8 +1,7 @@ -from typing import Optional, Union +from typing import Optional from langflow.base.io.chat import ChatComponent -from langflow.field_typing import Text -from langflow.schema import Record +from langflow.schema.message import Message class ChatOutput(ChatComponent): @@ -16,14 +15,12 @@ class ChatOutput(ChatComponent): sender_name: Optional[str] = "AI", input_value: Optional[str] = None, session_id: Optional[str] = None, - return_record: Optional[bool] = False, - record_template: Optional[str] = "{text}", - ) -> Union[Text, Record]: + files: Optional[list[str]] = None, + ) -> Message: return super().build_with_record( sender=sender, sender_name=sender_name, input_value=input_value, session_id=session_id, - return_record=return_record, - record_template=record_template or "", + files=files, ) diff --git a/src/backend/base/langflow/components/outputs/RecordsOutput.py b/src/backend/base/langflow/components/outputs/RecordsOutput.py index 25eae862e..cbd268ea6 100644 --- a/src/backend/base/langflow/components/outputs/RecordsOutput.py +++ b/src/backend/base/langflow/components/outputs/RecordsOutput.py @@ -2,9 +2,19 @@ from langflow.custom import CustomComponent from langflow.schema import Record -class RecordsOutput(CustomComponent): +class RecordOutput(CustomComponent): display_name = "Records Output" description = "Display Records as a Table" + def build_config(self): + return { + "input_value": { + "display_name": "Records", + "input_types": ["Record"], + "info": "Record or Record list to be passed as input.", + }, + } + def build(self, input_value: Record) -> Record: + self.status = input_value return input_value diff --git a/src/backend/base/langflow/components/outputs/TextOutput.py b/src/backend/base/langflow/components/outputs/TextOutput.py index 0d55621b2..9096b7a4d 100644 --- a/src/backend/base/langflow/components/outputs/TextOutput.py +++ b/src/backend/base/langflow/components/outputs/TextOutput.py @@ -12,7 +12,7 @@ class TextOutput(TextComponent): def build_config(self): return { "input_value": { - "display_name": "Value", + "display_name": "Text", "input_types": ["Record", "Text"], "info": "Text or Record to be passed as output.", }, diff --git a/src/backend/base/langflow/components/prompts/Prompt.py b/src/backend/base/langflow/components/prompts/Prompt.py new file mode 100644 index 000000000..d2d9f78a0 --- /dev/null +++ b/src/backend/base/langflow/components/prompts/Prompt.py @@ -0,0 +1,24 @@ +from langflow.custom import CustomComponent +from langflow.field_typing import TemplateField +from langflow.field_typing.prompt import Prompt + + +class PromptComponent(CustomComponent): + display_name: str = "Empty Prompt" + description: str = "Create a prompt template with dynamic variables." + icon = "prompts" + + def build_config(self): + return { + "template": TemplateField(display_name="Template"), + "code": TemplateField(advanced=True), + } + + async def build( + self, + template: Prompt, + **kwargs, + ) -> Prompt: + prompt = await Prompt.from_template_and_variables(template, kwargs) # type: ignore + self.status = prompt.format_text() + return prompt diff --git a/src/backend/base/langflow/components/retrievers/SelfQueryRetriever.py b/src/backend/base/langflow/components/retrievers/SelfQueryRetriever.py new file mode 100644 index 000000000..3e6d6f696 --- /dev/null +++ b/src/backend/base/langflow/components/retrievers/SelfQueryRetriever.py @@ -0,0 +1,68 @@ +# from langflow.field_typing import Data +from langchain.chains.query_constructor.base import AttributeInfo +from langchain.retrievers.self_query.base import SelfQueryRetriever +from langchain_core.vectorstores import VectorStore + +from langflow.custom import CustomComponent +from langflow.field_typing import BaseLanguageModel, Text +from langflow.schema import Record +from langflow.schema.message import Message + + +class SelfQueryRetrieverComponent(CustomComponent): + display_name: str = "Self Query Retriever" + description: str = "Retriever that uses a vector store and an LLM to generate the vector store queries." + icon = "LangChain" + + def build_config(self): + return { + "query": { + "display_name": "Query", + "input_types": ["Message", "Text"], + "info": "Query to be passed as input.", + }, + "vectorstore": { + "display_name": "Vector Store", + "info": "Vector Store to be passed as input.", + }, + "attribute_infos": { + "display_name": "Metadata Field Info", + "info": "Metadata Field Info to be passed as input.", + }, + "document_content_description": { + "display_name": "Document Content Description", + "info": "Document Content Description to be passed as input.", + }, + "llm": { + "display_name": "LLM", + "info": "LLM to be passed as input.", + }, + } + + def build( + self, + query: Message, + vectorstore: VectorStore, + attribute_infos: list[Record], + document_content_description: Text, + llm: BaseLanguageModel, + ) -> Record: + metadata_field_infos = [AttributeInfo(**record.data) for record in attribute_infos] + self_query_retriever = SelfQueryRetriever.from_llm( + llm=llm, + vectorstore=vectorstore, + document_contents=document_content_description, + metadata_field_info=metadata_field_infos, + enable_limit=True, + ) + + if isinstance(query, Message): + input_text = query.text + elif isinstance(query, str): + input_text = query + else: + raise ValueError(f"Query type {type(query)} not supported.") + documents = self_query_retriever.invoke(input=input_text) + records = [Record.from_document(document) for document in documents] + self.status = records + return records diff --git a/src/backend/base/langflow/components/textsplitters/CharacterTextSplitter.py b/src/backend/base/langflow/components/textsplitters/CharacterTextSplitter.py index ee340ab26..9f60d7c88 100644 --- a/src/backend/base/langflow/components/textsplitters/CharacterTextSplitter.py +++ b/src/backend/base/langflow/components/textsplitters/CharacterTextSplitter.py @@ -3,7 +3,7 @@ from typing import List from langchain_text_splitters import CharacterTextSplitter from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record from langflow.utils.util import unescape_string diff --git a/src/backend/base/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py b/src/backend/base/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py index 7ef7d5c24..a43fdcd72 100644 --- a/src/backend/base/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py +++ b/src/backend/base/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py @@ -3,7 +3,7 @@ from typing import List, Optional from langchain_text_splitters import Language, RecursiveCharacterTextSplitter from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class LanguageRecursiveTextSplitterComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/tools/PythonCodeStructuredTool.py b/src/backend/base/langflow/components/tools/PythonCodeStructuredTool.py index cf9d85974..84392cbdb 100644 --- a/src/backend/base/langflow/components/tools/PythonCodeStructuredTool.py +++ b/src/backend/base/langflow/components/tools/PythonCodeStructuredTool.py @@ -91,4 +91,4 @@ class PythonCodeStructuredTool(CustomComponent): tool = StructuredTool.from_function( func=func, args_schema=_class, name=name, description=description, return_direct=return_direct ) - return tool + return tool # type: ignore diff --git a/src/backend/base/langflow/components/tools/SearchApi.py b/src/backend/base/langflow/components/tools/SearchApi.py index 3dcd48d9f..3e6721fd6 100644 --- a/src/backend/base/langflow/components/tools/SearchApi.py +++ b/src/backend/base/langflow/components/tools/SearchApi.py @@ -3,7 +3,7 @@ from typing import Optional from langchain_community.utilities.searchapi import SearchApiAPIWrapper from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record from langflow.services.database.models.base import orjson_dumps diff --git a/src/backend/base/langflow/components/vectorsearch/RedisSearch.py b/src/backend/base/langflow/components/vectorsearch/RedisSearch.py index afe653f6e..75aba7f8a 100644 --- a/src/backend/base/langflow/components/vectorsearch/RedisSearch.py +++ b/src/backend/base/langflow/components/vectorsearch/RedisSearch.py @@ -1,10 +1,11 @@ from typing import List, Optional +from langchain_core.embeddings import Embeddings + from langflow.components.vectorstores.base.model import LCVectorStoreComponent from langflow.components.vectorstores.Redis import RedisComponent from langflow.field_typing import Text from langflow.schema import Record -from langchain_core.embeddings import Embeddings class RedisSearchComponent(RedisComponent, LCVectorStoreComponent): diff --git a/src/backend/base/langflow/components/vectorsearch/WeaviateSearch.py b/src/backend/base/langflow/components/vectorsearch/WeaviateSearch.py index b51f65a55..b70dfa41d 100644 --- a/src/backend/base/langflow/components/vectorsearch/WeaviateSearch.py +++ b/src/backend/base/langflow/components/vectorsearch/WeaviateSearch.py @@ -1,10 +1,11 @@ from typing import List, Optional +from langchain_core.embeddings import Embeddings + from langflow.components.vectorstores.base.model import LCVectorStoreComponent from langflow.components.vectorstores.Weaviate import WeaviateVectorStoreComponent from langflow.field_typing import Text from langflow.schema import Record -from langchain_core.embeddings import Embeddings class WeaviateSearchVectorStore(WeaviateVectorStoreComponent, LCVectorStoreComponent): diff --git a/src/backend/base/langflow/components/vectorsearch/pgvectorSearch.py b/src/backend/base/langflow/components/vectorsearch/pgvectorSearch.py index c6bedfede..304439ff4 100644 --- a/src/backend/base/langflow/components/vectorsearch/pgvectorSearch.py +++ b/src/backend/base/langflow/components/vectorsearch/pgvectorSearch.py @@ -1,10 +1,11 @@ from typing import List +from langchain_core.embeddings import Embeddings + from langflow.components.vectorstores.base.model import LCVectorStoreComponent from langflow.components.vectorstores.pgvector import PGVectorComponent from langflow.field_typing import Text from langflow.schema import Record -from langchain_core.embeddings import Embeddings class PGVectorSearchComponent(PGVectorComponent, LCVectorStoreComponent): diff --git a/src/backend/base/langflow/components/vectorstores/AstraDB.py b/src/backend/base/langflow/components/vectorstores/AstraDB.py index d13b489c6..cd4a06aea 100644 --- a/src/backend/base/langflow/components/vectorstores/AstraDB.py +++ b/src/backend/base/langflow/components/vectorstores/AstraDB.py @@ -163,3 +163,4 @@ class AstraDBVectorStoreComponent(CustomComponent): ) return vector_store + return vector_store diff --git a/src/backend/base/langflow/components/vectorstores/Chroma.py b/src/backend/base/langflow/components/vectorstores/Chroma.py index 3671dbbdb..6001b119c 100644 --- a/src/backend/base/langflow/components/vectorstores/Chroma.py +++ b/src/backend/base/langflow/components/vectorstores/Chroma.py @@ -1,3 +1,4 @@ +from copy import deepcopy from typing import List, Optional, Union import chromadb @@ -7,8 +8,9 @@ from langchain_core.embeddings import Embeddings from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore +from langflow.base.vectorstores.utils import chroma_collection_to_records from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class ChromaComponent(CustomComponent): @@ -48,6 +50,11 @@ class ChromaComponent(CustomComponent): "display_name": "Server SSL Enabled", "advanced": True, }, + "allow_duplicates": { + "display_name": "Allow Duplicates", + "advanced": True, + "info": "If false, will not add documents that are already in the Vector Store.", + }, } def build( @@ -61,6 +68,7 @@ class ChromaComponent(CustomComponent): chroma_server_host: Optional[str] = None, chroma_server_http_port: Optional[int] = None, chroma_server_grpc_port: Optional[int] = None, + allow_duplicates: bool = False, ) -> Union[VectorStore, BaseRetriever]: """ Builds the Vector Store or BaseRetriever object. @@ -75,6 +83,7 @@ class ChromaComponent(CustomComponent): - chroma_server_host (Optional[str]): The host for the Chroma server. - chroma_server_http_port (Optional[int]): The HTTP port for the Chroma server. - chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server. + - allow_duplicates (bool): Whether to allow duplicates in the Vector Store. Returns: - Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object. @@ -93,32 +102,34 @@ class ChromaComponent(CustomComponent): ) client = chromadb.HttpClient(settings=chroma_settings) - # If documents, then we need to create a Chroma instance using .from_documents - # Check index_directory and expand it if it is a relative path if index_directory is not None: index_directory = self.resolve_path(index_directory) + chroma = Chroma( + persist_directory=index_directory, + client=client, + embedding_function=embedding, + collection_name=collection_name, + ) + if allow_duplicates: + stored_records = [] + else: + stored_records = chroma_collection_to_records(chroma.get()) + _stored_documents_without_id = [] + for record in deepcopy(stored_records): + del record.id + _stored_documents_without_id.append(record) documents = [] for _input in inputs or []: if isinstance(_input, Record): - documents.append(_input.to_lc_document()) + if _input not in _stored_documents_without_id: + documents.append(_input.to_lc_document()) else: - documents.append(_input) - if documents is not None and embedding is not None: - if len(documents) == 0: - raise ValueError("If documents are provided, there must be at least one document.") - chroma = Chroma.from_documents( - documents=documents, # type: ignore - persist_directory=index_directory, - collection_name=collection_name, - embedding=embedding, - client=client, - ) - else: - chroma = Chroma( - persist_directory=index_directory, - client=client, - embedding_function=embedding, - ) + raise ValueError("Inputs must be a Record objects.") + + if documents and embedding is not None: + chroma.add_documents(documents) + + self.status = stored_records return chroma diff --git a/src/backend/base/langflow/components/vectorstores/FAISS.py b/src/backend/base/langflow/components/vectorstores/FAISS.py index 9d9624919..3efd5b722 100644 --- a/src/backend/base/langflow/components/vectorstores/FAISS.py +++ b/src/backend/base/langflow/components/vectorstores/FAISS.py @@ -6,7 +6,7 @@ from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent from langflow.field_typing import Embeddings -from langflow.schema.schema import Record +from langflow.schema import Record class FAISSComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/MongoDBAtlasVector.py b/src/backend/base/langflow/components/vectorstores/MongoDBAtlasVector.py index 8c045a1bd..61c4933e9 100644 --- a/src/backend/base/langflow/components/vectorstores/MongoDBAtlasVector.py +++ b/src/backend/base/langflow/components/vectorstores/MongoDBAtlasVector.py @@ -4,7 +4,7 @@ from langchain_community.vectorstores.mongodb_atlas import MongoDBAtlasVectorSea from langflow.custom import CustomComponent from langflow.field_typing import Embeddings -from langflow.schema.schema import Record +from langflow.schema import Record class MongoDBAtlasComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Pinecone.py b/src/backend/base/langflow/components/vectorstores/Pinecone.py index 2bc0e2252..135dd7501 100644 --- a/src/backend/base/langflow/components/vectorstores/Pinecone.py +++ b/src/backend/base/langflow/components/vectorstores/Pinecone.py @@ -8,7 +8,7 @@ from langchain_pinecone.vectorstores import PineconeVectorStore from langflow.custom import CustomComponent from langflow.field_typing import Embeddings -from langflow.schema.schema import Record +from langflow.schema import Record class PineconeComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Qdrant.py b/src/backend/base/langflow/components/vectorstores/Qdrant.py index 794e282db..6c1bdbcb6 100644 --- a/src/backend/base/langflow/components/vectorstores/Qdrant.py +++ b/src/backend/base/langflow/components/vectorstores/Qdrant.py @@ -6,7 +6,7 @@ from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent from langflow.field_typing import Embeddings -from langflow.schema.schema import Record +from langflow.schema import Record class QdrantComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Redis.py b/src/backend/base/langflow/components/vectorstores/Redis.py index 04d137538..c35ec018e 100644 --- a/src/backend/base/langflow/components/vectorstores/Redis.py +++ b/src/backend/base/langflow/components/vectorstores/Redis.py @@ -6,7 +6,7 @@ from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class RedisComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/SupabaseVectorStore.py b/src/backend/base/langflow/components/vectorstores/SupabaseVectorStore.py index 5e87a09ca..e7c847f2b 100644 --- a/src/backend/base/langflow/components/vectorstores/SupabaseVectorStore.py +++ b/src/backend/base/langflow/components/vectorstores/SupabaseVectorStore.py @@ -7,7 +7,7 @@ from supabase.client import Client, create_client from langflow.custom import CustomComponent from langflow.field_typing import Embeddings -from langflow.schema.schema import Record +from langflow.schema import Record class SupabaseComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Upstash.py b/src/backend/base/langflow/components/vectorstores/Upstash.py index c066d7f44..2695abecc 100644 --- a/src/backend/base/langflow/components/vectorstores/Upstash.py +++ b/src/backend/base/langflow/components/vectorstores/Upstash.py @@ -6,7 +6,7 @@ from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class UpstashVectorStoreComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Vectara.py b/src/backend/base/langflow/components/vectorstores/Vectara.py index 247614345..5a51b5a1b 100644 --- a/src/backend/base/langflow/components/vectorstores/Vectara.py +++ b/src/backend/base/langflow/components/vectorstores/Vectara.py @@ -9,7 +9,7 @@ from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent from langflow.field_typing import BaseRetriever -from langflow.schema.schema import Record +from langflow.schema import Record class VectaraComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index e1a802000..fafa2f390 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -8,7 +8,7 @@ from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class WeaviateVectorStoreComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/pgvector.py b/src/backend/base/langflow/components/vectorstores/pgvector.py index 75c833ded..3ea7b6eb6 100644 --- a/src/backend/base/langflow/components/vectorstores/pgvector.py +++ b/src/backend/base/langflow/components/vectorstores/pgvector.py @@ -6,7 +6,7 @@ from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore from langflow.custom import CustomComponent -from langflow.schema.schema import Record +from langflow.schema import Record class PGVectorComponent(CustomComponent): diff --git a/src/backend/base/langflow/custom/custom_component/custom_component.py b/src/backend/base/langflow/custom/custom_component/custom_component.py index aeac9cae6..5c1da081b 100644 --- a/src/backend/base/langflow/custom/custom_component/custom_component.py +++ b/src/backend/base/langflow/custom/custom_component/custom_component.py @@ -7,6 +7,7 @@ import yaml from cachetools import TTLCache, cachedmethod from langchain_core.documents import Document from pydantic import BaseModel + from langflow.custom.code_parser.utils import ( extract_inner_type_from_generic_alias, extract_union_types_from_generic_alias, @@ -125,8 +126,11 @@ class CustomComponent(Component): @staticmethod def resolve_path(path: str) -> str: """Resolves the path to an absolute path.""" + if not path: + return path path_object = Path(path) - if path_object.parts[0] == "~": + + if path_object.parts and path_object.parts[0] == "~": path_object = path_object.expanduser() elif path_object.is_relative_to("."): path_object = path_object.resolve() @@ -378,13 +382,14 @@ class CustomComponent(Component): The variable for the current user with the specified name. """ - def get_variable(name: str): + def get_variable(name: str, field: str): if hasattr(self, "_user_id") and not self._user_id: raise ValueError(f"User id is not set for {self.__class__.__name__}") variable_service = get_variable_service() # Get service instance # Retrieve and decrypt the variable by name for the current user with session_scope() as session: - return variable_service.get_variable(user_id=self._user_id or "", name=name, session=session) + user_id = self._user_id or "" + return variable_service.get_variable(user_id=user_id, name=name, field=field, session=session) return get_variable diff --git a/src/backend/base/langflow/field_typing/__init__.py b/src/backend/base/langflow/field_typing/__init__.py index 15ce03693..67dfec050 100644 --- a/src/backend/base/langflow/field_typing/__init__.py +++ b/src/backend/base/langflow/field_typing/__init__.py @@ -19,13 +19,13 @@ from .constants import ( Embeddings, NestedDict, Object, - Prompt, PromptTemplate, Text, TextSplitter, Tool, VectorStore, ) +from .prompt import Prompt from .range_spec import RangeSpec diff --git a/src/backend/base/langflow/field_typing/constants.py b/src/backend/base/langflow/field_typing/constants.py index d73257c14..807f9a77e 100644 --- a/src/backend/base/langflow/field_typing/constants.py +++ b/src/backend/base/langflow/field_typing/constants.py @@ -6,7 +6,7 @@ from langchain.memory.chat_memory import BaseChatMemory from langchain_core.document_loaders import BaseLoader from langchain_core.documents import Document from langchain_core.embeddings import Embeddings -from langchain_core.language_models import BaseLLM, BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel, BaseLLM from langchain_core.memory import BaseMemory from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate, PromptTemplate @@ -15,6 +15,8 @@ from langchain_core.tools import Tool from langchain_core.vectorstores import VectorStore from langchain_text_splitters import TextSplitter +from langflow.field_typing.prompt import Prompt + # Type alias for more complex dicts NestedDict = Dict[str, Union[str, Dict]] @@ -27,10 +29,6 @@ class Data: pass -class Prompt: - pass - - class Code: pass diff --git a/src/backend/base/langflow/field_typing/prompt.py b/src/backend/base/langflow/field_typing/prompt.py new file mode 100644 index 000000000..029261ac7 --- /dev/null +++ b/src/backend/base/langflow/field_typing/prompt.py @@ -0,0 +1,42 @@ +from langchain_core.load import load +from langchain_core.messages import HumanMessage +from langchain_core.prompts import BaseChatPromptTemplate, ChatPromptTemplate, PromptTemplate + +from langflow.base.prompts.utils import dict_values_to_string +from langflow.schema.message import Message +from langflow.schema.record import Record + + +class Prompt(Record): + def load_lc_prompt(self): + if "prompt" not in self: + raise ValueError("Prompt is required.") + return load(self.prompt) + + @classmethod + def from_lc_prompt( + cls, + prompt: BaseChatPromptTemplate, + ): + prompt_json = prompt.to_json() + return cls(prompt=prompt_json) + + def format_text(self): + prompt_template = PromptTemplate.from_template(self.template) + variables_with_str_values = dict_values_to_string(self.variables) + formatted_prompt = prompt_template.format(**variables_with_str_values) + self.text = formatted_prompt + return formatted_prompt + + @classmethod + async def from_template_and_variables(cls, template: str, variables: dict): + instance = cls(template=template, variables=variables) + contents = [{"type": "text", "text": instance.format_text()}] + # Get all Message instances from the kwargs + for value in variables.values(): + if isinstance(value, Message): + content_dicts = await value.get_file_content_dicts() + contents.extend(content_dicts) + prompt_template = ChatPromptTemplate.from_messages([HumanMessage(content=contents)]) + instance.prompt = prompt_template.to_json() + return instance diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index f4e71bd7c..56b5e8bfe 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -710,6 +710,7 @@ class Graph: chat_service: ChatService, vertex_id: str, inputs_dict: Optional[Dict[str, str]] = None, + files: Optional[list[str]] = None, user_id: Optional[str] = None, fallback_to_env_vars: bool = False, ): @@ -737,7 +738,9 @@ class Graph: # Check the cache for the vertex cached_result = await chat_service.get_cache(key=vertex.id) if isinstance(cached_result, CacheMiss): - await vertex.build(user_id=user_id, inputs=inputs_dict, fallback_to_env_vars=fallback_to_env_vars) + await vertex.build( + user_id=user_id, inputs=inputs_dict, fallback_to_env_vars=fallback_to_env_vars, files=files + ) await chat_service.set_cache(key=vertex.id, data=vertex) else: cached_vertex = cached_result["result"] @@ -751,7 +754,10 @@ class Graph: vertex.result.used_frozen_result = True else: - await vertex.build(user_id=user_id, inputs=inputs_dict, fallback_to_env_vars=fallback_to_env_vars) + await vertex.build( + user_id=user_id, inputs=inputs_dict, fallback_to_env_vars=fallback_to_env_vars, files=files + ) + await chat_service.set_cache(key=vertex.id, data=vertex) if vertex.result is not None: params = f"{vertex._built_object_repr()}{params}" @@ -764,11 +770,13 @@ class Graph: next_runnable_vertices, top_level_vertices = await self.get_next_and_top_level_vertices( lock, set_cache_coro, vertex ) - log_transaction(vertex, status="success") + flow_id = self.flow_id + log_transaction(flow_id, vertex, status="success") return next_runnable_vertices, top_level_vertices, result_dict, params, valid, artifacts, vertex except Exception as exc: logger.exception(f"Error building vertex: {exc}") - log_transaction(vertex, status="failure", error=str(exc)) + flow_id = self.flow_id + log_transaction(flow_id, vertex, status="failure", error=str(exc)) raise exc async def get_next_and_top_level_vertices( diff --git a/src/backend/base/langflow/graph/schema.py b/src/backend/base/langflow/graph/schema.py index 60e7ab590..766575364 100644 --- a/src/backend/base/langflow/graph/schema.py +++ b/src/backend/base/langflow/graph/schema.py @@ -1,15 +1,17 @@ from enum import Enum from typing import Any, List, Optional -from pydantic import BaseModel, Field, field_serializer +from pydantic import BaseModel, Field, field_serializer, model_validator from langflow.graph.utils import serialize_field +from langflow.schema.schema import Log, StreamURL from langflow.utils.schemas import ChatOutputResponse, ContainsEnumMeta class ResultData(BaseModel): results: Optional[Any] = Field(default_factory=dict) artifacts: Optional[Any] = Field(default_factory=dict) + logs: Optional[List[dict]] = Field(default_factory=list) messages: Optional[list[ChatOutputResponse]] = Field(default_factory=list) timedelta: Optional[float] = None duration: Optional[str] = None @@ -23,6 +25,24 @@ class ResultData(BaseModel): return {key: serialize_field(val) for key, val in value.items()} return serialize_field(value) + @model_validator(mode="before") + @classmethod + def validate_model(cls, values): + if not values.get("logs") and values.get("artifacts"): + # Build the log from the artifacts + message = values["artifacts"] + + # ! Temporary fix + if not isinstance(message, dict): + message = {"message": message} + + if "stream_url" in message and "type" in message: + stream_url = StreamURL(location=message["stream_url"]) + values["logs"] = [Log(message=stream_url, type=message["type"])] + elif "type" in message: + values["logs"] = [Log(message=message, type=message["type"])] + return values + class InterfaceComponentTypes(str, Enum, metaclass=ContainsEnumMeta): # ChatInput and ChatOutput are the only ones that are diff --git a/src/backend/base/langflow/graph/utils.py b/src/backend/base/langflow/graph/utils.py index 83e2177b1..06b7ca90a 100644 --- a/src/backend/base/langflow/graph/utils.py +++ b/src/backend/base/langflow/graph/utils.py @@ -1,9 +1,12 @@ -from typing import Any, Union +from enum import Enum +from typing import Any, Generator, Union from langchain_core.documents import Document from pydantic import BaseModel from langflow.interface.utils import extract_input_variables_from_prompt +from langflow.schema import Record +from langflow.schema.message import Message class UnbuiltObject: @@ -14,6 +17,16 @@ class UnbuiltResult: pass +class ArtifactType(str, Enum): + TEXT = "text" + RECORD = "record" + OBJECT = "object" + ARRAY = "array" + STREAM = "stream" + UNKNOWN = "unknown" + MESSAGE = "message" + + def validate_prompt(prompt: str): """Validate prompt.""" if extract_input_variables_from_prompt(prompt): @@ -50,3 +63,38 @@ def serialize_field(value): elif isinstance(value, str): return {"result": value} return value + + +def get_artifact_type(custom_component, build_result) -> str: + result = ArtifactType.UNKNOWN + value = custom_component.repr_value + match value: + case Record(): + result = ArtifactType.RECORD + + case str(): + result = ArtifactType.TEXT + + case dict(): + result = ArtifactType.OBJECT + + case list(): + result = ArtifactType.ARRAY + + case Message(): + result = ArtifactType.MESSAGE + + if result == ArtifactType.UNKNOWN: + if isinstance(build_result, Generator): + result = ArtifactType.STREAM + elif isinstance(value, Message) and isinstance(value.text, Generator): + result = ArtifactType.STREAM + + return result.value + + +def post_process_raw(raw, artifact_type: str): + if artifact_type == ArtifactType.STREAM.value: + raw = "" + + return raw diff --git a/src/backend/base/langflow/graph/vertex/base.py b/src/backend/base/langflow/graph/vertex/base.py index 963ae2115..86cf9cd4e 100644 --- a/src/backend/base/langflow/graph/vertex/base.py +++ b/src/backend/base/langflow/graph/vertex/base.py @@ -4,17 +4,17 @@ import inspect import os import types from enum import Enum -from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, Iterator, List, Optional +from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, Iterator, List, Mapping, Optional from loguru import logger from langflow.graph.schema import INPUT_COMPONENTS, OUTPUT_COMPONENTS, InterfaceComponentTypes, ResultData -from langflow.graph.utils import UnbuiltObject, UnbuiltResult -from langflow.graph.vertex.utils import log_transaction +from langflow.graph.utils import ArtifactType, UnbuiltObject, UnbuiltResult from langflow.interface.initialize import loading from langflow.interface.listing import lazy_load_dict from langflow.schema.schema import INPUT_FIELD_NAME from langflow.services.deps import get_storage_service +from langflow.services.monitor.utils import log_transaction from langflow.utils.constants import DIRECT_TYPES from langflow.utils.schemas import ChatOutputResponse from langflow.utils.util import sync_to_async, unescape_string @@ -63,6 +63,8 @@ class Vertex: self._built_result = None self._built = False self.artifacts: Dict[str, Any] = {} + self.artifacts_raw: Any = None + self.artifacts_type: Optional[str] = None self.steps: List[Callable] = [self._build] self.steps_ran: List[Callable] = [] self.task_id: Optional[str] = None @@ -371,7 +373,7 @@ class Vertex: self.load_from_db_fields = load_from_db_fields self._raw_params = params.copy() - def update_raw_params(self, new_params: Dict[str, str], overwrite: bool = False): + def update_raw_params(self, new_params: Mapping[str, str | list[str]], overwrite: bool = False): """ Update the raw parameters of the vertex with the given new parameters. @@ -422,11 +424,14 @@ class Vertex: try: messages = [ ChatOutputResponse( - message=artifacts["message"], + message=artifacts["text"], sender=artifacts.get("sender"), sender_name=artifacts.get("sender_name"), session_id=artifacts.get("session_id"), + stream_url=artifacts.get("stream_url"), + files=[{"path": file} if isinstance(file, str) else file for file in artifacts.get("files", [])], component_id=self.id, + type=self.artifacts_type, ).model_dump(exclude_none=True) ] except KeyError: @@ -439,12 +444,11 @@ class Vertex: # We need to set the artifacts to pass information # to the frontend self.set_artifacts() - artifacts = self.artifacts + artifacts = self.artifacts_raw if isinstance(artifacts, dict): messages = self.extract_messages_from_artifacts(artifacts) else: messages = [] - result_dict = ResultData( results=result_dict, artifacts=artifacts, @@ -525,12 +529,13 @@ class Vertex: Returns: The built result if use_result is True, else the built object. """ + flow_id = self.graph.flow_id if not self._built: - log_transaction(source=self, target=requester, flow_id=self.graph.flow_id, status="error") + log_transaction(flow_id, vertex=self, target=requester, status="error") raise ValueError(f"Component {self.display_name} has not been built yet") result = self._built_result if self.use_result else self._built_object - log_transaction(source=self, target=requester, flow_id=self.graph.flow_id, status="success") + log_transaction(flow_id, vertex=self, target=requester, status="success") return result async def _build_vertex_and_update_params(self, key, vertex: "Vertex"): @@ -624,6 +629,8 @@ class Vertex: self._built_object, self.artifacts = result elif len(result) == 3: self._custom_component, self._built_object, self.artifacts = result + self.artifacts_raw = self.artifacts.get("raw", None) + self.artifacts_type = self.artifacts.get("type", None) or ArtifactType.UNKNOWN.value else: self._built_object = result @@ -664,6 +671,7 @@ class Vertex: self, user_id=None, inputs: Optional[Dict[str, Any]] = None, + files: Optional[list[str]] = None, requester: Optional["Vertex"] = None, **kwargs, ) -> Any: @@ -681,9 +689,14 @@ class Vertex: return await self.get_requester_result(requester) self._reset() - if self._is_chat_input() and inputs: - inputs = {"input_value": inputs.get(INPUT_FIELD_NAME, "")} - self.update_raw_params(inputs, overwrite=True) + if self._is_chat_input() and (inputs or files): + chat_input = {} + if inputs: + chat_input.update({"input_value": inputs.get(INPUT_FIELD_NAME, "")}) + if files: + chat_input.update({"files": files}) + + self.update_raw_params(chat_input, overwrite=True) # Run steps for step in self.steps: diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index 590c38c24..ba91a2597 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -2,13 +2,14 @@ import json from typing import AsyncIterator, Dict, Iterator, List import yaml -from langchain_core.messages import AIMessage +from langchain_core.messages import AIMessage, AIMessageChunk from loguru import logger from langflow.graph.schema import CHAT_COMPONENTS, RECORDS_COMPONENTS, InterfaceComponentTypes -from langflow.graph.utils import UnbuiltObject, serialize_field +from langflow.graph.utils import ArtifactType, UnbuiltObject, serialize_field from langflow.graph.vertex.base import Vertex from langflow.schema import Record +from langflow.schema.message import Message from langflow.schema.schema import INPUT_FIELD_NAME from langflow.services.monitor.utils import log_vertex_build from langflow.utils.schemas import ChatOutputResponse, RecordOutputResponse @@ -83,10 +84,11 @@ class InterfaceVertex(Vertex): sender = self.params.get("sender", None) sender_name = self.params.get("sender_name", None) message = self.params.get(INPUT_FIELD_NAME, None) + files = [{"path": file} if isinstance(file, str) else file for file in self.params.get("files", [])] if isinstance(message, str): message = unescape_string(message) stream_url = None - if isinstance(self._built_object, AIMessage): + if isinstance(self._built_object, (AIMessage, AIMessageChunk)): artifacts = ChatOutputResponse.from_message( self._built_object, sender=sender, @@ -97,23 +99,27 @@ class InterfaceVertex(Vertex): # Turn the dict into a pleasing to # read JSON inside a code block message = dict_to_codeblock(self._built_object) - elif isinstance(self._built_object, Record): - message = self._built_object.text - elif isinstance(message, (AsyncIterator, Iterator)): - stream_url = self.build_stream_url() - message = "" + elif isinstance(self._built_object, Message): + if isinstance(message, (AsyncIterator, Iterator)): + stream_url = self.build_stream_url() + message = "" + self._built_object.text = message + else: + message = self._built_object.text elif not isinstance(self._built_object, str): message = str(self._built_object) # if the message is a generator or iterator # it means that it is a stream of messages else: message = self._built_object - + artifact_type = ArtifactType.STREAM if stream_url is not None else ArtifactType.OBJECT artifacts = ChatOutputResponse( message=message, sender=sender, sender_name=sender_name, stream_url=stream_url, + files=files, + type=artifact_type, ) self.will_stream = stream_url is not None @@ -195,6 +201,8 @@ class InterfaceVertex(Vertex): message=complete_message, sender=self.params.get("sender", ""), sender_name=self.params.get("sender_name", ""), + files=[{"path": file} if isinstance(file, str) else file for file in self.params.get("files", [])], + type=ArtifactType.OBJECT.value, ).model_dump() self.params[INPUT_FIELD_NAME] = complete_message self._built_object = Record(text=complete_message, data=self.artifacts) diff --git a/src/backend/base/langflow/graph/vertex/utils.py b/src/backend/base/langflow/graph/vertex/utils.py index 59a1c1949..0f69e4b2d 100644 --- a/src/backend/base/langflow/graph/vertex/utils.py +++ b/src/backend/base/langflow/graph/vertex/utils.py @@ -1,9 +1,5 @@ from typing import TYPE_CHECKING -from loguru import logger - -from langflow.services.deps import get_monitor_service - if TYPE_CHECKING: from langflow.graph.vertex.base import Vertex @@ -21,34 +17,3 @@ def build_clean_params(target: "Vertex") -> dict: if isinstance(value, list): params[key] = [item for item in value if isinstance(item, (str, int, bool, float, list, dict))] return params - - -def log_transaction(source: "Vertex", target: "Vertex", flow_id, status, error=None): - """ - Logs a transaction between two vertices. - - Args: - source (Vertex): The source vertex of the transaction. - target (Vertex): The target vertex of the transaction. - status: The status of the transaction. - error (Optional): Any error associated with the transaction. - - Raises: - Exception: If there is an error while logging the transaction. - - """ - try: - monitor_service = get_monitor_service() - clean_params = build_clean_params(target) - data = { - "source": source.vertex_type, - "target": target.vertex_type, - "target_args": clean_params, - "timestamp": monitor_service.get_timestamp(), - "status": status, - "error": error, - "flow_id": flow_id, - } - monitor_service.add_row(table_name="transactions", data=data) - except Exception as e: - logger.error(f"Error logging transaction: {e}") diff --git a/src/backend/base/langflow/helpers/__init__.py b/src/backend/base/langflow/helpers/__init__.py index adfa72088..38b460af2 100644 --- a/src/backend/base/langflow/helpers/__init__.py +++ b/src/backend/base/langflow/helpers/__init__.py @@ -1,3 +1,3 @@ -from .record import docs_to_records, records_to_text +from .record import docs_to_records, records_to_text, messages_to_text -__all__ = ["docs_to_records", "records_to_text"] +__all__ = ["docs_to_records", "records_to_text", "messages_to_text"] diff --git a/src/backend/base/langflow/helpers/flow.py b/src/backend/base/langflow/helpers/flow.py index 7bdc510c6..61674942a 100644 --- a/src/backend/base/langflow/helpers/flow.py +++ b/src/backend/base/langflow/helpers/flow.py @@ -6,7 +6,8 @@ from pydantic.v1 import BaseModel, Field, create_model from sqlmodel import Session, select from langflow.graph.schema import RunOutputs -from langflow.schema.schema import INPUT_FIELD_NAME, Record +from langflow.schema import Record +from langflow.schema.schema import INPUT_FIELD_NAME from langflow.services.database.models.flow import Flow from langflow.services.deps import get_session, get_settings_service, session_scope @@ -259,3 +260,24 @@ def get_flow_by_id_or_endpoint_name( raise HTTPException(status_code=404, detail=f"Flow identifier {flow_id_or_name} not found") return flow + + +def generate_unique_flow_name(flow_name, user_id, session): + original_name = flow_name + n = 1 + while True: + # Check if a flow with the given name exists + existing_flow = session.exec( + select(Flow).where( + Flow.name == flow_name, + Flow.user_id == user_id, + ) + ).first() + + # If no flow with the given name exists, return the name + if not existing_flow: + return flow_name + + # If a flow with the name already exists, append (n) to the name and increment n + flow_name = f"{original_name} ({n})" + n += 1 diff --git a/src/backend/base/langflow/helpers/folders.py b/src/backend/base/langflow/helpers/folders.py new file mode 100644 index 000000000..c3d7567b5 --- /dev/null +++ b/src/backend/base/langflow/helpers/folders.py @@ -0,0 +1,23 @@ +from langflow.services.database.models.folder.model import Folder +from sqlalchemy import select + + +def generate_unique_folder_name(folder_name, user_id, session): + original_name = folder_name + n = 1 + while True: + # Check if a folder with the given name exists + existing_folder = session.exec( + select(Folder).where( + Folder.name == folder_name, + Folder.user_id == user_id, + ) + ).first() + + # If no folder with the given name exists, return the name + if not existing_folder: + return folder_name + + # If a folder with the name already exists, append (n) to the name and increment n + folder_name = f"{original_name} ({n})" + n += 1 diff --git a/src/backend/base/langflow/helpers/record.py b/src/backend/base/langflow/helpers/record.py index 7c13a9ad4..88d0bcd13 100644 --- a/src/backend/base/langflow/helpers/record.py +++ b/src/backend/base/langflow/helpers/record.py @@ -1,7 +1,9 @@ from typing import Union + from langchain_core.documents import Document from langflow.schema import Record +from langflow.schema.message import Message def docs_to_records(documents: list[Document]) -> list[Record]: @@ -27,7 +29,7 @@ def records_to_text(template: str, records: Union[Record, list[Record]]) -> str: Returns: list[str]: The converted list of texts. """ - if isinstance(records, Record): + if isinstance(records, (Record)): records = [records] # Check if there are any format strings in the template _records = [] @@ -39,3 +41,27 @@ def records_to_text(template: str, records: Union[Record, list[Record]]) -> str: formated_records = [template.format(data=record.data, **record.data) for record in _records] return "\n".join(formated_records) + + +def messages_to_text(template: str, messages: Union[Message, list[Message]]) -> str: + """ + Converts a list of Messages to a list of texts. + + Args: + messages (list[Message]): The list of Messages to convert. + + Returns: + list[str]: The converted list of texts. + """ + if isinstance(messages, (Message)): + messages = [messages] + # Check if there are any format strings in the template + _messages = [] + for message in messages: + # If it is not a message, create one with the key "text" + if not isinstance(message, Message): + raise ValueError("All elements in the list must be of type Message.") + _messages.append(message) + + formated_messages = [template.format(data=message.model_dump(), **message.model_dump()) for message in _messages] + return "\n".join(formated_messages) diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-01.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-01.svg new file mode 100644 index 000000000..62f3c1d27 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-01.svg @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.svg new file mode 100644 index 000000000..6a1e32abc --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.svg new file mode 100644 index 000000000..df4676205 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.svg @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.svg new file mode 100644 index 000000000..bd4dcdc54 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.svg @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.svg new file mode 100644 index 000000000..22fdcd454 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.svg new file mode 100644 index 000000000..9d45fb848 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.svg @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.svg new file mode 100644 index 000000000..d9800b2c5 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.svg @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.svg new file mode 100644 index 000000000..58e755d1b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.svg new file mode 100644 index 000000000..a498bfb52 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.svg @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.svg new file mode 100644 index 000000000..93ced759e --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.svg new file mode 100644 index 000000000..578c2444b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.svg new file mode 100644 index 000000000..373031e99 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.svg new file mode 100644 index 000000000..0a0523ddc --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.svg new file mode 100644 index 000000000..5c0672f70 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.svg new file mode 100644 index 000000000..7c6159c5b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.svg new file mode 100644 index 000000000..96389676f --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.svg @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.svg new file mode 100644 index 000000000..dc8aa54d5 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.svg new file mode 100644 index 000000000..33daef83b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.svg @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.svg new file mode 100644 index 000000000..f3a36ec3a --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.svg new file mode 100644 index 000000000..a53a56aa2 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.svg new file mode 100644 index 000000000..2cb2fcb8b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.svg new file mode 100644 index 000000000..9c2923e21 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.svg @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.svg new file mode 100644 index 000000000..111f30e4a --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.svg new file mode 100644 index 000000000..fd3b0edea --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.svg new file mode 100644 index 000000000..f5df7a6b9 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.svg new file mode 100644 index 000000000..5d2d1d26b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.svg @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.svg new file mode 100644 index 000000000..805d92ad4 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.svg new file mode 100644 index 000000000..6c5267009 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.svg new file mode 100644 index 000000000..812919cbb --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.svg @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.svg new file mode 100644 index 000000000..c228becdd --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.svg new file mode 100644 index 000000000..24467602b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.svg new file mode 100644 index 000000000..ffe3ec4f4 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.svg new file mode 100644 index 000000000..48ab569d0 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.svg new file mode 100644 index 000000000..4aa9f92a8 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.svg new file mode 100644 index 000000000..4cb7cba08 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.svg new file mode 100644 index 000000000..927475066 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.svg new file mode 100644 index 000000000..5edf770b1 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.svg new file mode 100644 index 000000000..29733814e --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.svg @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.svg new file mode 100644 index 000000000..07ee18224 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.svg new file mode 100644 index 000000000..9ab2fd502 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.svg new file mode 100644 index 000000000..99453cead --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.svg new file mode 100644 index 000000000..7e65d9d2a --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.svg new file mode 100644 index 000000000..add07c2fa --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.svg new file mode 100644 index 000000000..d069c007f --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.svg new file mode 100644 index 000000000..8ca1898df --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.svg new file mode 100644 index 000000000..1da4dd57e --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.svg @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.svg new file mode 100644 index 000000000..f3cadd3f0 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.svg new file mode 100644 index 000000000..72d24edf4 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.svg @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.svg new file mode 100644 index 000000000..31976afbc --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.svg new file mode 100644 index 000000000..8ca26c7ad --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.svg new file mode 100644 index 000000000..70c5f9af7 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.svg new file mode 100644 index 000000000..0b06acf10 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.svg new file mode 100644 index 000000000..efe31a6ae --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.svg b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.svg new file mode 100644 index 000000000..6be7092b0 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.svg new file mode 100644 index 000000000..a897a78b0 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.svg new file mode 100644 index 000000000..2b3d75526 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.svg new file mode 100644 index 000000000..d9de6b169 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.svg new file mode 100644 index 000000000..9fdb0bcd5 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.svg new file mode 100644 index 000000000..4cb73ec51 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.svg new file mode 100644 index 000000000..243c6a47d --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.svg new file mode 100644 index 000000000..57b370a73 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.svg new file mode 100644 index 000000000..9b9b8c929 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.svg new file mode 100644 index 000000000..c1f232eab --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.svg new file mode 100644 index 000000000..de37ab082 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.svg new file mode 100644 index 000000000..b3a217c91 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.svg new file mode 100644 index 000000000..57bb86169 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.svg new file mode 100644 index 000000000..400ecd776 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.svg new file mode 100644 index 000000000..fd894241b --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.svg new file mode 100644 index 000000000..003e0ef03 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.svg new file mode 100644 index 000000000..d1164b166 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.svg new file mode 100644 index 000000000..03a589409 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.svg new file mode 100644 index 000000000..841d226f3 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.svg new file mode 100644 index 000000000..7a069e53e --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.svg new file mode 100644 index 000000000..c69214ebd --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.svg new file mode 100644 index 000000000..65e523f31 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.svg new file mode 100644 index 000000000..912c33f73 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.svg new file mode 100644 index 000000000..1f0bfb9c1 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.svg new file mode 100644 index 000000000..c9c582d8e --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.svg b/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.svg new file mode 100644 index 000000000..13d034c47 --- /dev/null +++ b/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/backend/base/langflow/initial_setup/setup.py b/src/backend/base/langflow/initial_setup/setup.py index 83408d8b9..56739cd5c 100644 --- a/src/backend/base/langflow/initial_setup/setup.py +++ b/src/backend/base/langflow/initial_setup/setup.py @@ -1,5 +1,7 @@ +import json import logging import os +import shutil from collections import defaultdict from copy import deepcopy from datetime import datetime, timezone @@ -11,17 +13,14 @@ from emoji import demojize, purely_emoji # type: ignore from loguru import logger from sqlmodel import select -from langflow.base.constants import FIELD_FORMAT_ATTRIBUTES, NODE_FORMAT_ATTRIBUTES +from langflow.base.constants import FIELD_FORMAT_ATTRIBUTES, NODE_FORMAT_ATTRIBUTES, ORJSON_OPTIONS from langflow.interface.types import get_all_components from langflow.services.auth.utils import create_super_user from langflow.services.database.models.flow.model import Flow, FlowCreate from langflow.services.database.models.folder.model import Folder, FolderCreate -from langflow.services.database.models.user.crud import get_user_by_username -from langflow.services.deps import get_settings_service, session_scope - from langflow.services.database.models.folder.utils import create_default_folder_if_it_doesnt_exist -from langflow.services.deps import get_variable_service - +from langflow.services.database.models.user.crud import get_user_by_username +from langflow.services.deps import get_settings_service, get_storage_service, get_variable_service, session_scope STARTER_FOLDER_NAME = "Starter Projects" STARTER_FOLDER_DESCRIPTION = "Starter projects to help you get started in Langflow." @@ -74,10 +73,84 @@ def update_projects_components_with_latest_component_versions(project_data, all_ } ) node_data["template"][field_name][attr] = field_dict[attr] + # Remove fields that are not in the latest template + if node_data.get("display_name") != "Prompt": + for field_name in list(node_data["template"].keys()): + if field_name not in latest_template: + node_data["template"].pop(field_name) log_node_changes(node_changes_log) return project_data_copy +def update_edges_with_latest_component_versions(project_data): + edge_changes_log = defaultdict(list) + project_data_copy = deepcopy(project_data) + for edge in project_data_copy.get("edges", []): + source_handle = edge.get("data").get("sourceHandle") + target_handle = edge.get("data").get("targetHandle") + # Now find the source and target nodes in the nodes list + source_node = next( + (node for node in project_data.get("nodes", []) if node.get("id") == edge.get("source")), None + ) + target_node = next( + (node for node in project_data.get("nodes", []) if node.get("id") == edge.get("target")), None + ) + if source_node and target_node: + source_node_data = source_node.get("data").get("node") + target_node_data = target_node.get("data").get("node") + new_base_classes = source_node_data.get("base_classes") + if source_handle["baseClasses"] != new_base_classes: + edge_changes_log[source_node_data["display_name"]].append( + { + "attr": "baseClasses", + "old_value": source_handle["baseClasses"], + "new_value": new_base_classes, + } + ) + source_handle["baseClasses"] = new_base_classes + + field_name = target_handle.get("fieldName") + if field_name in target_node_data.get("template"): + if target_handle["inputTypes"] != target_node_data.get("template").get(field_name).get("input_types"): + edge_changes_log[target_node_data["display_name"]].append( + { + "attr": "inputTypes", + "old_value": target_handle["inputTypes"], + "new_value": target_node_data.get("template").get(field_name).get("input_types"), + } + ) + target_handle["inputTypes"] = target_node_data.get("template").get(field_name).get("input_types") + escaped_source_handle = escape_json_dump(source_handle) + escaped_target_handle = escape_json_dump(target_handle) + if edge["sourceHandle"] != escaped_source_handle: + edge_changes_log[source_node_data["display_name"]].append( + { + "attr": "sourceHandle", + "old_value": edge["sourceHandle"], + "new_value": escaped_source_handle, + } + ) + edge["sourceHandle"] = escaped_source_handle + if edge["targetHandle"] != escaped_target_handle: + edge_changes_log[target_node_data["display_name"]].append( + { + "attr": "targetHandle", + "old_value": edge["targetHandle"], + "new_value": escaped_target_handle, + } + ) + edge["targetHandle"] = escaped_target_handle + + else: + logger.error(f"Source or target node not found for edge: {edge}") + log_node_changes(edge_changes_log) + return project_data_copy + + +def escape_json_dump(edge_dict): + return json.dumps(edge_dict).replace('"', "œ") + + def log_node_changes(node_changes_log): # The idea here is to log the changes that were made to the nodes in debug # Something like: @@ -104,6 +177,25 @@ def load_starter_projects() -> list[tuple[Path, dict]]: return starter_projects +def copy_profile_pictures(): + config_dir = get_storage_service().settings_service.settings.config_dir + origin = Path(__file__).parent / "profile_pictures" + target = Path(config_dir) / "profile_pictures" + + if not os.path.exists(origin): + raise ValueError(f"The source folder '{origin}' does not exist.") + + if not os.path.exists(target): + os.makedirs(target) + + try: + shutil.copytree(origin, target, dirs_exist_ok=True) + logger.debug(f"Folder copied from '{origin}' to '{target}'") + + except Exception as e: + logger.error(f"Error copying the folder: {e}") + + def get_project_data(project): project_name = project.get("name") project_description = project.get("description") @@ -135,7 +227,7 @@ def get_project_data(project): def update_project_file(project_path, project, updated_project_data): project["data"] = updated_project_data with open(project_path, "w", encoding="utf-8") as f: - f.write(orjson.dumps(project, option=orjson.OPT_INDENT_2).decode()) + f.write(orjson.dumps(project, option=ORJSON_OPTIONS).decode()) logger.info(f"Updated starter project {project['name']} file") @@ -286,6 +378,7 @@ def create_or_update_starter_projects(): new_folder = create_starter_folder(session) starter_projects = load_starter_projects() delete_start_projects(session, new_folder.id) + copy_profile_pictures() for project_path, project in starter_projects: ( project_name, @@ -299,6 +392,7 @@ def create_or_update_starter_projects(): updated_project_data = update_projects_components_with_latest_component_versions( project_data, all_types_dict ) + updated_project_data = update_edges_with_latest_component_versions(updated_project_data) if updated_project_data != project_data: project_data = updated_project_data # We also need to update the project data in the file diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting (Hello, world!).json b/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting (Hello, world!).json index 38e01111b..2e122c63c 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting (Hello, world!).json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting (Hello, world!).json @@ -1,353 +1,213 @@ { - "id": "c091a57f-43a7-4a5e-b352-035ae8d8379c", "data": { + "edges": [ + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "Text", "str"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-k39HS" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-njtka", + "inputTypes": ["Text"], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-k39HS{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-k39HSœ}-ChatOutput-njtka{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-njtkaœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-k39HS", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-k39HSœ}", + "style": { + "stroke": "#555" + }, + "target": "ChatOutput-njtka", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-njtkaœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "str", "Text"], + "dataType": "Prompt", + "id": "Prompt-uxBqP" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-k39HS", + "inputTypes": ["Text", "Record", "Prompt"], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-uxBqP{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-uxBqPœ}-OpenAIModel-k39HS{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-k39HSœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-uxBqP", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-uxBqPœ}", + "style": { + "stroke": "#555" + }, + "target": "OpenAIModel-k39HS", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-k39HSœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "Record", "str", "Text"], + "dataType": "ChatInput", + "id": "ChatInput-P3fgL" + }, + "targetHandle": { + "fieldName": "user_input", + "id": "Prompt-uxBqP", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-ChatInput-P3fgL{œbaseClassesœ:[œobjectœ,œRecordœ,œstrœ,œTextœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-P3fgLœ}-Prompt-uxBqP{œfieldNameœ:œuser_inputœ,œidœ:œPrompt-uxBqPœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "ChatInput-P3fgL", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œRecordœ, œstrœ, œTextœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-P3fgLœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-uxBqP", + "targetHandle": "{œfieldNameœ: œuser_inputœ, œidœ: œPrompt-uxBqPœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { - "id": "Prompt-uxBqP", - "type": "genericNode", - "position": { - "x": 53.588791333410654, - "y": -107.07318910019967 - }, "data": { - "type": "Prompt", + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-uxBqP", "node": { + "base_classes": ["object", "str", "Text"], + "beta": false, + "custom_fields": { + "template": ["user_input"] + }, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, + "field_formatters": {}, + "field_order": [], + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], "template": { + "_type": "CustomComponent", "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", "advanced": true, "dynamic": true, + "fileTypes": [], + "file_path": "", "info": "", + "list": false, "load_from_db": false, - "title_case": false + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" }, "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Answer the user as if you were a pirate.\n\nUser: {user_input}\n\nAnswer: ", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", + "advanced": false, "display_name": "Template", - "advanced": false, - "input_types": ["Text"], "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "user_input": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", "fileTypes": [], "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", "password": false, - "name": "user_input", - "display_name": "user_input", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "Answer the user as if you were a pirate.\n\nUser: {user_input}\n\nAnswer: " + }, + "user_input": { "advanced": false, + "display_name": "user_input", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", "input_types": [ "Document", "BaseOutputParser", "Record", "Text" ], - "dynamic": false, - "info": "", + "list": false, "load_from_db": false, + "multiline": true, + "name": "user_input", + "password": false, + "placeholder": "", + "required": false, + "show": true, "title_case": false, - "type": "str" + "type": "str", + "value": "" } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, - "base_classes": ["object", "str", "Text"], - "name": "", - "display_name": "Prompt", - "documentation": "", - "custom_fields": { - "template": ["user_input"] - }, - "output_types": ["Text"], - "full_path": null, - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false, - "error": null + } }, - "id": "Prompt-uxBqP", - "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" + "type": "Prompt" }, - "selected": true, - "width": 384, - "height": 383, "dragging": false, + "height": 383, + "id": "Prompt-uxBqP", + "position": { + "x": 53.588791333410654, + "y": -107.07318910019967 + }, "positionAbsolute": { "x": 53.588791333410654, "y": -107.07318910019967 - } + }, + "selected": true, + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIModel-k39HS", - "type": "genericNode", - "position": { - "x": 634.8148772766217, - "y": 27.035057029045305 - }, "data": { - "type": "OpenAIModel", + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "id": "OpenAIModel-k39HS", "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-3.5-turbo", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": true, - "title_case": false, - "input_types": ["Text"], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 0.1, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", "base_classes": ["object", "Text", "str"], - "display_name": "OpenAI", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, "max_tokens": null, "model_kwargs": null, + "model_name": null, "openai_api_base": null, + "openai_api_key": null, "stream": null, - "system_message": null + "system_message": null, + "temperature": null }, - "output_types": ["Text"], + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "max_tokens", "model_kwargs", @@ -359,432 +219,513 @@ "system_message", "stream" ], - "beta": false + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-3.5-turbo" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": true + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } }, - "id": "OpenAIModel-k39HS", - "description": "Generates text using OpenAI LLMs.", - "display_name": "OpenAI" + "type": "OpenAIModel" }, - "selected": false, - "width": 384, + "dragging": false, "height": 563, + "id": "OpenAIModel-k39HS", + "position": { + "x": 634.8148772766217, + "y": 27.035057029045305 + }, "positionAbsolute": { "x": 634.8148772766217, "y": 27.035057029045305 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "ChatOutput-njtka", - "type": "genericNode", - "position": { - "x": 1193.250417197867, - "y": 71.88476890163852 - }, "data": { - "type": "ChatOutput", + "id": "ChatOutput-njtka", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "In case of Message being a Record, this template will be used to convert it to text.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "AI", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" + "base_classes": ["Record", "Text", "str", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null }, "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["Record", "Text", "str", "object"], "display_name": "Chat Output", "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null, - "record_template": null - }, - "output_types": ["Text", "Record"], "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "AI" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } }, - "id": "ChatOutput-njtka" + "type": "ChatOutput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 383, + "id": "ChatOutput-njtka", + "position": { + "x": 1193.250417197867, + "y": 71.88476890163852 + }, "positionAbsolute": { "x": 1193.250417197867, "y": 71.88476890163852 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { + "data": { + "id": "ChatInput-P3fgL", + "node": { + "base_classes": ["object", "Record", "str", "Text"], + "beta": false, + "custom_fields": { + "input_value": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Get chat inputs from the Playground.", + "display_name": "Chat Input", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "ChatInput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Text\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n files: Optional[list[str]] = None,\n session_id: Optional[str] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n files=files,\n session_id=session_id,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "hi" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatInput" + }, + "dragging": false, + "height": 375, "id": "ChatInput-P3fgL", - "type": "genericNode", "position": { "x": -495.2223093083827, "y": -232.56998443685862 }, - "data": { - "type": "ChatInput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Message\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n ) -> Union[Text, Record]:\n return super().build_no_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": [], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "value": "hi" - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Get chat inputs from the Playground.", - "icon": "ChatInput", - "base_classes": ["object", "Record", "str", "Text"], - "display_name": "Chat Input", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null - }, - "output_types": ["Text", "Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "ChatInput-P3fgL" - }, - "selected": false, - "width": 384, - "height": 375, "positionAbsolute": { "x": -495.2223093083827, "y": -232.56998443685862 }, - "dragging": false - } - ], - "edges": [ - { - "source": "OpenAIModel-k39HS", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-k39HSœ}", - "target": "ChatOutput-njtka", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-njtkaœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-njtka", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "Text", "str"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-k39HS" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-k39HS{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-k39HSœ}-ChatOutput-njtka{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-njtkaœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "Prompt-uxBqP", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-uxBqPœ}", - "target": "OpenAIModel-k39HS", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-k39HSœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-k39HS", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "str", "Text"], - "dataType": "Prompt", - "id": "Prompt-uxBqP" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-uxBqP{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-uxBqPœ}-OpenAIModel-k39HS{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-k39HSœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "ChatInput-P3fgL", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œRecordœ,œstrœ,œTextœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-P3fgLœ}", - "target": "Prompt-uxBqP", - "targetHandle": "{œfieldNameœ:œuser_inputœ,œidœ:œPrompt-uxBqPœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "user_input", - "id": "Prompt-uxBqP", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "Record", "str", "Text"], - "dataType": "ChatInput", - "id": "ChatInput-P3fgL" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-ChatInput-P3fgL{œbaseClassesœ:[œobjectœ,œRecordœ,œstrœ,œTextœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-P3fgLœ}-Prompt-uxBqP{œfieldNameœ:œuser_inputœ,œidœ:œPrompt-uxBqPœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -794,7 +735,8 @@ } }, "description": "This flow will get you experimenting with the basics of the UI, the Chat and the Prompt component. \n\nTry changing the Template in it to see how the model behaves. \nYou can change it to this and a Text Input into the `type_of_person` variable : \"Answer the user as if you were a pirate.\n\nUser: {user_input}\n\nAnswer: \" ", - "name": "Basic Prompting (Hello, World)", + "id": "c091a57f-43a7-4a5e-b352-035ae8d8379c", + "is_component": false, "last_tested_version": "1.0.0a4", - "is_component": false + "name": "Basic Prompting (Hello, World)" } diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writter.json b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writter.json index fcdef4056..e98859446 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writter.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writter.json @@ -1,657 +1,526 @@ { - "id": "6ad5559d-fb66-4fdc-8f98-96f4ac12799d", "data": { + "edges": [ + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["Record"], + "dataType": "URL", + "id": "URL-HYPkR" + }, + "targetHandle": { + "fieldName": "reference_2", + "id": "Prompt-Rse03", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-URL-HYPkR{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-HYPkRœ}-Prompt-Rse03{œfieldNameœ:œreference_2œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "URL-HYPkR", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œURLœ, œidœ: œURL-HYPkRœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-Rse03", + "targetHandle": "{œfieldNameœ: œreference_2œ, œidœ: œPrompt-Rse03œ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-gi29P" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-JPlxl", + "inputTypes": ["Text"], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-gi29P{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-gi29Pœ}-ChatOutput-JPlxl{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-JPlxlœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-gi29P", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-gi29Pœ}", + "style": { + "stroke": "#555" + }, + "target": "ChatOutput-JPlxl", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-JPlxlœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["Record"], + "dataType": "URL", + "id": "URL-2cX90" + }, + "targetHandle": { + "fieldName": "reference_1", + "id": "Prompt-Rse03", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-URL-2cX90{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-2cX90œ}-Prompt-Rse03{œfieldNameœ:œreference_1œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "URL-2cX90", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œURLœ, œidœ: œURL-2cX90œ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-Rse03", + "targetHandle": "{œfieldNameœ: œreference_1œ, œidœ: œPrompt-Rse03œ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "Text", "str"], + "dataType": "TextInput", + "id": "TextInput-og8Or" + }, + "targetHandle": { + "fieldName": "instructions", + "id": "Prompt-Rse03", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-TextInput-og8Or{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-og8Orœ}-Prompt-Rse03{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "TextInput-og8Or", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œTextInputœ, œidœ: œTextInput-og8Orœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-Rse03", + "targetHandle": "{œfieldNameœ: œinstructionsœ, œidœ: œPrompt-Rse03œ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "Text", "str"], + "dataType": "Prompt", + "id": "Prompt-Rse03" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-gi29P", + "inputTypes": ["Text", "Record", "Prompt"], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-Rse03{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-Rse03œ}-OpenAIModel-gi29P{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-gi29Pœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "Prompt-Rse03", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-Rse03œ}", + "style": { + "stroke": "#555" + }, + "target": "OpenAIModel-gi29P", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-gi29Pœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { - "id": "Prompt-Rse03", - "type": "genericNode", - "position": { - "x": 1331.381712783371, - "y": 535.0279854229713 - }, "data": { - "type": "Prompt", + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-Rse03", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Reference 1:\n\n{reference_1}\n\n---\n\nReference 2:\n\n{reference_2}\n\n---\n\n{instructions}\n\nBlog: \n\n\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "reference_1": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "reference_1", - "display_name": "reference_1", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - }, - "reference_2": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "reference_2", - "display_name": "reference_2", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - }, - "instructions": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "instructions", - "display_name": "instructions", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, "base_classes": ["object", "Text", "str"], - "name": "", - "display_name": "Prompt", - "documentation": "", + "beta": false, "custom_fields": { "template": ["reference_1", "reference_2", "instructions"] }, - "output_types": ["Text"], - "full_path": null, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false, - "error": null + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "instructions": { + "advanced": false, + "display_name": "instructions", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "instructions", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "reference_1": { + "advanced": false, + "display_name": "reference_1", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "reference_1", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "reference_2": { + "advanced": false, + "display_name": "reference_2", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "reference_2", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "Reference 1:\n\n{reference_1}\n\n---\n\nReference 2:\n\n{reference_2}\n\n---\n\n{instructions}\n\nBlog: \n\n\n" + } + } }, - "id": "Prompt-Rse03", - "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" + "type": "Prompt" }, - "selected": false, - "width": 384, - "height": 571, "dragging": false, + "height": 571, + "id": "Prompt-Rse03", + "position": { + "x": 1331.381712783371, + "y": 535.0279854229713 + }, "positionAbsolute": { "x": 1331.381712783371, "y": 535.0279854229713 - } + }, + "selected": false, + "type": "genericNode", + "width": 384 }, { + "data": { + "id": "URL-HYPkR", + "node": { + "base_classes": ["Record"], + "beta": false, + "custom_fields": { + "urls": null + }, + "description": "Fetch content from one or more URLs.", + "display_name": "URL", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "layout-template", + "output_types": ["Record"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Any, Dict\n\nfrom langchain_community.document_loaders.web_base import WebBaseLoader\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass URLComponent(CustomComponent):\n display_name = \"URL\"\n description = \"Fetch content from one or more URLs.\"\n icon = \"layout-template\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"urls\": {\"display_name\": \"URL\"},\n }\n\n def build(\n self,\n urls: list[str],\n ) -> list[Record]:\n loader = WebBaseLoader(web_paths=[url for url in urls if url])\n docs = loader.load()\n records = self.to_records(docs)\n self.status = records\n return records\n" + }, + "urls": { + "advanced": false, + "display_name": "URL", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "urls", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": [ + "https://www.promptingguide.ai/techniques/prompt_chaining" + ] + } + } + }, + "type": "URL" + }, + "dragging": false, + "height": 281, "id": "URL-HYPkR", - "type": "genericNode", "position": { "x": 568.2971412887712, "y": 700.9983368007821 }, - "data": { - "type": "URL", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Any, Dict\n\nfrom langchain_community.document_loaders.web_base import WebBaseLoader\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass URLComponent(CustomComponent):\n display_name = \"URL\"\n description = \"Fetch content from one or more URLs.\"\n icon = \"layout-template\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"urls\": {\"display_name\": \"URL\"},\n }\n\n def build(\n self,\n urls: list[str],\n ) -> list[Record]:\n loader = WebBaseLoader(web_paths=urls)\n docs = loader.load()\n records = self.to_records(docs)\n self.status = records\n return records\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "urls": { - "type": "str", - "required": true, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "urls", - "display_name": "URL", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": [ - "https://www.promptingguide.ai/techniques/prompt_chaining" - ] - }, - "_type": "CustomComponent" - }, - "description": "Fetch content from one or more URLs.", - "icon": "layout-template", - "base_classes": ["Record"], - "display_name": "URL", - "documentation": "", - "custom_fields": { - "urls": null - }, - "output_types": ["Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "URL-HYPkR" - }, - "selected": false, - "width": 384, - "height": 281, "positionAbsolute": { "x": 568.2971412887712, "y": 700.9983368007821 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { + "data": { + "id": "ChatOutput-JPlxl", + "node": { + "base_classes": ["Text", "Record", "object", "str"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Display a chat message in the Playground.", + "display_name": "Chat Output", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "AI" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatOutput" + }, + "height": 383, "id": "ChatOutput-JPlxl", - "type": "genericNode", "position": { "x": 2503.8617424688505, "y": 789.3005578928434 }, - "data": { - "type": "ChatOutput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "In case of Message being a Record, this template will be used to convert it to text.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "AI", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["Text", "Record", "object", "str"], - "display_name": "Chat Output", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null, - "record_template": null - }, - "output_types": ["Text", "Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "ChatOutput-JPlxl" - }, "selected": false, - "width": 384, - "height": 383 + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIModel-gi29P", - "type": "genericNode", - "position": { - "x": 1917.7089968570963, - "y": 575.9186499244129 - }, "data": { - "type": "OpenAIModel", + "id": "OpenAIModel-gi29P", "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "1024", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-3.5-turbo-0125", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "0.1", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", "base_classes": ["str", "Text", "object"], - "display_name": "OpenAI", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, "max_tokens": null, "model_kwargs": null, + "model_name": null, "openai_api_base": null, + "openai_api_key": null, "stream": null, - "system_message": null + "system_message": null, + "temperature": null }, - "output_types": ["Text"], + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "max_tokens", "model_kwargs", @@ -663,315 +532,406 @@ "system_message", "stream" ], - "beta": false + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": "1024" + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-3.5-turbo-0125" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": true + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": "0.1" + } + } }, - "id": "OpenAIModel-gi29P" + "type": "OpenAIModel" }, - "selected": false, - "width": 384, + "dragging": false, "height": 563, + "id": "OpenAIModel-gi29P", + "position": { + "x": 1917.7089968570963, + "y": 575.9186499244129 + }, "positionAbsolute": { "x": 1917.7089968570963, "y": 575.9186499244129 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { + "data": { + "id": "URL-2cX90", + "node": { + "base_classes": ["Record"], + "beta": false, + "custom_fields": { + "urls": null + }, + "description": "Fetch content from one or more URLs.", + "display_name": "URL", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "layout-template", + "output_types": ["Record"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Any, Dict\n\nfrom langchain_community.document_loaders.web_base import WebBaseLoader\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass URLComponent(CustomComponent):\n display_name = \"URL\"\n description = \"Fetch content from one or more URLs.\"\n icon = \"layout-template\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"urls\": {\"display_name\": \"URL\"},\n }\n\n def build(\n self,\n urls: list[str],\n ) -> list[Record]:\n loader = WebBaseLoader(web_paths=[url for url in urls if url])\n docs = loader.load()\n records = self.to_records(docs)\n self.status = records\n return records\n" + }, + "urls": { + "advanced": false, + "display_name": "URL", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "urls", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": ["https://www.promptingguide.ai/introduction/basics"] + } + } + }, + "type": "URL" + }, + "dragging": false, + "height": 281, "id": "URL-2cX90", - "type": "genericNode", "position": { "x": 573.961301764604, "y": 336.41463436122086 }, - "data": { - "type": "URL", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Any, Dict\n\nfrom langchain_community.document_loaders.web_base import WebBaseLoader\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass URLComponent(CustomComponent):\n display_name = \"URL\"\n description = \"Fetch content from one or more URLs.\"\n icon = \"layout-template\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"urls\": {\"display_name\": \"URL\"},\n }\n\n def build(\n self,\n urls: list[str],\n ) -> list[Record]:\n loader = WebBaseLoader(web_paths=urls)\n docs = loader.load()\n records = self.to_records(docs)\n self.status = records\n return records\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "urls": { - "type": "str", - "required": true, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "urls", - "display_name": "URL", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": ["https://www.promptingguide.ai/introduction/basics"] - }, - "_type": "CustomComponent" - }, - "description": "Fetch content from one or more URLs.", - "icon": "layout-template", - "base_classes": ["Record"], - "display_name": "URL", - "documentation": "", - "custom_fields": { - "urls": null - }, - "output_types": ["Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "URL-2cX90" - }, - "selected": false, - "width": 384, - "height": 281, "positionAbsolute": { "x": 573.961301764604, "y": 336.41463436122086 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "TextInput-og8Or", - "type": "genericNode", - "position": { - "x": 569.9387927203336, - "y": 1095.3352160671316 - }, "data": { - "type": "TextInput", + "id": "TextInput-og8Or", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextInput(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as input.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Optional[str] = \"\",\n record_template: Optional[str] = \"\",\n ) -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Use the references above for style to write a new blog/tutorial about prompt engineering techniques. Suggest non-covered topics.", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": ["Record", "Text"], - "dynamic": false, - "info": "Text or Record to be passed as input.", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Get text inputs from the Playground.", - "icon": "type", "base_classes": ["object", "Text", "str"], - "display_name": "Instructions", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, "record_template": null }, - "output_types": ["Text"], + "description": "Get text inputs from the Playground.", + "display_name": "Instructions", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "type", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextInput(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as input.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Optional[str] = \"\",\n record_template: Optional[str] = \"\",\n ) -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as input.", + "input_types": ["Record", "Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Use the references above for style to write a new blog/tutorial about prompt engineering techniques. Suggest non-covered topics." + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } }, - "id": "TextInput-og8Or" + "type": "TextInput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 289, + "id": "TextInput-og8Or", + "position": { + "x": 569.9387927203336, + "y": 1095.3352160671316 + }, "positionAbsolute": { "x": 569.9387927203336, "y": 1095.3352160671316 }, - "dragging": false - } - ], - "edges": [ - { - "source": "URL-HYPkR", - "target": "Prompt-Rse03", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-HYPkRœ}", - "targetHandle": "{œfieldNameœ:œreference_2œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "id": "reactflow__edge-URL-HYPkR{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-HYPkRœ}-Prompt-Rse03{œfieldNameœ:œreference_2œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "reference_2", - "id": "Prompt-Rse03", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["Record"], - "dataType": "URL", - "id": "URL-HYPkR" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "OpenAIModel-gi29P", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-gi29Pœ}", - "target": "ChatOutput-JPlxl", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-JPlxlœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-JPlxl", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-gi29P" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-gi29P{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-gi29Pœ}-ChatOutput-JPlxl{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-JPlxlœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "URL-2cX90", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-2cX90œ}", - "target": "Prompt-Rse03", - "targetHandle": "{œfieldNameœ:œreference_1œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "reference_1", - "id": "Prompt-Rse03", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["Record"], - "dataType": "URL", - "id": "URL-2cX90" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-URL-2cX90{œbaseClassesœ:[œRecordœ],œdataTypeœ:œURLœ,œidœ:œURL-2cX90œ}-Prompt-Rse03{œfieldNameœ:œreference_1œ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "TextInput-og8Or", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-og8Orœ}", - "target": "Prompt-Rse03", - "targetHandle": "{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "instructions", - "id": "Prompt-Rse03", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "Text", "str"], - "dataType": "TextInput", - "id": "TextInput-og8Or" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-TextInput-og8Or{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-og8Orœ}-Prompt-Rse03{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-Rse03œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "Prompt-Rse03", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-Rse03œ}", - "target": "OpenAIModel-gi29P", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-gi29Pœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-gi29P", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "Text", "str"], - "dataType": "Prompt", - "id": "Prompt-Rse03" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-Rse03{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-Rse03œ}-OpenAIModel-gi29P{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-gi29Pœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "selected": false + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -981,7 +941,8 @@ } }, "description": "This flow can be used to create a blog post following instructions from the user, using two other blogs as reference.", - "name": "Blog Writer", + "id": "6ad5559d-fb66-4fdc-8f98-96f4ac12799d", + "is_component": false, "last_tested_version": "1.0.0a0", - "is_component": false + "name": "Blog Writer" } diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Document QA.json b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Document QA.json index 5fa8547a1..256486942 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Document QA.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Document QA.json @@ -1,161 +1,281 @@ { - "id": "fecbce42-6f11-454c-8ab2-db6eddbbbb0f", "data": { + "edges": [ + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["str", "Record", "Text", "object"], + "dataType": "ChatInput", + "id": "ChatInput-MsSJ9" + }, + "targetHandle": { + "fieldName": "Question", + "id": "Prompt-tHwPf", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-ChatInput-MsSJ9{œbaseClassesœ:[œstrœ,œRecordœ,œTextœ,œobjectœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-MsSJ9œ}-Prompt-tHwPf{œfieldNameœ:œQuestionœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "ChatInput-MsSJ9", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œRecordœ, œTextœ, œobjectœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-MsSJ9œ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-tHwPf", + "targetHandle": "{œfieldNameœ: œQuestionœ, œidœ: œPrompt-tHwPfœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["Record"], + "dataType": "File", + "id": "File-6TEsD" + }, + "targetHandle": { + "fieldName": "Document", + "id": "Prompt-tHwPf", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-File-6TEsD{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-6TEsDœ}-Prompt-tHwPf{œfieldNameœ:œDocumentœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "File-6TEsD", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œFileœ, œidœ: œFile-6TEsDœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-tHwPf", + "targetHandle": "{œfieldNameœ: œDocumentœ, œidœ: œPrompt-tHwPfœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "str", "Text"], + "dataType": "Prompt", + "id": "Prompt-tHwPf" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-Bt067", + "inputTypes": ["Text", "Record", "Prompt"], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-tHwPf{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-tHwPfœ}-OpenAIModel-Bt067{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-Bt067œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-tHwPf", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-tHwPfœ}", + "style": { + "stroke": "#555" + }, + "target": "OpenAIModel-Bt067", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-Bt067œ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["object", "str", "Text"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-Bt067" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-F5Awj", + "inputTypes": ["Text"], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-Bt067{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-Bt067œ}-ChatOutput-F5Awj{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-F5Awjœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-Bt067", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-Bt067œ}", + "style": { + "stroke": "#555" + }, + "target": "ChatOutput-F5Awj", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-F5Awjœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { + "data": { + "description": "A component for creating prompt templates using dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-tHwPf", + "node": { + "base_classes": ["object", "str", "Text"], + "beta": false, + "custom_fields": { + "template": ["Document", "Question"] + }, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, + "field_formatters": {}, + "field_order": [], + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], + "template": { + "Document": { + "advanced": false, + "display_name": "Document", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "Document", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "Question": { + "advanced": false, + "display_name": "Question", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "Question", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "Answer user's questions based on the document below:\n\n---\n\n{Document}\n\n---\n\nQuestion:\n{Question}\n\nAnswer:\n" + } + } + }, + "type": "Prompt" + }, + "dragging": false, + "height": 479, "id": "Prompt-tHwPf", - "type": "genericNode", "position": { "x": 585.7906101139403, "y": 117.52115876762832 }, - "data": { - "type": "Prompt", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Answer user's questions based on the document below:\n\n---\n\n{Document}\n\n---\n\nQuestion:\n{Question}\n\nAnswer:\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "Document": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "Document", - "display_name": "Document", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - }, - "Question": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "Question", - "display_name": "Question", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, - "base_classes": ["object", "str", "Text"], - "name": "", - "display_name": "Prompt", - "documentation": "", - "custom_fields": { - "template": ["Document", "Question"] - }, - "output_types": ["Text"], - "full_path": null, - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false, - "error": null - }, - "id": "Prompt-tHwPf", - "description": "A component for creating prompt templates using dynamic variables.", - "display_name": "Prompt" - }, - "selected": false, - "width": 384, - "height": 479, "positionAbsolute": { "x": 585.7906101139403, "y": 117.52115876762832 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "File-6TEsD", - "type": "genericNode", - "position": { - "x": -18.636536329280602, - "y": 3.951948774836353 - }, "data": { - "type": "File", + "id": "File-6TEsD", "node": { + "base_classes": ["Record"], + "beta": false, + "custom_fields": { + "path": null, + "silent_errors": null + }, + "description": "A generic file loader.", + "display_name": "Files", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "output_types": ["Record"], "template": { - "path": { - "type": "file", - "required": true, - "placeholder": "", + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, "show": true, - "multiline": false, + "title_case": false, + "type": "code", + "value": "from pathlib import Path\nfrom typing import Any, Dict\n\nfrom langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record\nfrom langflow.interface.custom.custom_component import CustomComponent\nfrom langflow.schema import Record\n\n\nclass FileComponent(CustomComponent):\n display_name = \"Files\"\n description = \"A generic file loader.\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"path\": {\n \"display_name\": \"Path\",\n \"field_type\": \"file\",\n \"file_types\": TEXT_FILE_TYPES,\n \"info\": f\"Supported file types: {', '.join(TEXT_FILE_TYPES)}\",\n },\n \"silent_errors\": {\n \"display_name\": \"Silent Errors\",\n \"advanced\": True,\n \"info\": \"If true, errors will not raise an exception.\",\n },\n }\n\n def load_file(self, path: str, silent_errors: bool = False) -> Record:\n resolved_path = self.resolve_path(path)\n path_obj = Path(resolved_path)\n extension = path_obj.suffix[1:].lower()\n if extension == \"doc\":\n raise ValueError(\"doc files are not supported. Please save as .docx\")\n if extension not in TEXT_FILE_TYPES:\n raise ValueError(f\"Unsupported file type: {extension}\")\n record = parse_text_file_to_record(resolved_path, silent_errors)\n self.status = record if record else \"No data\"\n return record or Record()\n\n def build(\n self,\n path: str,\n silent_errors: bool = False,\n ) -> Record:\n record = self.load_file(path, silent_errors)\n self.status = record\n return record\n" + }, + "path": { + "advanced": false, + "display_name": "Path", + "dynamic": false, "fileTypes": [ ".txt", ".md", @@ -170,633 +290,357 @@ ".pdf", ".docx" ], - "password": false, - "name": "path", - "display_name": "Path", - "advanced": false, - "dynamic": false, "info": "Supported file types: txt, md, mdx, csv, json, yaml, yml, xml, html, htm, pdf, docx", + "list": false, "load_from_db": false, + "multiline": false, + "name": "path", + "password": false, + "placeholder": "", + "required": true, + "show": true, "title_case": false, + "type": "file", "value": "" }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from pathlib import Path\nfrom typing import Any, Dict\n\nfrom langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record\nfrom langflow.interface.custom.custom_component import CustomComponent\nfrom langflow.schema import Record\n\n\nclass FileComponent(CustomComponent):\n display_name = \"Files\"\n description = \"A generic file loader.\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"path\": {\n \"display_name\": \"Path\",\n \"field_type\": \"file\",\n \"file_types\": TEXT_FILE_TYPES,\n \"info\": f\"Supported file types: {', '.join(TEXT_FILE_TYPES)}\",\n },\n \"silent_errors\": {\n \"display_name\": \"Silent Errors\",\n \"advanced\": True,\n \"info\": \"If true, errors will not raise an exception.\",\n },\n }\n\n def load_file(self, path: str, silent_errors: bool = False) -> Record:\n resolved_path = self.resolve_path(path)\n path_obj = Path(resolved_path)\n extension = path_obj.suffix[1:].lower()\n if extension == \"doc\":\n raise ValueError(\"doc files are not supported. Please save as .docx\")\n if extension not in TEXT_FILE_TYPES:\n raise ValueError(f\"Unsupported file type: {extension}\")\n record = parse_text_file_to_record(resolved_path, silent_errors)\n self.status = record if record else \"No data\"\n return record or Record()\n\n def build(\n self,\n path: str,\n silent_errors: bool = False,\n ) -> Record:\n record = self.load_file(path, silent_errors)\n self.status = record\n return record\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, "silent_errors": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, + "advanced": true, + "display_name": "Silent Errors", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "silent_errors", - "display_name": "Silent Errors", - "advanced": true, - "dynamic": false, "info": "If true, errors will not raise an exception.", + "list": false, "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "A generic file loader.", - "base_classes": ["Record"], - "display_name": "Files", - "documentation": "", - "custom_fields": { - "path": null, - "silent_errors": null - }, - "output_types": ["Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false + "multiline": false, + "name": "silent_errors", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + } + } }, - "id": "File-6TEsD" + "type": "File" }, - "selected": false, - "width": 384, + "dragging": false, "height": 282, + "id": "File-6TEsD", + "position": { + "x": -18.636536329280602, + "y": 3.951948774836353 + }, "positionAbsolute": { "x": -18.636536329280602, "y": 3.951948774836353 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "ChatInput-MsSJ9", - "type": "genericNode", - "position": { - "x": -28.80036300619821, - "y": 379.81180230285355 - }, "data": { - "type": "ChatInput", + "id": "ChatInput-MsSJ9", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Message\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n ) -> Union[Text, Record]:\n return super().build_no_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": [], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "value": "" - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" + "base_classes": ["str", "Record", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null }, "description": "Get chat inputs from the Playground.", - "icon": "ChatInput", - "base_classes": ["str", "Record", "Text", "object"], "display_name": "Chat Input", "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null - }, - "output_types": ["Text", "Record"], "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "ChatInput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Text\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n files: Optional[list[str]] = None,\n session_id: Optional[str] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n files=files,\n session_id=session_id,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } }, - "id": "ChatInput-MsSJ9" + "type": "ChatInput" }, - "selected": true, - "width": 384, + "dragging": false, "height": 377, + "id": "ChatInput-MsSJ9", + "position": { + "x": -28.80036300619821, + "y": 379.81180230285355 + }, "positionAbsolute": { "x": -28.80036300619821, "y": 379.81180230285355 }, - "dragging": false + "selected": true, + "type": "genericNode", + "width": 384 }, { + "data": { + "id": "ChatOutput-F5Awj", + "node": { + "base_classes": ["str", "Record", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Display a chat message in the Playground.", + "display_name": "Chat Output", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "AI" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatOutput" + }, + "dragging": false, + "height": 385, "id": "ChatOutput-F5Awj", - "type": "genericNode", "position": { "x": 1733.3012915204283, "y": 168.76098809939327 }, - "data": { - "type": "ChatOutput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "AI", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["str", "Record", "Text", "object"], - "display_name": "Chat Output", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null - }, - "output_types": ["Text", "Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "ChatOutput-F5Awj" - }, - "selected": false, - "width": 384, - "height": 385, "positionAbsolute": { "x": 1733.3012915204283, "y": 168.76098809939327 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIModel-Bt067", - "type": "genericNode", - "position": { - "x": 1137.6078582863759, - "y": -14.41920034020356 - }, "data": { - "type": "OpenAIModel", + "id": "OpenAIModel-Bt067", "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-4-turbo-preview", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": false, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 0.1, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", "base_classes": ["object", "str", "Text"], - "display_name": "OpenAI", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, "max_tokens": null, "model_kwargs": null, + "model_name": null, "openai_api_base": null, + "openai_api_key": null, "stream": null, - "system_message": null + "system_message": null, + "temperature": null }, - "output_types": ["Text"], + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "max_tokens", "model_kwargs", @@ -808,116 +652,233 @@ "system_message", "stream" ], - "beta": false + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-4-turbo-preview" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": false, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": true + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } }, - "id": "OpenAIModel-Bt067" + "type": "OpenAIModel" }, - "selected": false, - "width": 384, + "dragging": false, "height": 642, + "id": "OpenAIModel-Bt067", + "position": { + "x": 1137.6078582863759, + "y": -14.41920034020356 + }, "positionAbsolute": { "x": 1137.6078582863759, "y": -14.41920034020356 }, - "dragging": false - } - ], - "edges": [ - { - "source": "ChatInput-MsSJ9", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œRecordœ,œTextœ,œobjectœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-MsSJ9œ}", - "target": "Prompt-tHwPf", - "targetHandle": "{œfieldNameœ:œQuestionœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "Question", - "id": "Prompt-tHwPf", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Record", "Text", "object"], - "dataType": "ChatInput", - "id": "ChatInput-MsSJ9" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-ChatInput-MsSJ9{œbaseClassesœ:[œstrœ,œRecordœ,œTextœ,œobjectœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-MsSJ9œ}-Prompt-tHwPf{œfieldNameœ:œQuestionœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "File-6TEsD", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-6TEsDœ}", - "target": "Prompt-tHwPf", - "targetHandle": "{œfieldNameœ:œDocumentœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "Document", - "id": "Prompt-tHwPf", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["Record"], - "dataType": "File", - "id": "File-6TEsD" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-File-6TEsD{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-6TEsDœ}-Prompt-tHwPf{œfieldNameœ:œDocumentœ,œidœ:œPrompt-tHwPfœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "Prompt-tHwPf", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-tHwPfœ}", - "target": "OpenAIModel-Bt067", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-Bt067œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-Bt067", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "str", "Text"], - "dataType": "Prompt", - "id": "Prompt-tHwPf" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-tHwPf{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-tHwPfœ}-OpenAIModel-Bt067{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-Bt067œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "OpenAIModel-Bt067", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-Bt067œ}", - "target": "ChatOutput-F5Awj", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-F5Awjœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-F5Awj", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "str", "Text"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-Bt067" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-Bt067{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-Bt067œ}-ChatOutput-F5Awj{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-F5Awjœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -927,7 +888,8 @@ } }, "description": "This flow integrates PDF reading with a language model to answer document-specific questions. Ideal for small-scale texts, it facilitates direct queries with immediate insights.", - "name": "Document QA", + "id": "fecbce42-6f11-454c-8ab2-db6eddbbbb0f", + "is_component": false, "last_tested_version": "1.0.0a0", - "is_component": false + "name": "Document QA" } diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Memory Conversation.json b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Memory Conversation.json index 1002b721a..f07f5b351 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Memory Conversation.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Memory Conversation.json @@ -1,883 +1,751 @@ { - "id": "08d5cccf-d098-4367-b14b-1078429c9ed9", - "icon": "🤖", - "icon_bg_color": "#FFD700", "data": { + "edges": [ + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "MemoryComponent", + "id": "MemoryComponent-cdA1J" + }, + "targetHandle": { + "fieldName": "context", + "id": "Prompt-ODkUx", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-Prompt-ODkUx{œfieldNameœ:œcontextœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "MemoryComponent-cdA1J", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œMemoryComponentœ, œidœ: œMemoryComponent-cdA1Jœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-ODkUx", + "targetHandle": "{œfieldNameœ: œcontextœ, œidœ: œPrompt-ODkUxœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["Text", "object", "Record", "str"], + "dataType": "ChatInput", + "id": "ChatInput-t7F8v" + }, + "targetHandle": { + "fieldName": "user_message", + "id": "Prompt-ODkUx", + "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-ChatInput-t7F8v{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-t7F8vœ}-Prompt-ODkUx{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "ChatInput-t7F8v", + "sourceHandle": "{œbaseClassesœ: [œTextœ, œobjectœ, œRecordœ, œstrœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-t7F8vœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-ODkUx", + "targetHandle": "{œfieldNameœ: œuser_messageœ, œidœ: œPrompt-ODkUxœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["Text", "str", "object"], + "dataType": "Prompt", + "id": "Prompt-ODkUx" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-9RykF", + "inputTypes": ["Text", "Record", "Prompt"], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-ODkUx{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-ODkUxœ}-OpenAIModel-9RykF{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-9RykFœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-ODkUx", + "sourceHandle": "{œbaseClassesœ: [œTextœ, œstrœ, œobjectœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-ODkUxœ}", + "style": { + "stroke": "#555" + }, + "target": "OpenAIModel-9RykF", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-9RykFœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["str", "object", "Text"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-9RykF" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-P1jEe", + "inputTypes": ["Text"], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-9RykF{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-9RykFœ}-ChatOutput-P1jEe{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-P1jEeœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-9RykF", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œobjectœ, œTextœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-9RykFœ}", + "style": { + "stroke": "#555" + }, + "target": "ChatOutput-P1jEe", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-P1jEeœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-foreground stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "MemoryComponent", + "id": "MemoryComponent-cdA1J" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "TextOutput-vrs6T", + "inputTypes": ["Record", "Text"], + "type": "str" + } + }, + "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-TextOutput-vrs6T{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-vrs6Tœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "MemoryComponent-cdA1J", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œMemoryComponentœ, œidœ: œMemoryComponent-cdA1Jœ}", + "style": { + "stroke": "#555" + }, + "target": "TextOutput-vrs6T", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œTextOutput-vrs6Tœ, œinputTypesœ: [œRecordœ, œTextœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { - "id": "ChatInput-t7F8v", - "type": "genericNode", - "position": { - "x": 1283.2700598313072, - "y": 982.5953650473145 - }, "data": { - "type": "ChatInput", + "id": "ChatInput-t7F8v", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Message\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n ) -> Union[Text, Record]:\n return super().build_no_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": [], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "value": "" - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": false, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "MySessionID" - }, - "_type": "CustomComponent" + "base_classes": ["Text", "object", "Record", "str"], + "beta": false, + "custom_fields": { + "input_value": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null }, "description": "Get chat inputs from the Playground.", - "icon": "ChatInput", - "base_classes": ["Text", "object", "Record", "str"], "display_name": "Chat Input", "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null - }, - "output_types": ["Text", "Record"], "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "ChatInput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Text\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n files: Optional[list[str]] = None,\n session_id: Optional[str] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n files=files,\n session_id=session_id,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "session_id": { + "advanced": false, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "MySessionID" + } + } }, - "id": "ChatInput-t7F8v" + "type": "ChatInput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 469, + "id": "ChatInput-t7F8v", + "position": { + "x": 1283.2700598313072, + "y": 982.5953650473145 + }, "positionAbsolute": { "x": 1283.2700598313072, "y": 982.5953650473145 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "ChatOutput-P1jEe", - "type": "genericNode", - "position": { - "x": 3154.916355514023, - "y": 851.051882666333 - }, "data": { - "type": "ChatOutput", + "id": "ChatOutput-P1jEe", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "AI", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": false, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "MySessionID" - }, - "_type": "CustomComponent" + "base_classes": ["Text", "object", "Record", "str"], + "beta": false, + "custom_fields": { + "input_value": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null }, "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["Text", "object", "Record", "str"], "display_name": "Chat Output", "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null - }, - "output_types": ["Text", "Record"], "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "AI" + }, + "session_id": { + "advanced": false, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "MySessionID" + } + } }, - "id": "ChatOutput-P1jEe" + "type": "ChatOutput" }, - "selected": false, - "width": 384, - "height": 477, "dragging": false, + "height": 477, + "id": "ChatOutput-P1jEe", + "position": { + "x": 3154.916355514023, + "y": 851.051882666333 + }, "positionAbsolute": { "x": 3154.916355514023, "y": 851.051882666333 - } + }, + "selected": false, + "type": "genericNode", + "width": 384 }, { + "data": { + "description": "Retrieves stored chat messages given a specific Session ID.", + "display_name": "Chat Memory", + "id": "MemoryComponent-cdA1J", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": true, + "custom_fields": { + "n_messages": null, + "order": null, + "record_template": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Retrieves stored chat messages given a specific Session ID.", + "display_name": "Chat Memory", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "history", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.memory.memory import BaseMemoryComponent\nfrom langflow.field_typing import Text\nfrom langflow.helpers.record import messages_to_text\nfrom langflow.memory import get_messages\nfrom langflow.schema.message import Message\n\n\nclass MemoryComponent(BaseMemoryComponent):\n display_name = \"Chat Memory\"\n description = \"Retrieves stored chat messages given a specific Session ID.\"\n beta: bool = True\n icon = \"history\"\n\n def build_config(self):\n return {\n \"sender\": {\n \"options\": [\"Machine\", \"User\", \"Machine and User\"],\n \"display_name\": \"Sender Type\",\n },\n \"sender_name\": {\"display_name\": \"Sender Name\", \"advanced\": True},\n \"n_messages\": {\n \"display_name\": \"Number of Messages\",\n \"info\": \"Number of messages to retrieve.\",\n },\n \"session_id\": {\n \"display_name\": \"Session ID\",\n \"info\": \"Session ID of the chat history.\",\n \"input_types\": [\"Text\"],\n },\n \"order\": {\n \"options\": [\"Ascending\", \"Descending\"],\n \"display_name\": \"Order\",\n \"info\": \"Order of the messages.\",\n \"advanced\": True,\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def get_messages(self, **kwargs) -> list[Message]:\n # Validate kwargs by checking if it contains the correct keys\n if \"sender\" not in kwargs:\n kwargs[\"sender\"] = None\n if \"sender_name\" not in kwargs:\n kwargs[\"sender_name\"] = None\n if \"session_id\" not in kwargs:\n kwargs[\"session_id\"] = None\n if \"limit\" not in kwargs:\n kwargs[\"limit\"] = 5\n if \"order\" not in kwargs:\n kwargs[\"order\"] = \"Descending\"\n\n kwargs[\"order\"] = \"DESC\" if kwargs[\"order\"] == \"Descending\" else \"ASC\"\n if kwargs[\"sender\"] == \"Machine and User\":\n kwargs[\"sender\"] = None\n return get_messages(**kwargs)\n\n def build(\n self,\n sender: Optional[str] = \"Machine and User\",\n sender_name: Optional[str] = None,\n session_id: Optional[str] = None,\n n_messages: int = 5,\n order: Optional[str] = \"Descending\",\n record_template: Optional[str] = \"{sender_name}: {text}\",\n ) -> Text:\n messages = self.get_messages(\n sender=sender,\n sender_name=sender_name,\n session_id=session_id,\n limit=n_messages,\n order=order,\n )\n messages_str = messages_to_text(template=record_template or \"\", messages=messages)\n self.status = messages_str\n return messages_str\n" + }, + "n_messages": { + "advanced": false, + "display_name": "Number of Messages", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Number of messages to retrieve.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "n_messages", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 5 + }, + "order": { + "advanced": true, + "display_name": "Order", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Order of the messages.", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "order", + "options": ["Ascending", "Descending"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Descending" + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "{sender_name}: {text}" + }, + "sender": { + "advanced": false, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User", "Machine and User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine and User" + }, + "sender_name": { + "advanced": true, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "session_id": { + "advanced": false, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Session ID of the chat history.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "MySessionID" + } + } + }, + "type": "MemoryComponent" + }, + "dragging": false, + "height": 489, "id": "MemoryComponent-cdA1J", - "type": "genericNode", "position": { "x": 1289.9606870058817, "y": 442.16804561053766 }, - "data": { - "type": "MemoryComponent", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.memory.memory import BaseMemoryComponent\nfrom langflow.field_typing import Text\nfrom langflow.helpers.record import records_to_text\nfrom langflow.memory import get_messages\nfrom langflow.schema.schema import Record\n\n\nclass MemoryComponent(BaseMemoryComponent):\n display_name = \"Chat Memory\"\n description = \"Retrieves stored chat messages given a specific Session ID.\"\n beta: bool = True\n icon = \"history\"\n\n def build_config(self):\n return {\n \"sender\": {\n \"options\": [\"Machine\", \"User\", \"Machine and User\"],\n \"display_name\": \"Sender Type\",\n },\n \"sender_name\": {\"display_name\": \"Sender Name\", \"advanced\": True},\n \"n_messages\": {\n \"display_name\": \"Number of Messages\",\n \"info\": \"Number of messages to retrieve.\",\n },\n \"session_id\": {\n \"display_name\": \"Session ID\",\n \"info\": \"Session ID of the chat history.\",\n \"input_types\": [\"Text\"],\n },\n \"order\": {\n \"options\": [\"Ascending\", \"Descending\"],\n \"display_name\": \"Order\",\n \"info\": \"Order of the messages.\",\n \"advanced\": True,\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def get_messages(self, **kwargs) -> list[Record]:\n # Validate kwargs by checking if it contains the correct keys\n if \"sender\" not in kwargs:\n kwargs[\"sender\"] = None\n if \"sender_name\" not in kwargs:\n kwargs[\"sender_name\"] = None\n if \"session_id\" not in kwargs:\n kwargs[\"session_id\"] = None\n if \"limit\" not in kwargs:\n kwargs[\"limit\"] = 5\n if \"order\" not in kwargs:\n kwargs[\"order\"] = \"Descending\"\n\n kwargs[\"order\"] = \"DESC\" if kwargs[\"order\"] == \"Descending\" else \"ASC\"\n if kwargs[\"sender\"] == \"Machine and User\":\n kwargs[\"sender\"] = None\n return get_messages(**kwargs)\n\n def build(\n self,\n sender: Optional[str] = \"Machine and User\",\n sender_name: Optional[str] = None,\n session_id: Optional[str] = None,\n n_messages: int = 5,\n order: Optional[str] = \"Descending\",\n record_template: Optional[str] = \"{sender_name}: {text}\",\n ) -> Text:\n messages = self.get_messages(\n sender=sender,\n sender_name=sender_name,\n session_id=session_id,\n limit=n_messages,\n order=order,\n )\n messages_str = records_to_text(template=record_template or \"\", records=messages)\n self.status = messages_str\n return messages_str\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "n_messages": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 5, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "n_messages", - "display_name": "Number of Messages", - "advanced": false, - "dynamic": false, - "info": "Number of messages to retrieve.", - "load_from_db": false, - "title_case": false - }, - "order": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Descending", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Ascending", "Descending"], - "name": "order", - "display_name": "Order", - "advanced": true, - "dynamic": false, - "info": "Order of the messages.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{sender_name}: {text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine and User", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User", "Machine and User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "Session ID of the chat history.", - "load_from_db": false, - "title_case": false, - "value": "MySessionID" - }, - "_type": "CustomComponent" - }, - "description": "Retrieves stored chat messages given a specific Session ID.", - "icon": "history", - "base_classes": ["str", "Text", "object"], - "display_name": "Chat Memory", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "session_id": null, - "n_messages": null, - "order": null, - "record_template": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": true - }, - "id": "MemoryComponent-cdA1J", - "description": "Retrieves stored chat messages given a specific Session ID.", - "display_name": "Chat Memory" - }, - "selected": false, - "width": 384, - "height": 489, - "dragging": false, "positionAbsolute": { "x": 1289.9606870058817, "y": 442.16804561053766 - } + }, + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "Prompt-ODkUx", - "type": "genericNode", - "position": { - "x": 1894.594426342426, - "y": 753.3797365481901 - }, "data": { - "type": "Prompt", + "description": "A component for creating prompt templates using dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-ODkUx", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "{context}\n\nUser: {user_message}\nAI: ", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "context": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "context", - "display_name": "context", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - }, - "user_message": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "user_message", - "display_name": "user_message", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, "base_classes": ["Text", "str", "object"], - "name": "", - "display_name": "Prompt", - "documentation": "", + "beta": false, "custom_fields": { "template": ["context", "user_message"] }, - "output_types": ["Text"], - "full_path": null, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false, - "error": null + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "context": { + "advanced": false, + "display_name": "context", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "context", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "{context}\n\nUser: {user_message}\nAI: " + }, + "user_message": { + "advanced": false, + "display_name": "user_message", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "user_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } }, - "id": "Prompt-ODkUx", - "description": "A component for creating prompt templates using dynamic variables.", - "display_name": "Prompt" + "type": "Prompt" }, - "selected": false, - "width": 384, - "height": 477, "dragging": false, + "height": 477, + "id": "Prompt-ODkUx", + "position": { + "x": 1894.594426342426, + "y": 753.3797365481901 + }, "positionAbsolute": { "x": 1894.594426342426, "y": 753.3797365481901 - } + }, + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIModel-9RykF", - "type": "genericNode", - "position": { - "x": 2561.5850334731617, - "y": 553.2745131130916 - }, "data": { - "type": "OpenAIModel", + "id": "OpenAIModel-9RykF", "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-4-1106-preview", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "0.2", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", "base_classes": ["str", "object", "Text"], - "display_name": "OpenAI", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, "max_tokens": null, "model_kwargs": null, + "model_name": null, "openai_api_base": null, + "openai_api_key": null, "stream": null, - "system_message": null + "system_message": null, + "temperature": null }, - "output_types": ["Text"], + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "max_tokens", "model_kwargs", @@ -889,239 +757,330 @@ "system_message", "stream" ], - "beta": false + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-4-1106-preview" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": "0.2" + } + } }, - "id": "OpenAIModel-9RykF" + "type": "OpenAIModel" }, - "selected": false, - "width": 384, + "dragging": false, "height": 563, + "id": "OpenAIModel-9RykF", + "position": { + "x": 2561.5850334731617, + "y": 553.2745131130916 + }, "positionAbsolute": { "x": 2561.5850334731617, "y": 553.2745131130916 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "TextOutput-vrs6T", - "type": "genericNode", - "position": { - "x": 1911.4785906252087, - "y": 247.39079954376987 - }, "data": { - "type": "TextOutput", + "id": "TextOutput-vrs6T", "node": { - "template": { - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": ["Record", "Text"], - "dynamic": false, - "info": "Text or Record to be passed as output.", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a text output in the Playground.", - "icon": "type", "base_classes": ["str", "object", "Text"], - "display_name": "Inspect Memory", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, "record_template": null }, - "output_types": ["Text"], + "description": "Display a text output in the Playground.", + "display_name": "Inspect Memory", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "type", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as output.", + "input_types": ["Record", "Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } }, - "id": "TextOutput-vrs6T" + "type": "TextOutput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 289, + "id": "TextOutput-vrs6T", + "position": { + "x": 1911.4785906252087, + "y": 247.39079954376987 + }, "positionAbsolute": { "x": 1911.4785906252087, "y": 247.39079954376987 }, - "dragging": false - } - ], - "edges": [ - { - "source": "MemoryComponent-cdA1J", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}", - "target": "Prompt-ODkUx", - "targetHandle": "{œfieldNameœ:œcontextœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "context", - "type": "str", - "id": "Prompt-ODkUx", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"] - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "MemoryComponent", - "id": "MemoryComponent-cdA1J" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-Prompt-ODkUx{œfieldNameœ:œcontextœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "selected": false - }, - { - "source": "ChatInput-t7F8v", - "sourceHandle": "{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-t7F8vœ}", - "target": "Prompt-ODkUx", - "targetHandle": "{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "user_message", - "type": "str", - "id": "Prompt-ODkUx", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"] - }, - "sourceHandle": { - "baseClasses": ["Text", "object", "Record", "str"], - "dataType": "ChatInput", - "id": "ChatInput-t7F8v" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-ChatInput-t7F8v{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-t7F8vœ}-Prompt-ODkUx{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "selected": false - }, - { - "source": "Prompt-ODkUx", - "sourceHandle": "{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-ODkUxœ}", - "target": "OpenAIModel-9RykF", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-9RykFœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-9RykF", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["Text", "str", "object"], - "dataType": "Prompt", - "id": "Prompt-ODkUx" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-ODkUx{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-ODkUxœ}-OpenAIModel-9RykF{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-9RykFœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "OpenAIModel-9RykF", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-9RykFœ}", - "target": "ChatOutput-P1jEe", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-P1jEeœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-P1jEe", - "inputTypes": ["Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "object", "Text"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-9RykF" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-9RykF{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-9RykFœ}-ChatOutput-P1jEe{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-P1jEeœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "MemoryComponent-cdA1J", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}", - "target": "TextOutput-vrs6T", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-vrs6Tœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "TextOutput-vrs6T", - "inputTypes": ["Record", "Text"], - "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "MemoryComponent", - "id": "MemoryComponent-cdA1J" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-foreground stroke-connection", - "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-TextOutput-vrs6T{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-vrs6Tœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}" + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -1131,7 +1090,10 @@ } }, "description": "This project can be used as a starting point for building a Chat experience with user specific memory. You can set a different Session ID to start a new message history.", - "name": "Memory Chatbot", + "icon": "🤖", + "icon_bg_color": "#FFD700", + "id": "08d5cccf-d098-4367-b14b-1078429c9ed9", + "is_component": false, "last_tested_version": "1.0.0a0", - "is_component": false + "name": "Memory Chatbot" } diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Prompt Chaining.json b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Prompt Chaining.json index d49eba054..5594a9109 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Prompt Chaining.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Prompt Chaining.json @@ -1,1576 +1,1497 @@ { - "id": "85392e54-20f3-4ab5-a179-cb4bef16f639", "data": { - "nodes": [ - { - "id": "Prompt-amqBu", - "type": "genericNode", - "position": { - "x": 2191.5837146441663, - "y": 1047.9307944451873 - }, - "data": { - "type": "Prompt", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "You are a helpful assistant. Given a long document, your task is to create a concise summary that captures the main points and key details. The summary should be clear, accurate, and succinct. Please provide the summary in the format below:\n####\n{document}\n####\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "document": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "document", - "display_name": "document", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, - "base_classes": ["object", "str", "Text"], - "name": "", - "display_name": "Prompt", - "documentation": "", - "custom_fields": { - "template": ["document"] - }, - "output_types": ["Text"], - "full_path": null, - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false, - "error": null - }, - "id": "Prompt-amqBu", - "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" - }, - "selected": false, - "width": 384, - "height": 385, - "positionAbsolute": { - "x": 2191.5837146441663, - "y": 1047.9307944451873 - }, - "dragging": false - }, - { - "id": "Prompt-gTNiz", - "type": "genericNode", - "position": { - "x": 3731.0813766902447, - "y": 799.631909121391 - }, - "data": { - "type": "Prompt", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Given a summary of an article, please create two multiple-choice questions that cover the key points and details mentioned. Ensure the questions are clear and provide three options (A, B, C), with one correct answer.\n####\n{summary}\n####", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "summary": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "summary", - "display_name": "summary", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, - "base_classes": ["object", "str", "Text"], - "name": "", - "display_name": "Prompt", - "documentation": "", - "custom_fields": { - "template": ["summary"] - }, - "output_types": ["Text"], - "full_path": null, - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false, - "error": null - }, - "id": "Prompt-gTNiz", - "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" - }, - "selected": false, - "width": 384, - "height": 385, - "dragging": false - }, - { - "id": "ChatOutput-EJkG3", - "type": "genericNode", - "position": { - "x": 3722.1747844849388, - "y": 1283.413553222214 - }, - "data": { - "type": "ChatOutput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "In case of Message being a Record, this template will be used to convert it to text.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Summarizer", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["object", "Record", "Text", "str"], - "display_name": "Chat Output", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null, - "record_template": null - }, - "output_types": ["Text", "Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "ChatOutput-EJkG3" - }, - "selected": false, - "width": 384, - "height": 385, - "dragging": false - }, - { - "id": "ChatOutput-DNmvg", - "type": "genericNode", - "position": { - "x": 5077.71285886074, - "y": 1232.9152769735522 - }, - "data": { - "type": "ChatOutput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": ["Text"], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "In case of Message being a Record, this template will be used to convert it to text.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": ["Machine", "User"], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Question Generator", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", - "base_classes": ["object", "Record", "Text", "str"], - "display_name": "Chat Output", - "documentation": "", - "custom_fields": { - "sender": null, - "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null, - "record_template": null - }, - "output_types": ["Text", "Record"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "ChatOutput-DNmvg" - }, - "selected": false, - "width": 384, - "height": 385 - }, - { - "id": "TextInput-sptaH", - "type": "genericNode", - "position": { - "x": 1700.5624822024752, - "y": 1039.603088937466 - }, - "data": { - "type": "TextInput", - "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextInput(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as input.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Optional[Text] = \"\",\n record_template: Optional[str] = \"\",\n ) -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "Revolutionary Nano-Battery Technology Unveiled In a groundbreaking announcement yesterday, researchers from the fictional Tech Innovations Institute revealed the development of a new nano-battery technology that promises to revolutionize energy storage. The new battery, dubbed the \"EnerGCell\", uses advanced nanomaterials to achieve unprecedented efficiency and storage capacities. According to lead researcher Dr. Ada Byron, the EnerGCell can store up to ten times more energy than the best lithium-ion batteries available today, while charging in just a fraction of the time. \"We're talking about charging your electric vehicle in just five minutes for a range of over 1,000 miles,\" Dr. Byron stated during the press conference. The technology behind the EnerGCell involves a complex arrangement of nanostructured electrodes that allow for rapid ion transfer and extremely high energy density. This breakthrough was achieved after a decade of research into nanomaterials and their applications in energy storage. The implications of this technology are vast, promising to accelerate the adoption of renewable energy by making it more practical and affordable to store wind and solar power. It could also lead to significant advancements in electric vehicles, mobile devices, and any other technology that relies on batteries. Despite the excitement, some experts are calling for patience, noting that the EnerGCell is still in its early stages of development and may take several years before it's commercially available. However, the potential impact of such a technology on the environment and the global economy is undeniable. Tech Innovations Institute plans to continue refining the EnerGCell and begin pilot projects with select partners in the coming year. If successful, this nano-battery technology could indeed be the breakthrough needed to usher in a new era of clean energy and technology.", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": ["Record", "Text"], - "dynamic": false, - "info": "Text or Record to be passed as input.", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Get text inputs from the Playground.", - "icon": "type", - "base_classes": ["str", "Text", "object"], - "display_name": "Text Input", - "documentation": "", - "custom_fields": { - "input_value": null, - "record_template": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "TextInput-sptaH" - }, - "selected": false, - "width": 384, - "height": 290, - "positionAbsolute": { - "x": 1700.5624822024752, - "y": 1039.603088937466 - }, - "dragging": false - }, - { - "id": "TextOutput-2MS4a", - "type": "genericNode", - "position": { - "x": 2917.216113690115, - "y": 513.0058511435552 - }, - "data": { - "type": "TextOutput", - "node": { - "template": { - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": ["Record", "Text"], - "dynamic": false, - "info": "Text or Record to be passed as output.", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a text output in the Playground.", - "icon": "type", - "base_classes": ["str", "Text", "object"], - "display_name": "First Prompt", - "documentation": "", - "custom_fields": { - "input_value": null, - "record_template": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "TextOutput-2MS4a" - }, - "selected": false, - "width": 384, - "height": 290, - "positionAbsolute": { - "x": 2917.216113690115, - "y": 513.0058511435552 - }, - "dragging": false - }, - { - "id": "OpenAIModel-uYXZJ", - "type": "genericNode", - "position": { - "x": 2925.784767523062, - "y": 933.6465680967775 - }, - "data": { - "type": "OpenAIModel", - "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-4-turbo-preview", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 0.1, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", - "base_classes": ["str", "Text", "object"], - "display_name": "OpenAI", - "documentation": "", - "custom_fields": { - "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, - "max_tokens": null, - "model_kwargs": null, - "openai_api_base": null, - "stream": null, - "system_message": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [ - "max_tokens", - "model_kwargs", - "model_name", - "openai_api_base", - "openai_api_key", - "temperature", - "input_value", - "system_message", - "stream" - ], - "beta": false - }, - "id": "OpenAIModel-uYXZJ" - }, - "selected": false, - "width": 384, - "height": 565, - "positionAbsolute": { - "x": 2925.784767523062, - "y": 933.6465680967775 - }, - "dragging": false - }, - { - "id": "TextOutput-MUDOR", - "type": "genericNode", - "position": { - "x": 4446.064323520379, - "y": 633.833297518702 - }, - "data": { - "type": "TextOutput", - "node": { - "template": { - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": ["Record", "Text"], - "dynamic": false, - "info": "Text or Record to be passed as output.", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "_type": "CustomComponent" - }, - "description": "Display a text output in the Playground.", - "icon": "type", - "base_classes": ["str", "Text", "object"], - "display_name": "Second Prompt", - "documentation": "", - "custom_fields": { - "input_value": null, - "record_template": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "TextOutput-MUDOR" - }, - "selected": false, - "width": 384, - "height": 290, - "dragging": false, - "positionAbsolute": { - "x": 4446.064323520379, - "y": 633.833297518702 - } - }, - { - "id": "OpenAIModel-XawYB", - "type": "genericNode", - "position": { - "x": 4500.152018344182, - "y": 1027.7382026227656 - }, - "data": { - "type": "OpenAIModel", - "node": { - "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "load_from_db": false, - "title_case": false - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-4-turbo-preview", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"], - "value": "" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, - "title_case": false, - "input_types": ["Text"] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 0.1, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", - "base_classes": ["str", "Text", "object"], - "display_name": "OpenAI", - "documentation": "", - "custom_fields": { - "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, - "max_tokens": null, - "model_kwargs": null, - "openai_api_base": null, - "stream": null, - "system_message": null - }, - "output_types": ["Text"], - "field_formatters": {}, - "frozen": false, - "field_order": [ - "max_tokens", - "model_kwargs", - "model_name", - "openai_api_base", - "openai_api_key", - "temperature", - "input_value", - "system_message", - "stream" - ], - "beta": false - }, - "id": "OpenAIModel-XawYB" - }, - "selected": false, - "width": 384, - "height": 565, - "positionAbsolute": { - "x": 4500.152018344182, - "y": 1027.7382026227656 - }, - "dragging": false - } - ], "edges": [ { - "source": "TextInput-sptaH", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-sptaHœ}", - "target": "Prompt-amqBu", - "targetHandle": "{œfieldNameœ:œdocumentœ,œidœ:œPrompt-amqBuœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "className": "stroke-gray-900 stroke-connection", "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "TextInput", + "id": "TextInput-sptaH" + }, "targetHandle": { "fieldName": "document", "id": "Prompt-amqBu", "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "TextInput", - "id": "TextInput-sptaH" } }, + "id": "reactflow__edge-TextInput-sptaH{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-sptaHœ}-Prompt-amqBu{œfieldNameœ:œdocumentœ,œidœ:œPrompt-amqBuœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "TextInput-sptaH", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œTextInputœ, œidœ: œTextInput-sptaHœ}", "style": { "stroke": "#555" }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-TextInput-sptaH{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œTextInputœ,œidœ:œTextInput-sptaHœ}-Prompt-amqBu{œfieldNameœ:œdocumentœ,œidœ:œPrompt-amqBuœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" + "target": "Prompt-amqBu", + "targetHandle": "{œfieldNameœ: œdocumentœ, œidœ: œPrompt-amqBuœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" }, { - "source": "Prompt-amqBu", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}", - "target": "TextOutput-2MS4a", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-2MS4aœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "className": "stroke-gray-900 stroke-connection", "data": { + "sourceHandle": { + "baseClasses": ["object", "str", "Text"], + "dataType": "Prompt", + "id": "Prompt-amqBu" + }, "targetHandle": { "fieldName": "input_value", "id": "TextOutput-2MS4a", "inputTypes": ["Record", "Text"], "type": "str" - }, + } + }, + "id": "reactflow__edge-Prompt-amqBu{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}-TextOutput-2MS4a{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-2MS4aœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-amqBu", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-amqBuœ}", + "style": { + "stroke": "#555" + }, + "target": "TextOutput-2MS4a", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œTextOutput-2MS4aœ, œinputTypesœ: [œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { "sourceHandle": { "baseClasses": ["object", "str", "Text"], "dataType": "Prompt", "id": "Prompt-amqBu" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-amqBu{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}-TextOutput-2MS4a{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-2MS4aœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "Prompt-amqBu", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}", - "target": "OpenAIModel-uYXZJ", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-uYXZJœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { + }, "targetHandle": { "fieldName": "input_value", "id": "OpenAIModel-uYXZJ", - "inputTypes": ["Text"], + "inputTypes": ["Text", "Record", "Prompt"], "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "str", "Text"], - "dataType": "Prompt", - "id": "Prompt-amqBu" } }, + "id": "reactflow__edge-Prompt-amqBu{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}-OpenAIModel-uYXZJ{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-uYXZJœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-amqBu", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-amqBuœ}", "style": { "stroke": "#555" }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-amqBu{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-amqBuœ}-OpenAIModel-uYXZJ{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-uYXZJœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" + "target": "OpenAIModel-uYXZJ", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-uYXZJœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" }, { - "source": "OpenAIModel-uYXZJ", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}", - "target": "Prompt-gTNiz", - "targetHandle": "{œfieldNameœ:œsummaryœ,œidœ:œPrompt-gTNizœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "className": "stroke-gray-900 stroke-connection", "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-uYXZJ" + }, "targetHandle": { "fieldName": "summary", "id": "Prompt-gTNiz", "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], "type": "str" - }, + } + }, + "id": "reactflow__edge-OpenAIModel-uYXZJ{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}-Prompt-gTNiz{œfieldNameœ:œsummaryœ,œidœ:œPrompt-gTNizœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-uYXZJ", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-uYXZJœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-gTNiz", + "targetHandle": "{œfieldNameœ: œsummaryœ, œidœ: œPrompt-gTNizœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { "sourceHandle": { "baseClasses": ["str", "Text", "object"], "dataType": "OpenAIModel", "id": "OpenAIModel-uYXZJ" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-uYXZJ{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}-Prompt-gTNiz{œfieldNameœ:œsummaryœ,œidœ:œPrompt-gTNizœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "OpenAIModel-uYXZJ", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}", - "target": "ChatOutput-EJkG3", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-EJkG3œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { + }, "targetHandle": { "fieldName": "input_value", "id": "ChatOutput-EJkG3", "inputTypes": ["Text"], "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-uYXZJ" } }, + "id": "reactflow__edge-OpenAIModel-uYXZJ{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}-ChatOutput-EJkG3{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-EJkG3œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-uYXZJ", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-uYXZJœ}", "style": { "stroke": "#555" }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-uYXZJ{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-uYXZJœ}-ChatOutput-EJkG3{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-EJkG3œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" + "target": "ChatOutput-EJkG3", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-EJkG3œ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" }, { - "source": "Prompt-gTNiz", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}", - "target": "TextOutput-MUDOR", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-MUDORœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "className": "stroke-gray-900 stroke-connection", "data": { + "sourceHandle": { + "baseClasses": ["object", "str", "Text"], + "dataType": "Prompt", + "id": "Prompt-gTNiz" + }, "targetHandle": { "fieldName": "input_value", "id": "TextOutput-MUDOR", "inputTypes": ["Record", "Text"], "type": "str" - }, + } + }, + "id": "reactflow__edge-Prompt-gTNiz{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}-TextOutput-MUDOR{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-MUDORœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-gTNiz", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-gTNizœ}", + "style": { + "stroke": "#555" + }, + "target": "TextOutput-MUDOR", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œTextOutput-MUDORœ, œinputTypesœ: [œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { "sourceHandle": { "baseClasses": ["object", "str", "Text"], "dataType": "Prompt", "id": "Prompt-gTNiz" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-gTNiz{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}-TextOutput-MUDOR{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-MUDORœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "Prompt-gTNiz", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}", - "target": "OpenAIModel-XawYB", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-XawYBœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { + }, "targetHandle": { "fieldName": "input_value", "id": "OpenAIModel-XawYB", - "inputTypes": ["Text"], + "inputTypes": ["Text", "Record", "Prompt"], "type": "str" - }, - "sourceHandle": { - "baseClasses": ["object", "str", "Text"], - "dataType": "Prompt", - "id": "Prompt-gTNiz" } }, + "id": "reactflow__edge-Prompt-gTNiz{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}-OpenAIModel-XawYB{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-XawYBœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "Prompt-gTNiz", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œstrœ, œTextœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-gTNizœ}", "style": { "stroke": "#555" }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-Prompt-gTNiz{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-gTNizœ}-OpenAIModel-XawYB{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-XawYBœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" + "target": "OpenAIModel-XawYB", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-XawYBœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" }, { - "source": "OpenAIModel-XawYB", - "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-XawYBœ}", - "target": "ChatOutput-DNmvg", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-DNmvgœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "className": "stroke-gray-900 stroke-connection", "data": { + "sourceHandle": { + "baseClasses": ["str", "Text", "object"], + "dataType": "OpenAIModel", + "id": "OpenAIModel-XawYB" + }, "targetHandle": { "fieldName": "input_value", "id": "ChatOutput-DNmvg", "inputTypes": ["Text"], "type": "str" - }, - "sourceHandle": { - "baseClasses": ["str", "Text", "object"], - "dataType": "OpenAIModel", - "id": "OpenAIModel-XawYB" } }, + "id": "reactflow__edge-OpenAIModel-XawYB{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-XawYBœ}-ChatOutput-DNmvg{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-DNmvgœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-XawYB", + "sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-XawYBœ}", "style": { "stroke": "#555" }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIModel-XawYB{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-XawYBœ}-ChatOutput-DNmvg{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-DNmvgœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" + "target": "ChatOutput-DNmvg", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-DNmvgœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + } + ], + "nodes": [ + { + "data": { + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-amqBu", + "node": { + "base_classes": ["object", "str", "Text"], + "beta": false, + "custom_fields": { + "template": ["document"] + }, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, + "field_formatters": {}, + "field_order": [], + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "document": { + "advanced": false, + "display_name": "document", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "document", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "You are a helpful assistant. Given a long document, your task is to create a concise summary that captures the main points and key details. The summary should be clear, accurate, and succinct. Please provide the summary in the format below:\n####\n{document}\n####\n" + } + } + }, + "type": "Prompt" + }, + "dragging": false, + "height": 385, + "id": "Prompt-amqBu", + "position": { + "x": 2191.5837146441663, + "y": 1047.9307944451873 + }, + "positionAbsolute": { + "x": 2191.5837146441663, + "y": 1047.9307944451873 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-gTNiz", + "node": { + "base_classes": ["object", "str", "Text"], + "beta": false, + "custom_fields": { + "template": ["summary"] + }, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, + "field_formatters": {}, + "field_order": [], + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": ["Prompt"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "summary": { + "advanced": false, + "display_name": "summary", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "summary", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "Given a summary of an article, please create two multiple-choice questions that cover the key points and details mentioned. Ensure the questions are clear and provide three options (A, B, C), with one correct answer.\n####\n{summary}\n####" + } + } + }, + "type": "Prompt" + }, + "dragging": false, + "height": 385, + "id": "Prompt-gTNiz", + "position": { + "x": 3731.0813766902447, + "y": 799.631909121391 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "ChatOutput-EJkG3", + "node": { + "base_classes": ["object", "Record", "Text", "str"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Display a chat message in the Playground.", + "display_name": "Chat Output", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Summarizer" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatOutput" + }, + "dragging": false, + "height": 385, + "id": "ChatOutput-EJkG3", + "position": { + "x": 3722.1747844849388, + "y": 1283.413553222214 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "ChatOutput-DNmvg", + "node": { + "base_classes": ["object", "Record", "Text", "str"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null, + "return_record": null, + "sender": null, + "sender_name": null, + "session_id": null + }, + "description": "Display a chat message in the Playground.", + "display_name": "Chat Output", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "ChatOutput", + "output_types": ["Message"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": ["Machine", "User"], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Question Generator" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatOutput" + }, + "height": 385, + "id": "ChatOutput-DNmvg", + "position": { + "x": 5077.71285886074, + "y": 1232.9152769735522 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "TextInput-sptaH", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null + }, + "description": "Get text inputs from the Playground.", + "display_name": "Text Input", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "type", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextInput(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Text\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as input.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Optional[Text] = \"\",\n record_template: Optional[str] = \"\",\n ) -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as input.", + "input_types": ["Record", "Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Revolutionary Nano-Battery Technology Unveiled In a groundbreaking announcement yesterday, researchers from the fictional Tech Innovations Institute revealed the development of a new nano-battery technology that promises to revolutionize energy storage. The new battery, dubbed the \"EnerGCell\", uses advanced nanomaterials to achieve unprecedented efficiency and storage capacities. According to lead researcher Dr. Ada Byron, the EnerGCell can store up to ten times more energy than the best lithium-ion batteries available today, while charging in just a fraction of the time. \"We're talking about charging your electric vehicle in just five minutes for a range of over 1,000 miles,\" Dr. Byron stated during the press conference. The technology behind the EnerGCell involves a complex arrangement of nanostructured electrodes that allow for rapid ion transfer and extremely high energy density. This breakthrough was achieved after a decade of research into nanomaterials and their applications in energy storage. The implications of this technology are vast, promising to accelerate the adoption of renewable energy by making it more practical and affordable to store wind and solar power. It could also lead to significant advancements in electric vehicles, mobile devices, and any other technology that relies on batteries. Despite the excitement, some experts are calling for patience, noting that the EnerGCell is still in its early stages of development and may take several years before it's commercially available. However, the potential impact of such a technology on the environment and the global economy is undeniable. Tech Innovations Institute plans to continue refining the EnerGCell and begin pilot projects with select partners in the coming year. If successful, this nano-battery technology could indeed be the breakthrough needed to usher in a new era of clean energy and technology." + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } + }, + "type": "TextInput" + }, + "dragging": false, + "height": 290, + "id": "TextInput-sptaH", + "position": { + "x": 1700.5624822024752, + "y": 1039.603088937466 + }, + "positionAbsolute": { + "x": 1700.5624822024752, + "y": 1039.603088937466 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "TextOutput-2MS4a", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null + }, + "description": "Display a text output in the Playground.", + "display_name": "First Prompt", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "type", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as output.", + "input_types": ["Record", "Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } + }, + "type": "TextOutput" + }, + "dragging": false, + "height": 290, + "id": "TextOutput-2MS4a", + "position": { + "x": 2917.216113690115, + "y": 513.0058511435552 + }, + "positionAbsolute": { + "x": 2917.216113690115, + "y": 513.0058511435552 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "OpenAIModel-uYXZJ", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "max_tokens": null, + "model_kwargs": null, + "model_name": null, + "openai_api_base": null, + "openai_api_key": null, + "stream": null, + "system_message": null, + "temperature": null + }, + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", + "field_formatters": {}, + "field_order": [ + "max_tokens", + "model_kwargs", + "model_name", + "openai_api_base", + "openai_api_key", + "temperature", + "input_value", + "system_message", + "stream" + ], + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-4-turbo-preview" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } + }, + "type": "OpenAIModel" + }, + "dragging": false, + "height": 565, + "id": "OpenAIModel-uYXZJ", + "position": { + "x": 2925.784767523062, + "y": 933.6465680967775 + }, + "positionAbsolute": { + "x": 2925.784767523062, + "y": 933.6465680967775 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "TextOutput-MUDOR", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "record_template": null + }, + "description": "Display a text output in the Playground.", + "display_name": "Second Prompt", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "type", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as output.", + "input_types": ["Record", "Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + } + } + }, + "type": "TextOutput" + }, + "dragging": false, + "height": 290, + "id": "TextOutput-MUDOR", + "position": { + "x": 4446.064323520379, + "y": 633.833297518702 + }, + "positionAbsolute": { + "x": 4446.064323520379, + "y": 633.833297518702 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "OpenAIModel-XawYB", + "node": { + "base_classes": ["str", "Text", "object"], + "beta": false, + "custom_fields": { + "input_value": null, + "max_tokens": null, + "model_kwargs": null, + "model_name": null, + "openai_api_base": null, + "openai_api_key": null, + "stream": null, + "system_message": null, + "temperature": null + }, + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", + "field_formatters": {}, + "field_order": [ + "max_tokens", + "model_kwargs", + "model_name", + "openai_api_base", + "openai_api_key", + "temperature", + "input_value", + "system_message", + "stream" + ], + "frozen": false, + "icon": "OpenAI", + "output_types": ["Text"], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text", "Record", "Prompt"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": ["Text"], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-4-turbo-preview" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": ["Text"], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } + }, + "type": "OpenAIModel" + }, + "dragging": false, + "height": 565, + "id": "OpenAIModel-XawYB", + "position": { + "x": 4500.152018344182, + "y": 1027.7382026227656 + }, + "positionAbsolute": { + "x": 4500.152018344182, + "y": 1027.7382026227656 + }, + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -1580,7 +1501,8 @@ } }, "description": "The Prompt Chaining flow chains prompts with LLMs, refining outputs through iterative stages.", - "name": "Prompt Chaining", + "id": "85392e54-20f3-4ab5-a179-cb4bef16f639", + "is_component": false, "last_tested_version": "1.0.0a0", - "is_component": false + "name": "Prompt Chaining" } diff --git a/src/backend/base/langflow/initial_setup/starter_projects/VectorStore-RAG-Flows.json b/src/backend/base/langflow/initial_setup/starter_projects/VectorStore-RAG-Flows.json index 736edd7dc..daed19b9a 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/VectorStore-RAG-Flows.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/VectorStore-RAG-Flows.json @@ -1,792 +1,592 @@ { - "id": "51e2b78a-199b-4054-9f32-e288eef6924c", "data": { + "edges": [ + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "object", + "Text", + "str" + ], + "dataType": "TextOutput", + "id": "TextOutput-BDknO" + }, + "targetHandle": { + "fieldName": "context", + "id": "Prompt-xeI6K", + "inputTypes": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-TextOutput-BDknO{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextOutputœ,œidœ:œTextOutput-BDknOœ}-Prompt-xeI6K{œfieldNameœ:œcontextœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "TextOutput-BDknO", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œTextOutputœ, œidœ: œTextOutput-BDknOœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-xeI6K", + "targetHandle": "{œfieldNameœ: œcontextœ, œidœ: œPrompt-xeI6Kœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Text", + "str", + "object", + "Record" + ], + "dataType": "ChatInput", + "id": "ChatInput-yxMKE" + }, + "targetHandle": { + "fieldName": "question", + "id": "Prompt-xeI6K", + "inputTypes": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-ChatInput-yxMKE{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}-Prompt-xeI6K{œfieldNameœ:œquestionœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "ChatInput-yxMKE", + "sourceHandle": "{œbaseClassesœ: [œTextœ, œstrœ, œobjectœ, œRecordœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-yxMKEœ}", + "style": { + "stroke": "#555" + }, + "target": "Prompt-xeI6K", + "targetHandle": "{œfieldNameœ: œquestionœ, œidœ: œPrompt-xeI6Kœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "object", + "Text", + "str" + ], + "dataType": "Prompt", + "id": "Prompt-xeI6K" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-EjXlN", + "inputTypes": [ + "Text", + "Record", + "Prompt" + ], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-xeI6K{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-xeI6Kœ}-OpenAIModel-EjXlN{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-EjXlNœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "Prompt-xeI6K", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-xeI6Kœ}", + "style": { + "stroke": "#555" + }, + "target": "OpenAIModel-EjXlN", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-EjXlNœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "object", + "Text", + "str" + ], + "dataType": "OpenAIModel", + "id": "OpenAIModel-EjXlN" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-Q39I8", + "inputTypes": [ + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-EjXlN{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-EjXlNœ}-ChatOutput-Q39I8{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-Q39I8œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "selected": false, + "source": "OpenAIModel-EjXlN", + "sourceHandle": "{œbaseClassesœ: [œobjectœ, œTextœ, œstrœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-EjXlNœ}", + "style": { + "stroke": "#555" + }, + "target": "ChatOutput-Q39I8", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-Q39I8œ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Record" + ], + "dataType": "File", + "id": "File-t0a6a" + }, + "targetHandle": { + "fieldName": "inputs", + "id": "RecursiveCharacterTextSplitter-tR9QM", + "inputTypes": [ + "Document", + "Record" + ], + "type": "Document" + } + }, + "id": "reactflow__edge-File-t0a6a{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-t0a6aœ}-RecursiveCharacterTextSplitter-tR9QM{œfieldNameœ:œinputsœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ,œinputTypesœ:[œDocumentœ,œRecordœ],œtypeœ:œDocumentœ}", + "selected": false, + "source": "File-t0a6a", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œFileœ, œidœ: œFile-t0a6aœ}", + "style": { + "stroke": "#555" + }, + "target": "RecursiveCharacterTextSplitter-tR9QM", + "targetHandle": "{œfieldNameœ: œinputsœ, œidœ: œRecursiveCharacterTextSplitter-tR9QMœ, œinputTypesœ: [œDocumentœ, œRecordœ], œtypeœ: œDocumentœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Embeddings" + ], + "dataType": "OpenAIEmbeddings", + "id": "OpenAIEmbeddings-ZlOk1" + }, + "targetHandle": { + "fieldName": "embedding", + "id": "AstraDBSearch-41nRz", + "inputTypes": null, + "type": "Embeddings" + } + }, + "id": "reactflow__edge-OpenAIEmbeddings-ZlOk1{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-ZlOk1œ}-AstraDBSearch-41nRz{œfieldNameœ:œembeddingœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}", + "source": "OpenAIEmbeddings-ZlOk1", + "sourceHandle": "{œbaseClassesœ: [œEmbeddingsœ], œdataTypeœ: œOpenAIEmbeddingsœ, œidœ: œOpenAIEmbeddings-ZlOk1œ}", + "style": { + "stroke": "#555" + }, + "target": "AstraDBSearch-41nRz", + "targetHandle": "{œfieldNameœ: œembeddingœ, œidœ: œAstraDBSearch-41nRzœ, œinputTypesœ: null, œtypeœ: œEmbeddingsœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Text", + "str", + "object", + "Record" + ], + "dataType": "ChatInput", + "id": "ChatInput-yxMKE" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "AstraDBSearch-41nRz", + "inputTypes": [ + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-ChatInput-yxMKE{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}-AstraDBSearch-41nRz{œfieldNameœ:œinput_valueœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", + "source": "ChatInput-yxMKE", + "sourceHandle": "{œbaseClassesœ: [œTextœ, œstrœ, œobjectœ, œRecordœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-yxMKEœ}", + "style": { + "stroke": "#555" + }, + "target": "AstraDBSearch-41nRz", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œAstraDBSearch-41nRzœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Record" + ], + "dataType": "RecursiveCharacterTextSplitter", + "id": "RecursiveCharacterTextSplitter-tR9QM" + }, + "targetHandle": { + "fieldName": "inputs", + "id": "AstraDB-eUCSS", + "inputTypes": null, + "type": "Record" + } + }, + "id": "reactflow__edge-RecursiveCharacterTextSplitter-tR9QM{œbaseClassesœ:[œRecordœ],œdataTypeœ:œRecursiveCharacterTextSplitterœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ}-AstraDB-eUCSS{œfieldNameœ:œinputsœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œRecordœ}", + "selected": false, + "source": "RecursiveCharacterTextSplitter-tR9QM", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œRecursiveCharacterTextSplitterœ, œidœ: œRecursiveCharacterTextSplitter-tR9QMœ}", + "style": { + "stroke": "#555" + }, + "target": "AstraDB-eUCSS", + "targetHandle": "{œfieldNameœ: œinputsœ, œidœ: œAstraDB-eUCSSœ, œinputTypesœ: null, œtypeœ: œRecordœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Embeddings" + ], + "dataType": "OpenAIEmbeddings", + "id": "OpenAIEmbeddings-9TPjc" + }, + "targetHandle": { + "fieldName": "embedding", + "id": "AstraDB-eUCSS", + "inputTypes": null, + "type": "Embeddings" + } + }, + "id": "reactflow__edge-OpenAIEmbeddings-9TPjc{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-9TPjcœ}-AstraDB-eUCSS{œfieldNameœ:œembeddingœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}", + "selected": false, + "source": "OpenAIEmbeddings-9TPjc", + "sourceHandle": "{œbaseClassesœ: [œEmbeddingsœ], œdataTypeœ: œOpenAIEmbeddingsœ, œidœ: œOpenAIEmbeddings-9TPjcœ}", + "style": { + "stroke": "#555" + }, + "target": "AstraDB-eUCSS", + "targetHandle": "{œfieldNameœ: œembeddingœ, œidœ: œAstraDB-eUCSSœ, œinputTypesœ: null, œtypeœ: œEmbeddingsœ}" + }, + { + "className": "stroke-gray-900 stroke-connection", + "data": { + "sourceHandle": { + "baseClasses": [ + "Record" + ], + "dataType": "AstraDBSearch", + "id": "AstraDBSearch-41nRz" + }, + "targetHandle": { + "fieldName": "input_value", + "id": "TextOutput-BDknO", + "inputTypes": [ + "Record", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-AstraDBSearch-41nRz{œbaseClassesœ:[œRecordœ],œdataTypeœ:œAstraDBSearchœ,œidœ:œAstraDBSearch-41nRzœ}-TextOutput-BDknO{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-BDknOœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", + "source": "AstraDBSearch-41nRz", + "sourceHandle": "{œbaseClassesœ: [œRecordœ], œdataTypeœ: œAstraDBSearchœ, œidœ: œAstraDBSearch-41nRzœ}", + "style": { + "stroke": "#555" + }, + "target": "TextOutput-BDknO", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œTextOutput-BDknOœ, œinputTypesœ: [œRecordœ, œTextœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { - "id": "ChatInput-yxMKE", - "type": "genericNode", - "position": { - "x": 1195.5276981160775, - "y": 209.421875 - }, "data": { - "type": "ChatInput", + "id": "ChatInput-yxMKE", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Message\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n ) -> Union[Text, Record]:\n return super().build_no_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": [], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "value": "what is a line" - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "Machine", - "User" - ], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "User", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "_type": "CustomComponent" - }, - "description": "Get chat inputs from the Playground.", - "icon": "ChatInput", "base_classes": [ "Text", "str", "object", "Record" ], - "display_name": "Chat Input", - "documentation": "", + "beta": false, "custom_fields": { + "input_value": null, + "return_record": null, "sender": null, "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null + "session_id": null }, - "output_types": [ - "Text", - "Record" - ], + "description": "Get chat inputs from the Playground.", + "display_name": "Chat Input", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false - }, - "id": "ChatInput-yxMKE" - }, - "selected": false, - "width": 384, - "height": 383 - }, - { - "id": "TextOutput-BDknO", - "type": "genericNode", - "position": { - "x": 2322.600672827879, - "y": 604.9467307442569 - }, - "data": { - "type": "TextOutput", - "node": { + "frozen": false, + "icon": "ChatInput", + "output_types": [ + "Message" + ], "template": { - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Value", - "advanced": false, - "input_types": [ - "Record", - "Text" - ], - "dynamic": false, - "info": "Text or Record to be passed as output.", - "load_from_db": false, - "title_case": false - }, + "_type": "CustomComponent", "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", "advanced": true, "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", "fileTypes": [], "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "info": "", + "list": false, "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n\n def build_config(self):\n build_config = super().build_config()\n build_config[\"input_value\"] = {\n \"input_types\": [],\n \"display_name\": \"Text\",\n \"multiline\": True,\n }\n\n return build_config\n\n def build(\n self,\n sender: Optional[str] = \"User\",\n sender_name: Optional[str] = \"User\",\n input_value: Optional[str] = None,\n files: Optional[list[str]] = None,\n session_id: Optional[str] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n files=files,\n session_id=session_id,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "what is a line" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", "input_types": [ "Text" - ] + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": [ + "Machine", + "User" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" }, - "_type": "CustomComponent" - }, - "description": "Display a text output in the Playground.", - "icon": "type", + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "User" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "ChatInput" + }, + "height": 383, + "id": "ChatInput-yxMKE", + "position": { + "x": 1195.5276981160775, + "y": 209.421875 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "TextOutput-BDknO", + "node": { "base_classes": [ "object", "Text", "str" ], - "display_name": "Extracted Chunks", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, "record_template": null }, + "description": "Display a text output in the Playground.", + "display_name": "Extracted Chunks", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "type", "output_types": [ "Text" ], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Text or Record to be passed as output.", + "input_types": [ + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "record_template": { + "advanced": true, + "display_name": "Record Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "record_template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "{text}" + } + } }, - "id": "TextOutput-BDknO" + "type": "TextOutput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 289, + "id": "TextOutput-BDknO", + "position": { + "x": 2322.600672827879, + "y": 604.9467307442569 + }, "positionAbsolute": { "x": 2322.600672827879, "y": 604.9467307442569 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIEmbeddings-ZlOk1", - "type": "genericNode", - "position": { - "x": 1183.667250865064, - "y": 687.3171828430261 - }, "data": { - "type": "OpenAIEmbeddings", + "id": "OpenAIEmbeddings-ZlOk1", "node": { - "template": { - "allowed_special": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": [], - "fileTypes": [], - "file_path": "", - "password": false, - "name": "allowed_special", - "display_name": "Allowed Special", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "chunk_size": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 1000, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "chunk_size", - "display_name": "Chunk Size", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "client": { - "type": "Any", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "client", - "display_name": "Client", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Dict, List, Optional\n\nfrom langchain_openai.embeddings.base import OpenAIEmbeddings\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, NestedDict\n\n\nclass OpenAIEmbeddingsComponent(CustomComponent):\n display_name = \"OpenAI Embeddings\"\n description = \"Generate embeddings using OpenAI models.\"\n\n def build_config(self):\n return {\n \"allowed_special\": {\n \"display_name\": \"Allowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"default_headers\": {\n \"display_name\": \"Default Headers\",\n \"advanced\": True,\n \"field_type\": \"dict\",\n },\n \"default_query\": {\n \"display_name\": \"Default Query\",\n \"advanced\": True,\n \"field_type\": \"NestedDict\",\n },\n \"disallowed_special\": {\n \"display_name\": \"Disallowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"advanced\": True},\n \"client\": {\"display_name\": \"Client\", \"advanced\": True},\n \"deployment\": {\"display_name\": \"Deployment\", \"advanced\": True},\n \"embedding_ctx_length\": {\n \"display_name\": \"Embedding Context Length\",\n \"advanced\": True,\n },\n \"max_retries\": {\"display_name\": \"Max Retries\", \"advanced\": True},\n \"model\": {\n \"display_name\": \"Model\",\n \"advanced\": False,\n \"options\": [\n \"text-embedding-3-small\",\n \"text-embedding-3-large\",\n \"text-embedding-ada-002\",\n ],\n },\n \"model_kwargs\": {\"display_name\": \"Model Kwargs\", \"advanced\": True},\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"password\": True,\n \"advanced\": True,\n },\n \"openai_api_key\": {\"display_name\": \"OpenAI API Key\", \"password\": True},\n \"openai_api_type\": {\n \"display_name\": \"OpenAI API Type\",\n \"advanced\": True,\n \"password\": True,\n },\n \"openai_api_version\": {\n \"display_name\": \"OpenAI API Version\",\n \"advanced\": True,\n },\n \"openai_organization\": {\n \"display_name\": \"OpenAI Organization\",\n \"advanced\": True,\n },\n \"openai_proxy\": {\"display_name\": \"OpenAI Proxy\", \"advanced\": True},\n \"request_timeout\": {\"display_name\": \"Request Timeout\", \"advanced\": True},\n \"show_progress_bar\": {\n \"display_name\": \"Show Progress Bar\",\n \"advanced\": True,\n },\n \"skip_empty\": {\"display_name\": \"Skip Empty\", \"advanced\": True},\n \"tiktoken_model_name\": {\n \"display_name\": \"TikToken Model Name\",\n \"advanced\": True,\n },\n \"tiktoken_enable\": {\"display_name\": \"TikToken Enable\", \"advanced\": True},\n }\n\n def build(\n self,\n openai_api_key: str,\n default_headers: Optional[Dict[str, str]] = None,\n default_query: Optional[NestedDict] = {},\n allowed_special: List[str] = [],\n disallowed_special: List[str] = [\"all\"],\n chunk_size: int = 1000,\n deployment: str = \"text-embedding-ada-002\",\n embedding_ctx_length: int = 8191,\n max_retries: int = 6,\n model: str = \"text-embedding-ada-002\",\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n openai_api_type: Optional[str] = None,\n openai_api_version: Optional[str] = None,\n openai_organization: Optional[str] = None,\n openai_proxy: Optional[str] = None,\n request_timeout: Optional[float] = None,\n show_progress_bar: bool = False,\n skip_empty: bool = False,\n tiktoken_enable: bool = True,\n tiktoken_model_name: Optional[str] = None,\n ) -> Embeddings:\n # This is to avoid errors with Vector Stores (e.g Chroma)\n if disallowed_special == [\"all\"]:\n disallowed_special = \"all\" # type: ignore\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n return OpenAIEmbeddings(\n tiktoken_enabled=tiktoken_enable,\n default_headers=default_headers,\n default_query=default_query,\n allowed_special=set(allowed_special),\n disallowed_special=\"all\",\n chunk_size=chunk_size,\n deployment=deployment,\n embedding_ctx_length=embedding_ctx_length,\n max_retries=max_retries,\n model=model,\n model_kwargs=model_kwargs,\n base_url=openai_api_base,\n api_key=api_key,\n openai_api_type=openai_api_type,\n api_version=openai_api_version,\n organization=openai_organization,\n openai_proxy=openai_proxy,\n timeout=request_timeout,\n show_progress_bar=show_progress_bar,\n skip_empty=skip_empty,\n tiktoken_model_name=tiktoken_model_name,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "default_headers": { - "type": "dict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "default_headers", - "display_name": "Default Headers", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "default_query": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "default_query", - "display_name": "Default Query", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "deployment": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "text-embedding-ada-002", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "deployment", - "display_name": "Deployment", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "disallowed_special": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": [ - "all" - ], - "fileTypes": [], - "file_path": "", - "password": false, - "name": "disallowed_special", - "display_name": "Disallowed Special", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "embedding_ctx_length": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 8191, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "embedding_ctx_length", - "display_name": "Embedding Context Length", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_retries": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 6, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_retries", - "display_name": "Max Retries", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "text-embedding-ada-002", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "text-embedding-3-small", - "text-embedding-3-large", - "text-embedding-ada-002" - ], - "name": "model", - "display_name": "Model", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": true, - "title_case": false, - "input_types": [ - "Text" - ], - "value": "OPENAI_API_KEY" - }, - "openai_api_type": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_type", - "display_name": "OpenAI API Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_api_version": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_version", - "display_name": "OpenAI API Version", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_organization": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_organization", - "display_name": "OpenAI Organization", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_proxy": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_proxy", - "display_name": "OpenAI Proxy", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "request_timeout": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "request_timeout", - "display_name": "Request Timeout", - "advanced": true, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "show_progress_bar": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "show_progress_bar", - "display_name": "Show Progress Bar", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "skip_empty": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "skip_empty", - "display_name": "Skip Empty", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "tiktoken_enable": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "tiktoken_enable", - "display_name": "TikToken Enable", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "tiktoken_model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "tiktoken_model_name", - "display_name": "TikToken Model Name", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "_type": "CustomComponent" - }, - "description": "Generate embeddings using OpenAI models.", "base_classes": [ "Embeddings" ], - "display_name": "OpenAI Embeddings", - "documentation": "", + "beta": false, "custom_fields": { - "openai_api_key": null, - "default_headers": null, - "default_query": null, "allowed_special": null, - "disallowed_special": null, "chunk_size": null, "client": null, + "default_headers": null, + "default_query": null, "deployment": null, + "disallowed_special": null, "embedding_ctx_length": null, "max_retries": null, "model": null, "model_kwargs": null, "openai_api_base": null, + "openai_api_key": null, "openai_api_type": null, "openai_api_version": null, "openai_organization": null, @@ -797,273 +597,512 @@ "tiktoken_enable": null, "tiktoken_model_name": null }, + "description": "Generate embeddings using OpenAI models.", + "display_name": "OpenAI Embeddings", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, "output_types": [ "Embeddings" ], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false - }, - "id": "OpenAIEmbeddings-ZlOk1" - }, - "selected": false, - "width": 384, - "height": 383, - "dragging": false - }, - { - "id": "OpenAIModel-EjXlN", - "type": "genericNode", - "position": { - "x": 3410.117202077183, - "y": 431.2038048137648 - }, - "data": { - "type": "OpenAIModel", - "node": { "template": { - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "_type": "CustomComponent", + "allowed_special": { + "advanced": true, + "display_name": "Allowed Special", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input", - "advanced": false, - "dynamic": false, "info": "", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" - ] + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "allowed_special", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": [] + }, + "chunk_size": { + "advanced": true, + "display_name": "Chunk Size", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "chunk_size", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 1000 }, "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\"},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-4o\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", "advanced": true, "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_tokens": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 256, "fileTypes": [], "file_path": "", - "password": false, - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "info": "", + "list": false, "load_from_db": false, - "title_case": false + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Dict, List, Optional\n\nfrom langchain_openai.embeddings.base import OpenAIEmbeddings\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, NestedDict\n\n\nclass OpenAIEmbeddingsComponent(CustomComponent):\n display_name = \"OpenAI Embeddings\"\n description = \"Generate embeddings using OpenAI models.\"\n\n def build_config(self):\n return {\n \"allowed_special\": {\n \"display_name\": \"Allowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"default_headers\": {\n \"display_name\": \"Default Headers\",\n \"advanced\": True,\n \"field_type\": \"dict\",\n },\n \"default_query\": {\n \"display_name\": \"Default Query\",\n \"advanced\": True,\n \"field_type\": \"NestedDict\",\n },\n \"disallowed_special\": {\n \"display_name\": \"Disallowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"advanced\": True},\n \"client\": {\"display_name\": \"Client\", \"advanced\": True},\n \"deployment\": {\"display_name\": \"Deployment\", \"advanced\": True},\n \"embedding_ctx_length\": {\n \"display_name\": \"Embedding Context Length\",\n \"advanced\": True,\n },\n \"max_retries\": {\"display_name\": \"Max Retries\", \"advanced\": True},\n \"model\": {\n \"display_name\": \"Model\",\n \"advanced\": False,\n \"options\": [\n \"text-embedding-3-small\",\n \"text-embedding-3-large\",\n \"text-embedding-ada-002\",\n ],\n },\n \"model_kwargs\": {\"display_name\": \"Model Kwargs\", \"advanced\": True},\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"password\": True,\n \"advanced\": True,\n },\n \"openai_api_key\": {\"display_name\": \"OpenAI API Key\", \"password\": True},\n \"openai_api_type\": {\n \"display_name\": \"OpenAI API Type\",\n \"advanced\": True,\n \"password\": True,\n },\n \"openai_api_version\": {\n \"display_name\": \"OpenAI API Version\",\n \"advanced\": True,\n },\n \"openai_organization\": {\n \"display_name\": \"OpenAI Organization\",\n \"advanced\": True,\n },\n \"openai_proxy\": {\"display_name\": \"OpenAI Proxy\", \"advanced\": True},\n \"request_timeout\": {\"display_name\": \"Request Timeout\", \"advanced\": True},\n \"show_progress_bar\": {\n \"display_name\": \"Show Progress Bar\",\n \"advanced\": True,\n },\n \"skip_empty\": {\"display_name\": \"Skip Empty\", \"advanced\": True},\n \"tiktoken_model_name\": {\n \"display_name\": \"TikToken Model Name\",\n \"advanced\": True,\n },\n \"tiktoken_enable\": {\"display_name\": \"TikToken Enable\", \"advanced\": True},\n }\n\n def build(\n self,\n openai_api_key: str,\n default_headers: Optional[Dict[str, str]] = None,\n default_query: Optional[NestedDict] = {},\n allowed_special: List[str] = [],\n disallowed_special: List[str] = [\"all\"],\n chunk_size: int = 1000,\n deployment: str = \"text-embedding-ada-002\",\n embedding_ctx_length: int = 8191,\n max_retries: int = 6,\n model: str = \"text-embedding-ada-002\",\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n openai_api_type: Optional[str] = None,\n openai_api_version: Optional[str] = None,\n openai_organization: Optional[str] = None,\n openai_proxy: Optional[str] = None,\n request_timeout: Optional[float] = None,\n show_progress_bar: bool = False,\n skip_empty: bool = False,\n tiktoken_enable: bool = True,\n tiktoken_model_name: Optional[str] = None,\n ) -> Embeddings:\n # This is to avoid errors with Vector Stores (e.g Chroma)\n if disallowed_special == [\"all\"]:\n disallowed_special = \"all\" # type: ignore\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n return OpenAIEmbeddings(\n tiktoken_enabled=tiktoken_enable,\n default_headers=default_headers,\n default_query=default_query,\n allowed_special=set(allowed_special),\n disallowed_special=\"all\",\n chunk_size=chunk_size,\n deployment=deployment,\n embedding_ctx_length=embedding_ctx_length,\n max_retries=max_retries,\n model=model,\n model_kwargs=model_kwargs,\n base_url=openai_api_base,\n api_key=api_key,\n openai_api_type=openai_api_type,\n api_version=openai_api_version,\n organization=openai_organization,\n openai_proxy=openai_proxy,\n timeout=request_timeout,\n show_progress_bar=show_progress_bar,\n skip_empty=skip_empty,\n tiktoken_model_name=tiktoken_model_name,\n )\n" + }, + "default_headers": { + "advanced": true, + "display_name": "Default Headers", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "default_headers", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict" + }, + "default_query": { + "advanced": true, + "display_name": "Default Query", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "default_query", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "deployment": { + "advanced": true, + "display_name": "Deployment", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "deployment", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "text-embedding-ada-002" + }, + "disallowed_special": { + "advanced": true, + "display_name": "Disallowed Special", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "disallowed_special", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": [ + "all" + ] + }, + "embedding_ctx_length": { + "advanced": true, + "display_name": "Embedding Context Length", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "embedding_ctx_length", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 8191 + }, + "max_retries": { + "advanced": true, + "display_name": "Max Retries", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_retries", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 6 + }, + "model": { + "advanced": false, + "display_name": "Model", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model", + "options": [ + "text-embedding-3-small", + "text-embedding-3-large", + "text-embedding-ada-002" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "text-embedding-ada-002" }, "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", "advanced": true, + "display_name": "Model Kwargs", "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "gpt-3.5-turbo", "fileTypes": [], "file_path": "", - "password": false, - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, "info": "", + "list": false, "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, "title_case": false, - "input_types": [ - "Text" - ] + "type": "NestedDict", + "value": {} }, "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_base", - "display_name": "OpenAI API Base", "advanced": true, + "display_name": "OpenAI API Base", "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, "fileTypes": [], "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "load_from_db": true, - "title_case": false, + "info": "", "input_types": [ "Text" ], - "value": "OPENAI_API_KEY" - }, - "stream": { - "type": "bool", - "required": false, - "placeholder": "", "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", "load_from_db": false, - "title_case": false - }, - "system_message": { - "type": "str", - "required": false, + "multiline": false, + "name": "openai_api_base", + "password": true, "placeholder": "", - "list": false, + "required": false, "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "load_from_db": false, "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", "input_types": [ "Text" - ] - }, - "temperature": { - "type": "float", - "required": false, - "placeholder": "", + ], "list": false, - "show": true, + "load_from_db": true, "multiline": false, - "value": 0.1, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "openai_api_type": { + "advanced": true, + "display_name": "OpenAI API Type", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, + "input_types": [ + "Text" + ], + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "openai_api_type", + "password": true, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" }, - "_type": "CustomComponent" - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", + "openai_api_version": { + "advanced": true, + "display_name": "OpenAI API Version", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_version", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_organization": { + "advanced": true, + "display_name": "OpenAI Organization", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_organization", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_proxy": { + "advanced": true, + "display_name": "OpenAI Proxy", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_proxy", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "request_timeout": { + "advanced": true, + "display_name": "Request Timeout", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "request_timeout", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float" + }, + "show_progress_bar": { + "advanced": true, + "display_name": "Show Progress Bar", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "show_progress_bar", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "skip_empty": { + "advanced": true, + "display_name": "Skip Empty", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "skip_empty", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "tiktoken_enable": { + "advanced": true, + "display_name": "TikToken Enable", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "tiktoken_enable", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": true + }, + "tiktoken_model_name": { + "advanced": true, + "display_name": "TikToken Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "tiktoken_model_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } + }, + "type": "OpenAIEmbeddings" + }, + "dragging": false, + "height": 383, + "id": "OpenAIEmbeddings-ZlOk1", + "position": { + "x": 1183.667250865064, + "y": 687.3171828430261 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "OpenAIModel-EjXlN", + "node": { "base_classes": [ "object", "Text", "str" ], - "display_name": "OpenAI", - "documentation": "", + "beta": false, "custom_fields": { "input_value": null, - "openai_api_key": null, - "temperature": null, - "model_name": null, "max_tokens": null, "model_kwargs": null, + "model_name": null, "openai_api_base": null, + "openai_api_key": null, "stream": null, - "system_message": null + "system_message": null, + "temperature": null }, - "output_types": [ - "Text" - ], + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "max_tokens", "model_kwargs", @@ -1075,384 +1114,599 @@ "system_message", "stream" ], - "beta": false + "frozen": false, + "icon": "OpenAI", + "output_types": [ + "Text" + ], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import NestedDict, Text\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n field_order = [\n \"max_tokens\",\n \"model_kwargs\",\n \"model_name\",\n \"openai_api_base\",\n \"openai_api_key\",\n \"temperature\",\n \"input_value\",\n \"system_message\",\n \"stream\",\n ]\n\n def build_config(self):\n return {\n \"input_value\": {\"display_name\": \"Input\", \"input_types\": [\"Text\", \"Record\", \"Prompt\"]},\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"advanced\": True,\n \"info\": \"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"advanced\": True,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"advanced\": False,\n \"options\": MODEL_NAMES,\n },\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"advanced\": True,\n \"info\": (\n \"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\\n\\n\"\n \"You can change this to use other APIs like JinaChat, LocalAI and Prem.\"\n ),\n },\n \"openai_api_key\": {\n \"display_name\": \"OpenAI API Key\",\n \"info\": \"The OpenAI API Key to use for the OpenAI model.\",\n \"advanced\": False,\n \"password\": True,\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"advanced\": False,\n \"value\": 0.1,\n },\n \"stream\": {\n \"display_name\": \"Stream\",\n \"info\": STREAM_INFO_TEXT,\n \"advanced\": True,\n },\n \"system_message\": {\n \"display_name\": \"System Message\",\n \"info\": \"System message to pass to the model.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n input_value: Text,\n openai_api_key: str,\n temperature: float = 0.1,\n model_name: str = \"gpt-3.5-turbo\",\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n stream: bool = False,\n system_message: Optional[str] = None,\n ) -> Text:\n if not openai_api_base:\n openai_api_base = \"https://api.openai.com/v1\"\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature,\n )\n\n return self.get_chat_result(output, stream, input_value, system_message)\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text", + "Record", + "Prompt" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_tokens", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 256 + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-3.5-turbo" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "stream", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "System message to pass to the model.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "system_message", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "temperature", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } }, - "id": "OpenAIModel-EjXlN" + "type": "OpenAIModel" }, - "selected": true, - "width": 384, + "dragging": false, "height": 563, + "id": "OpenAIModel-EjXlN", + "position": { + "x": 3410.117202077183, + "y": 431.2038048137648 + }, "positionAbsolute": { "x": 3410.117202077183, "y": 431.2038048137648 }, - "dragging": false + "selected": true, + "type": "genericNode", + "width": 384 }, { - "id": "Prompt-xeI6K", - "type": "genericNode", - "position": { - "x": 2969.0261961391298, - "y": 442.1613649809069 - }, "data": { - "type": "Prompt", + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "id": "Prompt-xeI6K", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langchain_core.prompts import PromptTemplate\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Prompt, TemplateField, Text\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Text:\n from langflow.base.prompts.utils import dict_values_to_string\n\n prompt_template = PromptTemplate.from_template(Text(template))\n kwargs = dict_values_to_string(kwargs)\n kwargs = {k: \"\\n\".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}\n try:\n formated_prompt = prompt_template.format(**kwargs)\n except Exception as exc:\n raise ValueError(f\"Error formatting prompt: {exc}\") from exc\n self.status = f'Prompt:\\n\"{formated_prompt}\"'\n return formated_prompt\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "template": { - "type": "prompt", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "{context}\n\n---\n\nGiven the context above, answer the question as best as possible.\n\nQuestion: {question}\n\nAnswer: ", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "template", - "display_name": "Template", - "advanced": false, - "input_types": [ - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent", - "context": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "context", - "display_name": "context", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - }, - "question": { - "field_type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "question", - "display_name": "question", - "advanced": false, - "input_types": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "type": "str" - } - }, - "description": "Create a prompt template with dynamic variables.", - "icon": "prompts", - "is_input": null, - "is_output": null, - "is_composition": null, "base_classes": [ "object", "Text", "str" ], - "name": "", - "display_name": "Prompt", - "documentation": "", + "beta": false, "custom_fields": { "template": [ "context", "question" ] }, - "output_types": [ - "Text" - ], - "full_path": null, + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt", + "documentation": "", + "error": null, "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false, - "error": null + "frozen": false, + "full_path": null, + "icon": "prompts", + "is_composition": null, + "is_input": null, + "is_output": null, + "name": "", + "output_types": [ + "Prompt" + ], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n" + }, + "context": { + "advanced": false, + "display_name": "context", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "context", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "question": { + "advanced": false, + "display_name": "question", + "dynamic": false, + "field_type": "str", + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "question", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "template": { + "advanced": false, + "display_name": "Template", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "template", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "prompt", + "value": "{context}\n\n---\n\nGiven the context above, answer the question as best as possible.\n\nQuestion: {question}\n\nAnswer: " + } + } }, - "id": "Prompt-xeI6K", - "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" + "type": "Prompt" }, - "selected": false, - "width": 384, + "dragging": false, "height": 477, + "id": "Prompt-xeI6K", + "position": { + "x": 2969.0261961391298, + "y": 442.1613649809069 + }, "positionAbsolute": { "x": 2969.0261961391298, "y": 442.1613649809069 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "ChatOutput-Q39I8", - "type": "genericNode", - "position": { - "x": 3887.2073667611485, - "y": 588.4801225794856 - }, "data": { - "type": "ChatOutput", + "id": "ChatOutput-Q39I8", "node": { - "template": { - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Optional, Union\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.field_typing import Text\nfrom langflow.schema import Record\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n return_record: Optional[bool] = False,\n record_template: Optional[str] = \"{text}\",\n ) -> Union[Text, Record]:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n return_record=return_record,\n record_template=record_template or \"\",\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Message", - "advanced": false, - "input_types": [ - "Text" - ], - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "record_template": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "{text}", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "record_template", - "display_name": "Record Template", - "advanced": true, - "dynamic": false, - "info": "In case of Message being a Record, this template will be used to convert it to text.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "return_record": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "return_record", - "display_name": "Return Record", - "advanced": true, - "dynamic": false, - "info": "Return the message as a record containing the sender, sender_name, and session_id.", - "load_from_db": false, - "title_case": false - }, - "sender": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Machine", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "Machine", - "User" - ], - "name": "sender", - "display_name": "Sender Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "sender_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "AI", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "sender_name", - "display_name": "Sender Name", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "session_id": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "session_id", - "display_name": "Session ID", - "advanced": true, - "dynamic": false, - "info": "If provided, the message will be stored in the memory.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "_type": "CustomComponent" - }, - "description": "Display a chat message in the Playground.", - "icon": "ChatOutput", "base_classes": [ "object", "Text", "Record", "str" ], - "display_name": "Chat Output", - "documentation": "", + "beta": false, "custom_fields": { + "input_value": null, + "record_template": null, + "return_record": null, "sender": null, "sender_name": null, - "input_value": null, - "session_id": null, - "return_record": null, - "record_template": null + "session_id": null }, - "output_types": [ - "Text", - "Record" - ], + "description": "Display a chat message in the Playground.", + "display_name": "Chat Output", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [], - "beta": false + "frozen": false, + "icon": "ChatOutput", + "output_types": [ + "Message" + ], + "template": { + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n\n def build(\n self,\n sender: Optional[str] = \"Machine\",\n sender_name: Optional[str] = \"AI\",\n input_value: Optional[str] = None,\n session_id: Optional[str] = None,\n files: Optional[list[str]] = None,\n ) -> Message:\n return super().build_with_record(\n sender=sender,\n sender_name=sender_name,\n input_value=input_value,\n session_id=session_id,\n files=files,\n )\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": true, + "name": "input_value", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "sender": { + "advanced": true, + "display_name": "Sender Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "sender", + "options": [ + "Machine", + "User" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Machine" + }, + "sender_name": { + "advanced": false, + "display_name": "Sender Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "sender_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "AI" + }, + "session_id": { + "advanced": true, + "display_name": "Session ID", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "If provided, the message will be stored in the memory.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "session_id", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } }, - "id": "ChatOutput-Q39I8" + "type": "ChatOutput" }, - "selected": false, - "width": 384, + "dragging": false, "height": 383, + "id": "ChatOutput-Q39I8", + "position": { + "x": 3887.2073667611485, + "y": 588.4801225794856 + }, "positionAbsolute": { "x": 3887.2073667611485, "y": 588.4801225794856 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "File-t0a6a", - "type": "genericNode", - "position": { - "x": 2257.233450682836, - "y": 1747.5389618367233 - }, "data": { - "type": "File", + "id": "File-t0a6a", "node": { + "base_classes": [ + "Record" + ], + "beta": false, + "custom_fields": { + "path": null, + "silent_errors": null + }, + "description": "A generic file loader.", + "display_name": "File", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "icon": "file-text", + "output_types": [ + "Record" + ], "template": { - "path": { - "type": "file", - "required": true, - "placeholder": "", + "_type": "CustomComponent", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, "show": true, - "multiline": false, + "title_case": false, + "type": "code", + "value": "from pathlib import Path\nfrom typing import Any, Dict\n\nfrom langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass FileComponent(CustomComponent):\n display_name = \"File\"\n description = \"A generic file loader.\"\n icon = \"file-text\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"path\": {\n \"display_name\": \"Path\",\n \"field_type\": \"file\",\n \"file_types\": TEXT_FILE_TYPES,\n \"info\": f\"Supported file types: {', '.join(TEXT_FILE_TYPES)}\",\n },\n \"silent_errors\": {\n \"display_name\": \"Silent Errors\",\n \"advanced\": True,\n \"info\": \"If true, errors will not raise an exception.\",\n },\n }\n\n def load_file(self, path: str, silent_errors: bool = False) -> Record:\n resolved_path = self.resolve_path(path)\n path_obj = Path(resolved_path)\n extension = path_obj.suffix[1:].lower()\n if extension == \"doc\":\n raise ValueError(\"doc files are not supported. Please save as .docx\")\n if extension not in TEXT_FILE_TYPES:\n raise ValueError(f\"Unsupported file type: {extension}\")\n record = parse_text_file_to_record(resolved_path, silent_errors)\n self.status = record if record else \"No data\"\n return record or Record()\n\n def build(\n self,\n path: str,\n silent_errors: bool = False,\n ) -> Record:\n record = self.load_file(path, silent_errors)\n self.status = record\n return record\n" + }, + "path": { + "advanced": false, + "display_name": "Path", + "dynamic": false, "fileTypes": [ ".txt", ".md", @@ -1474,664 +1728,235 @@ ".tsx" ], "file_path": "51e2b78a-199b-4054-9f32-e288eef6924c/Langflow conversation.pdf", - "password": false, - "name": "path", - "display_name": "Path", - "advanced": false, - "dynamic": false, "info": "Supported file types: txt, md, mdx, csv, json, yaml, yml, xml, html, htm, pdf, docx, py, sh, sql, js, ts, tsx", + "list": false, "load_from_db": false, + "multiline": false, + "name": "path", + "password": false, + "placeholder": "", + "required": true, + "show": true, "title_case": false, + "type": "file", "value": "" }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from pathlib import Path\nfrom typing import Any, Dict\n\nfrom langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\n\n\nclass FileComponent(CustomComponent):\n display_name = \"File\"\n description = \"A generic file loader.\"\n icon = \"file-text\"\n\n def build_config(self) -> Dict[str, Any]:\n return {\n \"path\": {\n \"display_name\": \"Path\",\n \"field_type\": \"file\",\n \"file_types\": TEXT_FILE_TYPES,\n \"info\": f\"Supported file types: {', '.join(TEXT_FILE_TYPES)}\",\n },\n \"silent_errors\": {\n \"display_name\": \"Silent Errors\",\n \"advanced\": True,\n \"info\": \"If true, errors will not raise an exception.\",\n },\n }\n\n def load_file(self, path: str, silent_errors: bool = False) -> Record:\n resolved_path = self.resolve_path(path)\n path_obj = Path(resolved_path)\n extension = path_obj.suffix[1:].lower()\n if extension == \"doc\":\n raise ValueError(\"doc files are not supported. Please save as .docx\")\n if extension not in TEXT_FILE_TYPES:\n raise ValueError(f\"Unsupported file type: {extension}\")\n record = parse_text_file_to_record(resolved_path, silent_errors)\n self.status = record if record else \"No data\"\n return record or Record()\n\n def build(\n self,\n path: str,\n silent_errors: bool = False,\n ) -> Record:\n record = self.load_file(path, silent_errors)\n self.status = record\n return record\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, "silent_errors": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, + "advanced": true, + "display_name": "Silent Errors", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "silent_errors", - "display_name": "Silent Errors", - "advanced": true, - "dynamic": false, "info": "If true, errors will not raise an exception.", + "list": false, "load_from_db": false, - "title_case": false - }, - "_type": "CustomComponent" - }, - "description": "A generic file loader.", - "icon": "file-text", - "base_classes": [ - "Record" - ], - "display_name": "File", - "documentation": "", - "custom_fields": { - "path": null, - "silent_errors": null - }, - "output_types": [ - "Record" - ], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false + "multiline": false, + "name": "silent_errors", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + } + } }, - "id": "File-t0a6a" + "type": "File" }, - "selected": false, - "width": 384, + "dragging": false, "height": 281, + "id": "File-t0a6a", + "position": { + "x": 2257.233450682836, + "y": 1747.5389618367233 + }, "positionAbsolute": { "x": 2257.233450682836, "y": 1747.5389618367233 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "RecursiveCharacterTextSplitter-tR9QM", - "type": "genericNode", - "position": { - "x": 2791.013514133929, - "y": 1462.9588953494142 - }, "data": { - "type": "RecursiveCharacterTextSplitter", + "id": "RecursiveCharacterTextSplitter-tR9QM", "node": { + "base_classes": [ + "Record" + ], + "beta": false, + "custom_fields": { + "chunk_overlap": null, + "chunk_size": null, + "inputs": null, + "separators": null + }, + "description": "Split text into chunks of a specified length.", + "display_name": "Recursive Character Text Splitter", + "documentation": "https://docs.langflow.org/components/text-splitters#recursivecharactertextsplitter", + "field_formatters": {}, + "field_order": [], + "frozen": false, + "output_types": [ + "Record" + ], "template": { - "inputs": { - "type": "Document", - "required": true, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, + "_type": "CustomComponent", + "chunk_overlap": { + "advanced": false, + "display_name": "Chunk Overlap", + "dynamic": false, "fileTypes": [], "file_path": "", + "info": "The amount of overlap between chunks.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "chunk_overlap", "password": false, - "name": "inputs", - "display_name": "Input", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 200 + }, + "chunk_size": { "advanced": false, + "display_name": "Chunk Size", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The maximum length of each chunk.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "chunk_size", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 1000 + }, + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Optional\n\nfrom langchain_core.documents import Document\nfrom langchain_text_splitters import RecursiveCharacterTextSplitter\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\nfrom langflow.utils.util import build_loader_repr_from_records, unescape_string\n\n\nclass RecursiveCharacterTextSplitterComponent(CustomComponent):\n display_name: str = \"Recursive Character Text Splitter\"\n description: str = \"Split text into chunks of a specified length.\"\n documentation: str = \"https://docs.langflow.org/components/text-splitters#recursivecharactertextsplitter\"\n\n def build_config(self):\n return {\n \"inputs\": {\n \"display_name\": \"Input\",\n \"info\": \"The texts to split.\",\n \"input_types\": [\"Document\", \"Record\"],\n },\n \"separators\": {\n \"display_name\": \"Separators\",\n \"info\": 'The characters to split on.\\nIf left empty defaults to [\"\\\\n\\\\n\", \"\\\\n\", \" \", \"\"].',\n \"is_list\": True,\n },\n \"chunk_size\": {\n \"display_name\": \"Chunk Size\",\n \"info\": \"The maximum length of each chunk.\",\n \"field_type\": \"int\",\n \"value\": 1000,\n },\n \"chunk_overlap\": {\n \"display_name\": \"Chunk Overlap\",\n \"info\": \"The amount of overlap between chunks.\",\n \"field_type\": \"int\",\n \"value\": 200,\n },\n \"code\": {\"show\": False},\n }\n\n def build(\n self,\n inputs: list[Document],\n separators: Optional[list[str]] = None,\n chunk_size: Optional[int] = 1000,\n chunk_overlap: Optional[int] = 200,\n ) -> list[Record]:\n \"\"\"\n Split text into chunks of a specified length.\n\n Args:\n separators (list[str]): The characters to split on.\n chunk_size (int): The maximum length of each chunk.\n chunk_overlap (int): The amount of overlap between chunks.\n length_function (function): The function to use to calculate the length of the text.\n\n Returns:\n list[str]: The chunks of text.\n \"\"\"\n\n if separators == \"\":\n separators = None\n elif separators:\n # check if the separators list has escaped characters\n # if there are escaped characters, unescape them\n separators = [unescape_string(x) for x in separators]\n\n # Make sure chunk_size and chunk_overlap are ints\n if isinstance(chunk_size, str):\n chunk_size = int(chunk_size)\n if isinstance(chunk_overlap, str):\n chunk_overlap = int(chunk_overlap)\n splitter = RecursiveCharacterTextSplitter(\n separators=separators,\n chunk_size=chunk_size,\n chunk_overlap=chunk_overlap,\n )\n documents = []\n for _input in inputs:\n if isinstance(_input, Record):\n documents.append(_input.to_lc_document())\n else:\n documents.append(_input)\n docs = splitter.split_documents(documents)\n records = self.to_records(docs)\n self.repr_value = build_loader_repr_from_records(records)\n return records\n" + }, + "inputs": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The texts to split.", "input_types": [ "Document", "Record" ], - "dynamic": false, - "info": "The texts to split.", + "list": true, "load_from_db": false, - "title_case": false - }, - "chunk_overlap": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, "multiline": false, - "value": 200, - "fileTypes": [], - "file_path": "", + "name": "inputs", "password": false, - "name": "chunk_overlap", - "display_name": "Chunk Overlap", - "advanced": false, - "dynamic": false, - "info": "The amount of overlap between chunks.", - "load_from_db": false, - "title_case": false - }, - "chunk_size": { - "type": "int", - "required": false, "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 1000, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "chunk_size", - "display_name": "Chunk Size", - "advanced": false, - "dynamic": false, - "info": "The maximum length of each chunk.", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", "required": true, - "placeholder": "", - "list": false, "show": true, - "multiline": true, - "value": "from typing import Optional\n\nfrom langchain_core.documents import Document\nfrom langchain_text_splitters import RecursiveCharacterTextSplitter\n\nfrom langflow.custom import CustomComponent\nfrom langflow.schema import Record\nfrom langflow.utils.util import build_loader_repr_from_records, unescape_string\n\n\nclass RecursiveCharacterTextSplitterComponent(CustomComponent):\n display_name: str = \"Recursive Character Text Splitter\"\n description: str = \"Split text into chunks of a specified length.\"\n documentation: str = \"https://docs.langflow.org/components/text-splitters#recursivecharactertextsplitter\"\n\n def build_config(self):\n return {\n \"inputs\": {\n \"display_name\": \"Input\",\n \"info\": \"The texts to split.\",\n \"input_types\": [\"Document\", \"Record\"],\n },\n \"separators\": {\n \"display_name\": \"Separators\",\n \"info\": 'The characters to split on.\\nIf left empty defaults to [\"\\\\n\\\\n\", \"\\\\n\", \" \", \"\"].',\n \"is_list\": True,\n },\n \"chunk_size\": {\n \"display_name\": \"Chunk Size\",\n \"info\": \"The maximum length of each chunk.\",\n \"field_type\": \"int\",\n \"value\": 1000,\n },\n \"chunk_overlap\": {\n \"display_name\": \"Chunk Overlap\",\n \"info\": \"The amount of overlap between chunks.\",\n \"field_type\": \"int\",\n \"value\": 200,\n },\n \"code\": {\"show\": False},\n }\n\n def build(\n self,\n inputs: list[Document],\n separators: Optional[list[str]] = None,\n chunk_size: Optional[int] = 1000,\n chunk_overlap: Optional[int] = 200,\n ) -> list[Record]:\n \"\"\"\n Split text into chunks of a specified length.\n\n Args:\n separators (list[str]): The characters to split on.\n chunk_size (int): The maximum length of each chunk.\n chunk_overlap (int): The amount of overlap between chunks.\n length_function (function): The function to use to calculate the length of the text.\n\n Returns:\n list[str]: The chunks of text.\n \"\"\"\n\n if separators == \"\":\n separators = None\n elif separators:\n # check if the separators list has escaped characters\n # if there are escaped characters, unescape them\n separators = [unescape_string(x) for x in separators]\n\n # Make sure chunk_size and chunk_overlap are ints\n if isinstance(chunk_size, str):\n chunk_size = int(chunk_size)\n if isinstance(chunk_overlap, str):\n chunk_overlap = int(chunk_overlap)\n splitter = RecursiveCharacterTextSplitter(\n separators=separators,\n chunk_size=chunk_size,\n chunk_overlap=chunk_overlap,\n )\n documents = []\n for _input in inputs:\n if isinstance(_input, Record):\n documents.append(_input.to_lc_document())\n else:\n documents.append(_input)\n docs = splitter.split_documents(documents)\n records = self.to_records(docs)\n self.repr_value = build_loader_repr_from_records(records)\n return records\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false + "title_case": false, + "type": "Document" }, "separators": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, + "advanced": false, + "display_name": "Separators", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "separators", - "display_name": "Separators", - "advanced": false, - "dynamic": false, "info": "The characters to split on.\nIf left empty defaults to [\"\\n\\n\", \"\\n\", \" \", \"\"].", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "separators", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", "value": [ "" ] - }, - "_type": "CustomComponent" - }, - "description": "Split text into chunks of a specified length.", - "base_classes": [ - "Record" - ], - "display_name": "Recursive Character Text Splitter", - "documentation": "https://docs.langflow.org/components/text-splitters#recursivecharactertextsplitter", - "custom_fields": { - "inputs": null, - "separators": null, - "chunk_size": null, - "chunk_overlap": null - }, - "output_types": [ - "Record" - ], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false + } + } }, - "id": "RecursiveCharacterTextSplitter-tR9QM" + "type": "RecursiveCharacterTextSplitter" }, - "selected": false, - "width": 384, + "dragging": false, "height": 501, + "id": "RecursiveCharacterTextSplitter-tR9QM", + "position": { + "x": 2791.013514133929, + "y": 1462.9588953494142 + }, "positionAbsolute": { "x": 2791.013514133929, "y": 1462.9588953494142 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "AstraDBSearch-41nRz", - "type": "genericNode", - "position": { - "x": 1723.976434815103, - "y": 277.03317407245913 - }, "data": { - "type": "AstraDBSearch", + "id": "AstraDBSearch-41nRz", "node": { - "template": { - "embedding": { - "type": "Embeddings", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "embedding", - "display_name": "Embedding", - "advanced": false, - "dynamic": false, - "info": "Embedding to use", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "input_value", - "display_name": "Input Value", - "advanced": false, - "dynamic": false, - "info": "Input value to search", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "api_endpoint": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "api_endpoint", - "display_name": "API Endpoint", - "advanced": false, - "dynamic": false, - "info": "API endpoint URL for the Astra DB service.", - "load_from_db": true, - "title_case": false, - "input_types": [ - "Text" - ], - "value": "ASTRA_DB_API_ENDPOINT" - }, - "batch_size": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "batch_size", - "display_name": "Batch Size", - "advanced": true, - "dynamic": false, - "info": "Optional number of records to process in a single batch.", - "load_from_db": false, - "title_case": false - }, - "bulk_delete_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "bulk_delete_concurrency", - "display_name": "Bulk Delete Concurrency", - "advanced": true, - "dynamic": false, - "info": "Optional concurrency level for bulk delete operations.", - "load_from_db": false, - "title_case": false - }, - "bulk_insert_batch_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "bulk_insert_batch_concurrency", - "display_name": "Bulk Insert Batch Concurrency", - "advanced": true, - "dynamic": false, - "info": "Optional concurrency level for bulk insert operations.", - "load_from_db": false, - "title_case": false - }, - "bulk_insert_overwrite_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "bulk_insert_overwrite_concurrency", - "display_name": "Bulk Insert Overwrite Concurrency", - "advanced": true, - "dynamic": false, - "info": "Optional concurrency level for bulk insert operations that overwrite existing records.", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import List, Optional\n\nfrom langflow.components.vectorstores.AstraDB import AstraDBVectorStoreComponent\nfrom langflow.components.vectorstores.base.model import LCVectorStoreComponent\nfrom langflow.field_typing import Embeddings, Text\nfrom langflow.schema import Record\n\n\nclass AstraDBSearchComponent(LCVectorStoreComponent):\n display_name = \"Astra DB Search\"\n description = \"Searches an existing Astra DB Vector Store.\"\n icon = \"AstraDB\"\n field_order = [\"token\", \"api_endpoint\", \"collection_name\", \"input_value\", \"embedding\"]\n\n def build_config(self):\n return {\n \"search_type\": {\n \"display_name\": \"Search Type\",\n \"options\": [\"Similarity\", \"MMR\"],\n },\n \"input_value\": {\n \"display_name\": \"Input Value\",\n \"info\": \"Input value to search\",\n },\n \"embedding\": {\"display_name\": \"Embedding\", \"info\": \"Embedding to use\"},\n \"collection_name\": {\n \"display_name\": \"Collection Name\",\n \"info\": \"The name of the collection within Astra DB where the vectors will be stored.\",\n },\n \"token\": {\n \"display_name\": \"Token\",\n \"info\": \"Authentication token for accessing Astra DB.\",\n \"password\": True,\n },\n \"api_endpoint\": {\n \"display_name\": \"API Endpoint\",\n \"info\": \"API endpoint URL for the Astra DB service.\",\n },\n \"namespace\": {\n \"display_name\": \"Namespace\",\n \"info\": \"Optional namespace within Astra DB to use for the collection.\",\n \"advanced\": True,\n },\n \"metric\": {\n \"display_name\": \"Metric\",\n \"info\": \"Optional distance metric for vector comparisons in the vector store.\",\n \"advanced\": True,\n },\n \"batch_size\": {\n \"display_name\": \"Batch Size\",\n \"info\": \"Optional number of records to process in a single batch.\",\n \"advanced\": True,\n },\n \"bulk_insert_batch_concurrency\": {\n \"display_name\": \"Bulk Insert Batch Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations.\",\n \"advanced\": True,\n },\n \"bulk_insert_overwrite_concurrency\": {\n \"display_name\": \"Bulk Insert Overwrite Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations that overwrite existing records.\",\n \"advanced\": True,\n },\n \"bulk_delete_concurrency\": {\n \"display_name\": \"Bulk Delete Concurrency\",\n \"info\": \"Optional concurrency level for bulk delete operations.\",\n \"advanced\": True,\n },\n \"setup_mode\": {\n \"display_name\": \"Setup Mode\",\n \"info\": \"Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.\",\n \"options\": [\"Sync\", \"Async\", \"Off\"],\n \"advanced\": True,\n },\n \"pre_delete_collection\": {\n \"display_name\": \"Pre Delete Collection\",\n \"info\": \"Boolean flag to determine whether to delete the collection before creating a new one.\",\n \"advanced\": True,\n },\n \"metadata_indexing_include\": {\n \"display_name\": \"Metadata Indexing Include\",\n \"info\": \"Optional list of metadata fields to include in the indexing.\",\n \"advanced\": True,\n },\n \"metadata_indexing_exclude\": {\n \"display_name\": \"Metadata Indexing Exclude\",\n \"info\": \"Optional list of metadata fields to exclude from the indexing.\",\n \"advanced\": True,\n },\n \"collection_indexing_policy\": {\n \"display_name\": \"Collection Indexing Policy\",\n \"info\": \"Optional dictionary defining the indexing policy for the collection.\",\n \"advanced\": True,\n },\n \"number_of_results\": {\n \"display_name\": \"Number of Results\",\n \"info\": \"Number of results to return.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n embedding: Embeddings,\n collection_name: str,\n input_value: Text,\n token: str,\n api_endpoint: str,\n search_type: str = \"Similarity\",\n number_of_results: int = 4,\n namespace: Optional[str] = None,\n metric: Optional[str] = None,\n batch_size: Optional[int] = None,\n bulk_insert_batch_concurrency: Optional[int] = None,\n bulk_insert_overwrite_concurrency: Optional[int] = None,\n bulk_delete_concurrency: Optional[int] = None,\n setup_mode: str = \"Sync\",\n pre_delete_collection: bool = False,\n metadata_indexing_include: Optional[List[str]] = None,\n metadata_indexing_exclude: Optional[List[str]] = None,\n collection_indexing_policy: Optional[dict] = None,\n ) -> List[Record]:\n vector_store = AstraDBVectorStoreComponent().build(\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n try:\n return self.search_with_vector_store(input_value, search_type, vector_store, k=number_of_results)\n except KeyError as e:\n if \"content\" in str(e):\n raise ValueError(\n \"You should ingest data through Langflow (or LangChain) to query it in Langflow. Your collection does not contain a field name 'content'.\"\n )\n else:\n raise e\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "collection_indexing_policy": { - "type": "dict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "collection_indexing_policy", - "display_name": "Collection Indexing Policy", - "advanced": true, - "dynamic": false, - "info": "Optional dictionary defining the indexing policy for the collection.", - "load_from_db": false, - "title_case": false - }, - "collection_name": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "collection_name", - "display_name": "Collection Name", - "advanced": false, - "dynamic": false, - "info": "The name of the collection within Astra DB where the vectors will be stored.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ], - "value": "langflow" - }, - "metadata_indexing_exclude": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "metadata_indexing_exclude", - "display_name": "Metadata Indexing Exclude", - "advanced": true, - "dynamic": false, - "info": "Optional list of metadata fields to exclude from the indexing.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "metadata_indexing_include": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "metadata_indexing_include", - "display_name": "Metadata Indexing Include", - "advanced": true, - "dynamic": false, - "info": "Optional list of metadata fields to include in the indexing.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "metric": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "metric", - "display_name": "Metric", - "advanced": true, - "dynamic": false, - "info": "Optional distance metric for vector comparisons in the vector store.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "namespace": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "namespace", - "display_name": "Namespace", - "advanced": true, - "dynamic": false, - "info": "Optional namespace within Astra DB to use for the collection.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "number_of_results": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 4, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "number_of_results", - "display_name": "Number of Results", - "advanced": true, - "dynamic": false, - "info": "Number of results to return.", - "load_from_db": false, - "title_case": false - }, - "pre_delete_collection": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "pre_delete_collection", - "display_name": "Pre Delete Collection", - "advanced": true, - "dynamic": false, - "info": "Boolean flag to determine whether to delete the collection before creating a new one.", - "load_from_db": false, - "title_case": false - }, - "search_type": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Similarity", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "Similarity", - "MMR" - ], - "name": "search_type", - "display_name": "Search Type", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "setup_mode": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Sync", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "Sync", - "Async", - "Off" - ], - "name": "setup_mode", - "display_name": "Setup Mode", - "advanced": true, - "dynamic": false, - "info": "Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "token": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "token", - "display_name": "Token", - "advanced": false, - "dynamic": false, - "info": "Authentication token for accessing Astra DB.", - "load_from_db": true, - "title_case": false, - "input_types": [ - "Text" - ], - "value": "ASTRA_DB_APPLICATION_TOKEN" - }, - "_type": "CustomComponent" - }, - "description": "Searches an existing Astra DB Vector Store.", - "icon": "AstraDB", "base_classes": [ "Record" ], - "display_name": "Astra DB Search", - "documentation": "", + "beta": false, "custom_fields": { - "embedding": null, - "collection_name": null, - "input_value": null, - "token": null, "api_endpoint": null, - "search_type": null, - "number_of_results": null, - "namespace": null, - "metric": null, "batch_size": null, + "bulk_delete_concurrency": null, "bulk_insert_batch_concurrency": null, "bulk_insert_overwrite_concurrency": null, - "bulk_delete_concurrency": null, - "setup_mode": null, - "pre_delete_collection": null, - "metadata_indexing_include": null, + "collection_indexing_policy": null, + "collection_name": null, + "embedding": null, + "input_value": null, "metadata_indexing_exclude": null, - "collection_indexing_policy": null + "metadata_indexing_include": null, + "metric": null, + "namespace": null, + "number_of_results": null, + "pre_delete_collection": null, + "search_type": null, + "setup_mode": null, + "token": null }, - "output_types": [ - "Record" - ], + "description": "Searches an existing Astra DB Vector Store.", + "display_name": "Astra DB Search", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "token", "api_endpoint", @@ -2139,402 +1964,450 @@ "input_value", "embedding" ], - "beta": false - }, - "id": "AstraDBSearch-41nRz" - }, - "selected": false, - "width": 384, - "height": 713, - "dragging": false, - "positionAbsolute": { - "x": 1723.976434815103, - "y": 277.03317407245913 - } - }, - { - "id": "AstraDB-eUCSS", - "type": "genericNode", - "position": { - "x": 3372.04958055989, - "y": 1611.0742035495277 - }, - "data": { - "type": "AstraDB", - "node": { + "frozen": false, + "icon": "AstraDB", + "output_types": [ + "Record" + ], "template": { - "embedding": { - "type": "Embeddings", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "embedding", - "display_name": "Embedding", - "advanced": false, - "dynamic": false, - "info": "Embedding to use", - "load_from_db": false, - "title_case": false - }, - "inputs": { - "type": "Record", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "inputs", - "display_name": "Inputs", - "advanced": false, - "dynamic": false, - "info": "Optional list of records to be processed and stored in the vector store.", - "load_from_db": false, - "title_case": false - }, + "_type": "CustomComponent", "api_endpoint": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": false, + "display_name": "API Endpoint", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "api_endpoint", - "display_name": "API Endpoint", - "advanced": false, - "dynamic": false, "info": "API endpoint URL for the Astra DB service.", - "load_from_db": true, - "title_case": false, "input_types": [ "Text" ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "api_endpoint", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", "value": "ASTRA_DB_API_ENDPOINT" }, "batch_size": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Batch Size", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "batch_size", - "display_name": "Batch Size", - "advanced": true, - "dynamic": false, "info": "Optional number of records to process in a single batch.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "batch_size", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" }, "bulk_delete_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Bulk Delete Concurrency", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "bulk_delete_concurrency", - "display_name": "Bulk Delete Concurrency", - "advanced": true, - "dynamic": false, "info": "Optional concurrency level for bulk delete operations.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "bulk_delete_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" }, "bulk_insert_batch_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Bulk Insert Batch Concurrency", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "bulk_insert_batch_concurrency", - "display_name": "Bulk Insert Batch Concurrency", - "advanced": true, - "dynamic": false, "info": "Optional concurrency level for bulk insert operations.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "bulk_insert_batch_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" }, "bulk_insert_overwrite_concurrency": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Bulk Insert Overwrite Concurrency", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "bulk_insert_overwrite_concurrency", - "display_name": "Bulk Insert Overwrite Concurrency", - "advanced": true, - "dynamic": false, "info": "Optional concurrency level for bulk insert operations that overwrite existing records.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "bulk_insert_overwrite_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" }, "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import List, Optional, Union\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, VectorStore\nfrom langflow.schema import Record\nfrom langchain_core.retrievers import BaseRetriever\n\n\nclass AstraDBVectorStoreComponent(CustomComponent):\n display_name = \"Astra DB\"\n description = \"Builds or loads an Astra DB Vector Store.\"\n icon = \"AstraDB\"\n field_order = [\"token\", \"api_endpoint\", \"collection_name\", \"inputs\", \"embedding\"]\n\n def build_config(self):\n return {\n \"inputs\": {\n \"display_name\": \"Inputs\",\n \"info\": \"Optional list of records to be processed and stored in the vector store.\",\n },\n \"embedding\": {\"display_name\": \"Embedding\", \"info\": \"Embedding to use\"},\n \"collection_name\": {\n \"display_name\": \"Collection Name\",\n \"info\": \"The name of the collection within Astra DB where the vectors will be stored.\",\n },\n \"token\": {\n \"display_name\": \"Token\",\n \"info\": \"Authentication token for accessing Astra DB.\",\n \"password\": True,\n },\n \"api_endpoint\": {\n \"display_name\": \"API Endpoint\",\n \"info\": \"API endpoint URL for the Astra DB service.\",\n },\n \"namespace\": {\n \"display_name\": \"Namespace\",\n \"info\": \"Optional namespace within Astra DB to use for the collection.\",\n \"advanced\": True,\n },\n \"metric\": {\n \"display_name\": \"Metric\",\n \"info\": \"Optional distance metric for vector comparisons in the vector store.\",\n \"advanced\": True,\n },\n \"batch_size\": {\n \"display_name\": \"Batch Size\",\n \"info\": \"Optional number of records to process in a single batch.\",\n \"advanced\": True,\n },\n \"bulk_insert_batch_concurrency\": {\n \"display_name\": \"Bulk Insert Batch Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations.\",\n \"advanced\": True,\n },\n \"bulk_insert_overwrite_concurrency\": {\n \"display_name\": \"Bulk Insert Overwrite Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations that overwrite existing records.\",\n \"advanced\": True,\n },\n \"bulk_delete_concurrency\": {\n \"display_name\": \"Bulk Delete Concurrency\",\n \"info\": \"Optional concurrency level for bulk delete operations.\",\n \"advanced\": True,\n },\n \"setup_mode\": {\n \"display_name\": \"Setup Mode\",\n \"info\": \"Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.\",\n \"options\": [\"Sync\", \"Async\", \"Off\"],\n \"advanced\": True,\n },\n \"pre_delete_collection\": {\n \"display_name\": \"Pre Delete Collection\",\n \"info\": \"Boolean flag to determine whether to delete the collection before creating a new one.\",\n \"advanced\": True,\n },\n \"metadata_indexing_include\": {\n \"display_name\": \"Metadata Indexing Include\",\n \"info\": \"Optional list of metadata fields to include in the indexing.\",\n \"advanced\": True,\n },\n \"metadata_indexing_exclude\": {\n \"display_name\": \"Metadata Indexing Exclude\",\n \"info\": \"Optional list of metadata fields to exclude from the indexing.\",\n \"advanced\": True,\n },\n \"collection_indexing_policy\": {\n \"display_name\": \"Collection Indexing Policy\",\n \"info\": \"Optional dictionary defining the indexing policy for the collection.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n embedding: Embeddings,\n token: str,\n api_endpoint: str,\n collection_name: str,\n inputs: Optional[List[Record]] = None,\n namespace: Optional[str] = None,\n metric: Optional[str] = None,\n batch_size: Optional[int] = None,\n bulk_insert_batch_concurrency: Optional[int] = None,\n bulk_insert_overwrite_concurrency: Optional[int] = None,\n bulk_delete_concurrency: Optional[int] = None,\n setup_mode: str = \"Sync\",\n pre_delete_collection: bool = False,\n metadata_indexing_include: Optional[List[str]] = None,\n metadata_indexing_exclude: Optional[List[str]] = None,\n collection_indexing_policy: Optional[dict] = None,\n ) -> Union[VectorStore, BaseRetriever]:\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError:\n raise ImportError(\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n\n try:\n setup_mode_value = SetupMode[setup_mode.upper()]\n except KeyError:\n raise ValueError(f\"Invalid setup mode: {setup_mode}\")\n if inputs:\n documents = [_input.to_lc_document() for _input in inputs]\n\n vector_store = AstraDBVectorStore.from_documents(\n documents=documents,\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode_value,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n else:\n vector_store = AstraDBVectorStore(\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode_value,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n\n return vector_store\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", "advanced": true, "dynamic": true, + "fileTypes": [], + "file_path": "", "info": "", + "list": false, "load_from_db": false, - "title_case": false + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import List, Optional\n\nfrom langflow.components.vectorstores.AstraDB import AstraDBVectorStoreComponent\nfrom langflow.components.vectorstores.base.model import LCVectorStoreComponent\nfrom langflow.field_typing import Embeddings, Text\nfrom langflow.schema import Record\n\n\nclass AstraDBSearchComponent(LCVectorStoreComponent):\n display_name = \"Astra DB Search\"\n description = \"Searches an existing Astra DB Vector Store.\"\n icon = \"AstraDB\"\n field_order = [\"token\", \"api_endpoint\", \"collection_name\", \"input_value\", \"embedding\"]\n\n def build_config(self):\n return {\n \"search_type\": {\n \"display_name\": \"Search Type\",\n \"options\": [\"Similarity\", \"MMR\"],\n },\n \"input_value\": {\n \"display_name\": \"Input Value\",\n \"info\": \"Input value to search\",\n },\n \"embedding\": {\"display_name\": \"Embedding\", \"info\": \"Embedding to use\"},\n \"collection_name\": {\n \"display_name\": \"Collection Name\",\n \"info\": \"The name of the collection within Astra DB where the vectors will be stored.\",\n },\n \"token\": {\n \"display_name\": \"Token\",\n \"info\": \"Authentication token for accessing Astra DB.\",\n \"password\": True,\n },\n \"api_endpoint\": {\n \"display_name\": \"API Endpoint\",\n \"info\": \"API endpoint URL for the Astra DB service.\",\n },\n \"namespace\": {\n \"display_name\": \"Namespace\",\n \"info\": \"Optional namespace within Astra DB to use for the collection.\",\n \"advanced\": True,\n },\n \"metric\": {\n \"display_name\": \"Metric\",\n \"info\": \"Optional distance metric for vector comparisons in the vector store.\",\n \"advanced\": True,\n },\n \"batch_size\": {\n \"display_name\": \"Batch Size\",\n \"info\": \"Optional number of records to process in a single batch.\",\n \"advanced\": True,\n },\n \"bulk_insert_batch_concurrency\": {\n \"display_name\": \"Bulk Insert Batch Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations.\",\n \"advanced\": True,\n },\n \"bulk_insert_overwrite_concurrency\": {\n \"display_name\": \"Bulk Insert Overwrite Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations that overwrite existing records.\",\n \"advanced\": True,\n },\n \"bulk_delete_concurrency\": {\n \"display_name\": \"Bulk Delete Concurrency\",\n \"info\": \"Optional concurrency level for bulk delete operations.\",\n \"advanced\": True,\n },\n \"setup_mode\": {\n \"display_name\": \"Setup Mode\",\n \"info\": \"Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.\",\n \"options\": [\"Sync\", \"Async\", \"Off\"],\n \"advanced\": True,\n },\n \"pre_delete_collection\": {\n \"display_name\": \"Pre Delete Collection\",\n \"info\": \"Boolean flag to determine whether to delete the collection before creating a new one.\",\n \"advanced\": True,\n },\n \"metadata_indexing_include\": {\n \"display_name\": \"Metadata Indexing Include\",\n \"info\": \"Optional list of metadata fields to include in the indexing.\",\n \"advanced\": True,\n },\n \"metadata_indexing_exclude\": {\n \"display_name\": \"Metadata Indexing Exclude\",\n \"info\": \"Optional list of metadata fields to exclude from the indexing.\",\n \"advanced\": True,\n },\n \"collection_indexing_policy\": {\n \"display_name\": \"Collection Indexing Policy\",\n \"info\": \"Optional dictionary defining the indexing policy for the collection.\",\n \"advanced\": True,\n },\n \"number_of_results\": {\n \"display_name\": \"Number of Results\",\n \"info\": \"Number of results to return.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n embedding: Embeddings,\n collection_name: str,\n input_value: Text,\n token: str,\n api_endpoint: str,\n search_type: str = \"Similarity\",\n number_of_results: int = 4,\n namespace: Optional[str] = None,\n metric: Optional[str] = None,\n batch_size: Optional[int] = None,\n bulk_insert_batch_concurrency: Optional[int] = None,\n bulk_insert_overwrite_concurrency: Optional[int] = None,\n bulk_delete_concurrency: Optional[int] = None,\n setup_mode: str = \"Sync\",\n pre_delete_collection: bool = False,\n metadata_indexing_include: Optional[List[str]] = None,\n metadata_indexing_exclude: Optional[List[str]] = None,\n collection_indexing_policy: Optional[dict] = None,\n ) -> List[Record]:\n vector_store = AstraDBVectorStoreComponent().build(\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n try:\n return self.search_with_vector_store(input_value, search_type, vector_store, k=number_of_results)\n except KeyError as e:\n if \"content\" in str(e):\n raise ValueError(\n \"You should ingest data through Langflow (or LangChain) to query it in Langflow. Your collection does not contain a field name 'content'.\"\n )\n else:\n raise e\n" }, "collection_indexing_policy": { - "type": "dict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Collection Indexing Policy", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "collection_indexing_policy", - "display_name": "Collection Indexing Policy", - "advanced": true, - "dynamic": false, "info": "Optional dictionary defining the indexing policy for the collection.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "collection_indexing_policy", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict" }, "collection_name": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": false, + "display_name": "Collection Name", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "collection_name", - "display_name": "Collection Name", - "advanced": false, - "dynamic": false, "info": "The name of the collection within Astra DB where the vectors will be stored.", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "collection_name", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", "value": "langflow" }, - "metadata_indexing_exclude": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, + "embedding": { + "advanced": false, + "display_name": "Embedding", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "metadata_indexing_exclude", - "display_name": "Metadata Indexing Exclude", - "advanced": true, - "dynamic": false, - "info": "Optional list of metadata fields to exclude from the indexing.", + "info": "Embedding to use", + "list": false, "load_from_db": false, + "multiline": false, + "name": "embedding", + "password": false, + "placeholder": "", + "required": true, + "show": true, "title_case": false, + "type": "Embeddings" + }, + "input_value": { + "advanced": false, + "display_name": "Input Value", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Input value to search", "input_types": [ "Text" - ] + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "input_value", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str" + }, + "metadata_indexing_exclude": { + "advanced": true, + "display_name": "Metadata Indexing Exclude", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional list of metadata fields to exclude from the indexing.", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "metadata_indexing_exclude", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" }, "metadata_indexing_include": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Metadata Indexing Include", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "metadata_indexing_include", - "display_name": "Metadata Indexing Include", - "advanced": true, - "dynamic": false, "info": "Optional list of metadata fields to include in the indexing.", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" - ] + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "metadata_indexing_include", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" }, "metric": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Metric", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "metric", - "display_name": "Metric", - "advanced": true, - "dynamic": false, "info": "Optional distance metric for vector comparisons in the vector store.", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" - ] + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "metric", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" }, "namespace": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": true, + "display_name": "Namespace", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "namespace", - "display_name": "Namespace", - "advanced": true, - "dynamic": false, "info": "Optional namespace within Astra DB to use for the collection.", - "load_from_db": false, - "title_case": false, "input_types": [ "Text" - ] + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "namespace", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "number_of_results": { + "advanced": true, + "display_name": "Number of Results", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Number of results to return.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "number_of_results", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 4 }, "pre_delete_collection": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, + "advanced": true, + "display_name": "Pre Delete Collection", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, - "name": "pre_delete_collection", - "display_name": "Pre Delete Collection", - "advanced": true, - "dynamic": false, "info": "Boolean flag to determine whether to delete the collection before creating a new one.", + "list": false, "load_from_db": false, - "title_case": false + "multiline": false, + "name": "pre_delete_collection", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "search_type": { + "advanced": false, + "display_name": "Search Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "search_type", + "options": [ + "Similarity", + "MMR" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Similarity" }, "setup_mode": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "Sync", + "advanced": true, + "display_name": "Setup Mode", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": false, + "info": "Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "setup_mode", "options": [ "Sync", "Async", "Off" ], - "name": "setup_mode", - "display_name": "Setup Mode", - "advanced": true, - "dynamic": false, - "info": "Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.", - "load_from_db": false, + "password": false, + "placeholder": "", + "required": false, + "show": true, "title_case": false, - "input_types": [ - "Text" - ] + "type": "str", + "value": "Sync" }, "token": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, + "advanced": false, + "display_name": "Token", + "dynamic": false, "fileTypes": [], "file_path": "", - "password": true, - "name": "token", - "display_name": "Token", - "advanced": false, - "dynamic": false, "info": "Authentication token for accessing Astra DB.", - "load_from_db": true, - "title_case": false, "input_types": [ "Text" ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "token", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", "value": "ASTRA_DB_APPLICATION_TOKEN" - }, - "_type": "CustomComponent" - }, - "description": "Builds or loads an Astra DB Vector Store.", - "icon": "AstraDB", + } + } + }, + "type": "AstraDBSearch" + }, + "dragging": false, + "height": 713, + "id": "AstraDBSearch-41nRz", + "position": { + "x": 1723.976434815103, + "y": 277.03317407245913 + }, + "positionAbsolute": { + "x": 1723.976434815103, + "y": 277.03317407245913 + }, + "selected": false, + "type": "genericNode", + "width": 384 + }, + { + "data": { + "id": "AstraDB-eUCSS", + "node": { "base_classes": [ "VectorStore" ], - "display_name": "Astra DB", - "documentation": "", + "beta": false, "custom_fields": { - "embedding": null, - "token": null, "api_endpoint": null, - "collection_name": null, - "inputs": null, - "namespace": null, - "metric": null, "batch_size": null, + "bulk_delete_concurrency": null, "bulk_insert_batch_concurrency": null, "bulk_insert_overwrite_concurrency": null, - "bulk_delete_concurrency": null, - "setup_mode": null, - "pre_delete_collection": null, - "metadata_indexing_include": null, + "collection_indexing_policy": null, + "collection_name": null, + "embedding": null, + "inputs": null, "metadata_indexing_exclude": null, - "collection_indexing_policy": null + "metadata_indexing_include": null, + "metric": null, + "namespace": null, + "pre_delete_collection": null, + "setup_mode": null, + "token": null }, - "output_types": [ - "VectorStore" - ], + "description": "Builds or loads an Astra DB Vector Store.", + "display_name": "Astra DB", + "documentation": "", "field_formatters": {}, - "frozen": false, "field_order": [ "token", "api_endpoint", @@ -2542,525 +2415,395 @@ "inputs", "embedding" ], - "beta": false + "frozen": false, + "icon": "AstraDB", + "output_types": [ + "VectorStore", + "BaseRetriever" + ], + "template": { + "_type": "CustomComponent", + "api_endpoint": { + "advanced": false, + "display_name": "API Endpoint", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "API endpoint URL for the Astra DB service.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "api_endpoint", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "ASTRA_DB_API_ENDPOINT" + }, + "batch_size": { + "advanced": true, + "display_name": "Batch Size", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional number of records to process in a single batch.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "batch_size", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" + }, + "bulk_delete_concurrency": { + "advanced": true, + "display_name": "Bulk Delete Concurrency", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional concurrency level for bulk delete operations.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "bulk_delete_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" + }, + "bulk_insert_batch_concurrency": { + "advanced": true, + "display_name": "Bulk Insert Batch Concurrency", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional concurrency level for bulk insert operations.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "bulk_insert_batch_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" + }, + "bulk_insert_overwrite_concurrency": { + "advanced": true, + "display_name": "Bulk Insert Overwrite Concurrency", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional concurrency level for bulk insert operations that overwrite existing records.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "bulk_insert_overwrite_concurrency", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int" + }, + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import List, Optional, Union\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, VectorStore\nfrom langflow.schema import Record\nfrom langchain_core.retrievers import BaseRetriever\n\n\nclass AstraDBVectorStoreComponent(CustomComponent):\n display_name = \"Astra DB\"\n description = \"Builds or loads an Astra DB Vector Store.\"\n icon = \"AstraDB\"\n field_order = [\"token\", \"api_endpoint\", \"collection_name\", \"inputs\", \"embedding\"]\n\n def build_config(self):\n return {\n \"inputs\": {\n \"display_name\": \"Inputs\",\n \"info\": \"Optional list of records to be processed and stored in the vector store.\",\n },\n \"embedding\": {\"display_name\": \"Embedding\", \"info\": \"Embedding to use\"},\n \"collection_name\": {\n \"display_name\": \"Collection Name\",\n \"info\": \"The name of the collection within Astra DB where the vectors will be stored.\",\n },\n \"token\": {\n \"display_name\": \"Token\",\n \"info\": \"Authentication token for accessing Astra DB.\",\n \"password\": True,\n },\n \"api_endpoint\": {\n \"display_name\": \"API Endpoint\",\n \"info\": \"API endpoint URL for the Astra DB service.\",\n },\n \"namespace\": {\n \"display_name\": \"Namespace\",\n \"info\": \"Optional namespace within Astra DB to use for the collection.\",\n \"advanced\": True,\n },\n \"metric\": {\n \"display_name\": \"Metric\",\n \"info\": \"Optional distance metric for vector comparisons in the vector store.\",\n \"advanced\": True,\n },\n \"batch_size\": {\n \"display_name\": \"Batch Size\",\n \"info\": \"Optional number of records to process in a single batch.\",\n \"advanced\": True,\n },\n \"bulk_insert_batch_concurrency\": {\n \"display_name\": \"Bulk Insert Batch Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations.\",\n \"advanced\": True,\n },\n \"bulk_insert_overwrite_concurrency\": {\n \"display_name\": \"Bulk Insert Overwrite Concurrency\",\n \"info\": \"Optional concurrency level for bulk insert operations that overwrite existing records.\",\n \"advanced\": True,\n },\n \"bulk_delete_concurrency\": {\n \"display_name\": \"Bulk Delete Concurrency\",\n \"info\": \"Optional concurrency level for bulk delete operations.\",\n \"advanced\": True,\n },\n \"setup_mode\": {\n \"display_name\": \"Setup Mode\",\n \"info\": \"Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.\",\n \"options\": [\"Sync\", \"Async\", \"Off\"],\n \"advanced\": True,\n },\n \"pre_delete_collection\": {\n \"display_name\": \"Pre Delete Collection\",\n \"info\": \"Boolean flag to determine whether to delete the collection before creating a new one.\",\n \"advanced\": True,\n },\n \"metadata_indexing_include\": {\n \"display_name\": \"Metadata Indexing Include\",\n \"info\": \"Optional list of metadata fields to include in the indexing.\",\n \"advanced\": True,\n },\n \"metadata_indexing_exclude\": {\n \"display_name\": \"Metadata Indexing Exclude\",\n \"info\": \"Optional list of metadata fields to exclude from the indexing.\",\n \"advanced\": True,\n },\n \"collection_indexing_policy\": {\n \"display_name\": \"Collection Indexing Policy\",\n \"info\": \"Optional dictionary defining the indexing policy for the collection.\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n embedding: Embeddings,\n token: str,\n api_endpoint: str,\n collection_name: str,\n inputs: Optional[List[Record]] = None,\n namespace: Optional[str] = None,\n metric: Optional[str] = None,\n batch_size: Optional[int] = None,\n bulk_insert_batch_concurrency: Optional[int] = None,\n bulk_insert_overwrite_concurrency: Optional[int] = None,\n bulk_delete_concurrency: Optional[int] = None,\n setup_mode: str = \"Sync\",\n pre_delete_collection: bool = False,\n metadata_indexing_include: Optional[List[str]] = None,\n metadata_indexing_exclude: Optional[List[str]] = None,\n collection_indexing_policy: Optional[dict] = None,\n ) -> Union[VectorStore, BaseRetriever]:\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError:\n raise ImportError(\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n\n try:\n setup_mode_value = SetupMode[setup_mode.upper()]\n except KeyError:\n raise ValueError(f\"Invalid setup mode: {setup_mode}\")\n if inputs:\n documents = [_input.to_lc_document() for _input in inputs]\n\n vector_store = AstraDBVectorStore.from_documents(\n documents=documents,\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode_value,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n else:\n vector_store = AstraDBVectorStore(\n embedding=embedding,\n collection_name=collection_name,\n token=token,\n api_endpoint=api_endpoint,\n namespace=namespace,\n metric=metric,\n batch_size=batch_size,\n bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,\n bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,\n bulk_delete_concurrency=bulk_delete_concurrency,\n setup_mode=setup_mode_value,\n pre_delete_collection=pre_delete_collection,\n metadata_indexing_include=metadata_indexing_include,\n metadata_indexing_exclude=metadata_indexing_exclude,\n collection_indexing_policy=collection_indexing_policy,\n )\n\n return vector_store\n return vector_store\n" + }, + "collection_indexing_policy": { + "advanced": true, + "display_name": "Collection Indexing Policy", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional dictionary defining the indexing policy for the collection.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "collection_indexing_policy", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict" + }, + "collection_name": { + "advanced": false, + "display_name": "Collection Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "The name of the collection within Astra DB where the vectors will be stored.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "collection_name", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "langflow" + }, + "embedding": { + "advanced": false, + "display_name": "Embedding", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Embedding to use", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "embedding", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "Embeddings" + }, + "inputs": { + "advanced": false, + "display_name": "Inputs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional list of records to be processed and stored in the vector store.", + "list": true, + "load_from_db": false, + "multiline": false, + "name": "inputs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "Record" + }, + "metadata_indexing_exclude": { + "advanced": true, + "display_name": "Metadata Indexing Exclude", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional list of metadata fields to exclude from the indexing.", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "metadata_indexing_exclude", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "metadata_indexing_include": { + "advanced": true, + "display_name": "Metadata Indexing Include", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional list of metadata fields to include in the indexing.", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "metadata_indexing_include", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "metric": { + "advanced": true, + "display_name": "Metric", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional distance metric for vector comparisons in the vector store.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "metric", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "namespace": { + "advanced": true, + "display_name": "Namespace", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Optional namespace within Astra DB to use for the collection.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "namespace", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "pre_delete_collection": { + "advanced": true, + "display_name": "Pre Delete Collection", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Boolean flag to determine whether to delete the collection before creating a new one.", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "pre_delete_collection", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "setup_mode": { + "advanced": true, + "display_name": "Setup Mode", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Configuration mode for setting up the vector store, with options like “Sync”, “Async”, or “Off”.", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "setup_mode", + "options": [ + "Sync", + "Async", + "Off" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Sync" + }, + "token": { + "advanced": false, + "display_name": "Token", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "Authentication token for accessing Astra DB.", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "token", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "ASTRA_DB_APPLICATION_TOKEN" + } + } }, - "id": "AstraDB-eUCSS" + "type": "AstraDB" }, - "selected": false, - "width": 384, + "dragging": false, "height": 573, + "id": "AstraDB-eUCSS", + "position": { + "x": 3372.04958055989, + "y": 1611.0742035495277 + }, "positionAbsolute": { "x": 3372.04958055989, "y": 1611.0742035495277 }, - "dragging": false + "selected": false, + "type": "genericNode", + "width": 384 }, { - "id": "OpenAIEmbeddings-9TPjc", - "type": "genericNode", - "position": { - "x": 2814.0402191223047, - "y": 1955.9268168273086 - }, "data": { - "type": "OpenAIEmbeddings", + "id": "OpenAIEmbeddings-9TPjc", "node": { - "template": { - "allowed_special": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": [], - "fileTypes": [], - "file_path": "", - "password": false, - "name": "allowed_special", - "display_name": "Allowed Special", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "chunk_size": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 1000, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "chunk_size", - "display_name": "Chunk Size", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "client": { - "type": "Any", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "client", - "display_name": "Client", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from typing import Dict, List, Optional\n\nfrom langchain_openai.embeddings.base import OpenAIEmbeddings\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, NestedDict\n\n\nclass OpenAIEmbeddingsComponent(CustomComponent):\n display_name = \"OpenAI Embeddings\"\n description = \"Generate embeddings using OpenAI models.\"\n\n def build_config(self):\n return {\n \"allowed_special\": {\n \"display_name\": \"Allowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"default_headers\": {\n \"display_name\": \"Default Headers\",\n \"advanced\": True,\n \"field_type\": \"dict\",\n },\n \"default_query\": {\n \"display_name\": \"Default Query\",\n \"advanced\": True,\n \"field_type\": \"NestedDict\",\n },\n \"disallowed_special\": {\n \"display_name\": \"Disallowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"advanced\": True},\n \"client\": {\"display_name\": \"Client\", \"advanced\": True},\n \"deployment\": {\"display_name\": \"Deployment\", \"advanced\": True},\n \"embedding_ctx_length\": {\n \"display_name\": \"Embedding Context Length\",\n \"advanced\": True,\n },\n \"max_retries\": {\"display_name\": \"Max Retries\", \"advanced\": True},\n \"model\": {\n \"display_name\": \"Model\",\n \"advanced\": False,\n \"options\": [\n \"text-embedding-3-small\",\n \"text-embedding-3-large\",\n \"text-embedding-ada-002\",\n ],\n },\n \"model_kwargs\": {\"display_name\": \"Model Kwargs\", \"advanced\": True},\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"password\": True,\n \"advanced\": True,\n },\n \"openai_api_key\": {\"display_name\": \"OpenAI API Key\", \"password\": True},\n \"openai_api_type\": {\n \"display_name\": \"OpenAI API Type\",\n \"advanced\": True,\n \"password\": True,\n },\n \"openai_api_version\": {\n \"display_name\": \"OpenAI API Version\",\n \"advanced\": True,\n },\n \"openai_organization\": {\n \"display_name\": \"OpenAI Organization\",\n \"advanced\": True,\n },\n \"openai_proxy\": {\"display_name\": \"OpenAI Proxy\", \"advanced\": True},\n \"request_timeout\": {\"display_name\": \"Request Timeout\", \"advanced\": True},\n \"show_progress_bar\": {\n \"display_name\": \"Show Progress Bar\",\n \"advanced\": True,\n },\n \"skip_empty\": {\"display_name\": \"Skip Empty\", \"advanced\": True},\n \"tiktoken_model_name\": {\n \"display_name\": \"TikToken Model Name\",\n \"advanced\": True,\n },\n \"tiktoken_enable\": {\"display_name\": \"TikToken Enable\", \"advanced\": True},\n }\n\n def build(\n self,\n openai_api_key: str,\n default_headers: Optional[Dict[str, str]] = None,\n default_query: Optional[NestedDict] = {},\n allowed_special: List[str] = [],\n disallowed_special: List[str] = [\"all\"],\n chunk_size: int = 1000,\n deployment: str = \"text-embedding-ada-002\",\n embedding_ctx_length: int = 8191,\n max_retries: int = 6,\n model: str = \"text-embedding-ada-002\",\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n openai_api_type: Optional[str] = None,\n openai_api_version: Optional[str] = None,\n openai_organization: Optional[str] = None,\n openai_proxy: Optional[str] = None,\n request_timeout: Optional[float] = None,\n show_progress_bar: bool = False,\n skip_empty: bool = False,\n tiktoken_enable: bool = True,\n tiktoken_model_name: Optional[str] = None,\n ) -> Embeddings:\n # This is to avoid errors with Vector Stores (e.g Chroma)\n if disallowed_special == [\"all\"]:\n disallowed_special = \"all\" # type: ignore\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n return OpenAIEmbeddings(\n tiktoken_enabled=tiktoken_enable,\n default_headers=default_headers,\n default_query=default_query,\n allowed_special=set(allowed_special),\n disallowed_special=\"all\",\n chunk_size=chunk_size,\n deployment=deployment,\n embedding_ctx_length=embedding_ctx_length,\n max_retries=max_retries,\n model=model,\n model_kwargs=model_kwargs,\n base_url=openai_api_base,\n api_key=api_key,\n openai_api_type=openai_api_type,\n api_version=openai_api_version,\n organization=openai_organization,\n openai_proxy=openai_proxy,\n timeout=request_timeout,\n show_progress_bar=show_progress_bar,\n skip_empty=skip_empty,\n tiktoken_model_name=tiktoken_model_name,\n )\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "default_headers": { - "type": "dict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "default_headers", - "display_name": "Default Headers", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "default_query": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "default_query", - "display_name": "Default Query", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "deployment": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": "text-embedding-ada-002", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "deployment", - "display_name": "Deployment", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "disallowed_special": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": [ - "all" - ], - "fileTypes": [], - "file_path": "", - "password": false, - "name": "disallowed_special", - "display_name": "Disallowed Special", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "embedding_ctx_length": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 8191, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "embedding_ctx_length", - "display_name": "Embedding Context Length", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "max_retries": { - "type": "int", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": 6, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "max_retries", - "display_name": "Max Retries", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "model": { - "type": "str", - "required": false, - "placeholder": "", - "list": true, - "show": true, - "multiline": false, - "value": "text-embedding-ada-002", - "fileTypes": [], - "file_path": "", - "password": false, - "options": [ - "text-embedding-3-small", - "text-embedding-3-large", - "text-embedding-ada-002" - ], - "name": "model", - "display_name": "Model", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "model_kwargs": { - "type": "NestedDict", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": {}, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "openai_api_base": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_api_key": { - "type": "str", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "dynamic": false, - "info": "", - "load_from_db": true, - "title_case": false, - "input_types": [ - "Text" - ], - "value": "OPENAI_API_KEY" - }, - "openai_api_type": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": true, - "name": "openai_api_type", - "display_name": "OpenAI API Type", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_api_version": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_api_version", - "display_name": "OpenAI API Version", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_organization": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_organization", - "display_name": "OpenAI Organization", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "openai_proxy": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "openai_proxy", - "display_name": "OpenAI Proxy", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "request_timeout": { - "type": "float", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "request_timeout", - "display_name": "Request Timeout", - "advanced": true, - "dynamic": false, - "info": "", - "rangeSpec": { - "step_type": "float", - "min": -1, - "max": 1, - "step": 0.1 - }, - "load_from_db": false, - "title_case": false - }, - "show_progress_bar": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "show_progress_bar", - "display_name": "Show Progress Bar", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "skip_empty": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "skip_empty", - "display_name": "Skip Empty", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "tiktoken_enable": { - "type": "bool", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "value": true, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "tiktoken_enable", - "display_name": "TikToken Enable", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false - }, - "tiktoken_model_name": { - "type": "str", - "required": false, - "placeholder": "", - "list": false, - "show": true, - "multiline": false, - "fileTypes": [], - "file_path": "", - "password": false, - "name": "tiktoken_model_name", - "display_name": "TikToken Model Name", - "advanced": true, - "dynamic": false, - "info": "", - "load_from_db": false, - "title_case": false, - "input_types": [ - "Text" - ] - }, - "_type": "CustomComponent" - }, - "description": "Generate embeddings using OpenAI models.", "base_classes": [ "Embeddings" ], - "display_name": "OpenAI Embeddings", - "documentation": "", + "beta": false, "custom_fields": { - "openai_api_key": null, - "default_headers": null, - "default_query": null, "allowed_special": null, - "disallowed_special": null, "chunk_size": null, "client": null, + "default_headers": null, + "default_query": null, "deployment": null, + "disallowed_special": null, "embedding_ctx_length": null, "max_retries": null, "model": null, "model_kwargs": null, "openai_api_base": null, + "openai_api_key": null, "openai_api_type": null, "openai_api_version": null, "openai_organization": null, @@ -3071,327 +2814,490 @@ "tiktoken_enable": null, "tiktoken_model_name": null }, + "description": "Generate embeddings using OpenAI models.", + "display_name": "OpenAI Embeddings", + "documentation": "", + "field_formatters": {}, + "field_order": [], + "frozen": false, "output_types": [ "Embeddings" ], - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false + "template": { + "_type": "CustomComponent", + "allowed_special": { + "advanced": true, + "display_name": "Allowed Special", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "allowed_special", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": [] + }, + "chunk_size": { + "advanced": true, + "display_name": "Chunk Size", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "chunk_size", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 1000 + }, + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from typing import Dict, List, Optional\n\nfrom langchain_openai.embeddings.base import OpenAIEmbeddings\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.custom import CustomComponent\nfrom langflow.field_typing import Embeddings, NestedDict\n\n\nclass OpenAIEmbeddingsComponent(CustomComponent):\n display_name = \"OpenAI Embeddings\"\n description = \"Generate embeddings using OpenAI models.\"\n\n def build_config(self):\n return {\n \"allowed_special\": {\n \"display_name\": \"Allowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"default_headers\": {\n \"display_name\": \"Default Headers\",\n \"advanced\": True,\n \"field_type\": \"dict\",\n },\n \"default_query\": {\n \"display_name\": \"Default Query\",\n \"advanced\": True,\n \"field_type\": \"NestedDict\",\n },\n \"disallowed_special\": {\n \"display_name\": \"Disallowed Special\",\n \"advanced\": True,\n \"field_type\": \"str\",\n \"is_list\": True,\n },\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"advanced\": True},\n \"client\": {\"display_name\": \"Client\", \"advanced\": True},\n \"deployment\": {\"display_name\": \"Deployment\", \"advanced\": True},\n \"embedding_ctx_length\": {\n \"display_name\": \"Embedding Context Length\",\n \"advanced\": True,\n },\n \"max_retries\": {\"display_name\": \"Max Retries\", \"advanced\": True},\n \"model\": {\n \"display_name\": \"Model\",\n \"advanced\": False,\n \"options\": [\n \"text-embedding-3-small\",\n \"text-embedding-3-large\",\n \"text-embedding-ada-002\",\n ],\n },\n \"model_kwargs\": {\"display_name\": \"Model Kwargs\", \"advanced\": True},\n \"openai_api_base\": {\n \"display_name\": \"OpenAI API Base\",\n \"password\": True,\n \"advanced\": True,\n },\n \"openai_api_key\": {\"display_name\": \"OpenAI API Key\", \"password\": True},\n \"openai_api_type\": {\n \"display_name\": \"OpenAI API Type\",\n \"advanced\": True,\n \"password\": True,\n },\n \"openai_api_version\": {\n \"display_name\": \"OpenAI API Version\",\n \"advanced\": True,\n },\n \"openai_organization\": {\n \"display_name\": \"OpenAI Organization\",\n \"advanced\": True,\n },\n \"openai_proxy\": {\"display_name\": \"OpenAI Proxy\", \"advanced\": True},\n \"request_timeout\": {\"display_name\": \"Request Timeout\", \"advanced\": True},\n \"show_progress_bar\": {\n \"display_name\": \"Show Progress Bar\",\n \"advanced\": True,\n },\n \"skip_empty\": {\"display_name\": \"Skip Empty\", \"advanced\": True},\n \"tiktoken_model_name\": {\n \"display_name\": \"TikToken Model Name\",\n \"advanced\": True,\n },\n \"tiktoken_enable\": {\"display_name\": \"TikToken Enable\", \"advanced\": True},\n }\n\n def build(\n self,\n openai_api_key: str,\n default_headers: Optional[Dict[str, str]] = None,\n default_query: Optional[NestedDict] = {},\n allowed_special: List[str] = [],\n disallowed_special: List[str] = [\"all\"],\n chunk_size: int = 1000,\n deployment: str = \"text-embedding-ada-002\",\n embedding_ctx_length: int = 8191,\n max_retries: int = 6,\n model: str = \"text-embedding-ada-002\",\n model_kwargs: NestedDict = {},\n openai_api_base: Optional[str] = None,\n openai_api_type: Optional[str] = None,\n openai_api_version: Optional[str] = None,\n openai_organization: Optional[str] = None,\n openai_proxy: Optional[str] = None,\n request_timeout: Optional[float] = None,\n show_progress_bar: bool = False,\n skip_empty: bool = False,\n tiktoken_enable: bool = True,\n tiktoken_model_name: Optional[str] = None,\n ) -> Embeddings:\n # This is to avoid errors with Vector Stores (e.g Chroma)\n if disallowed_special == [\"all\"]:\n disallowed_special = \"all\" # type: ignore\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n\n return OpenAIEmbeddings(\n tiktoken_enabled=tiktoken_enable,\n default_headers=default_headers,\n default_query=default_query,\n allowed_special=set(allowed_special),\n disallowed_special=\"all\",\n chunk_size=chunk_size,\n deployment=deployment,\n embedding_ctx_length=embedding_ctx_length,\n max_retries=max_retries,\n model=model,\n model_kwargs=model_kwargs,\n base_url=openai_api_base,\n api_key=api_key,\n openai_api_type=openai_api_type,\n api_version=openai_api_version,\n organization=openai_organization,\n openai_proxy=openai_proxy,\n timeout=request_timeout,\n show_progress_bar=show_progress_bar,\n skip_empty=skip_empty,\n tiktoken_model_name=tiktoken_model_name,\n )\n" + }, + "default_headers": { + "advanced": true, + "display_name": "Default Headers", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "default_headers", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict" + }, + "default_query": { + "advanced": true, + "display_name": "Default Query", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "default_query", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "deployment": { + "advanced": true, + "display_name": "Deployment", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "deployment", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "text-embedding-ada-002" + }, + "disallowed_special": { + "advanced": true, + "display_name": "Disallowed Special", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "disallowed_special", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": [ + "all" + ] + }, + "embedding_ctx_length": { + "advanced": true, + "display_name": "Embedding Context Length", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "embedding_ctx_length", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 8191 + }, + "max_retries": { + "advanced": true, + "display_name": "Max Retries", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "max_retries", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 6 + }, + "model": { + "advanced": false, + "display_name": "Model", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": true, + "load_from_db": false, + "multiline": false, + "name": "model", + "options": [ + "text-embedding-3-small", + "text-embedding-3-large", + "text-embedding-ada-002" + ], + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "text-embedding-ada-002" + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "model_kwargs", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "NestedDict", + "value": {} + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_base", + "password": true, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": true, + "multiline": false, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "str", + "value": "OPENAI_API_KEY" + }, + "openai_api_type": { + "advanced": true, + "display_name": "OpenAI API Type", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_type", + "password": true, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_api_version": { + "advanced": true, + "display_name": "OpenAI API Version", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_api_version", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_organization": { + "advanced": true, + "display_name": "OpenAI Organization", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_organization", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "openai_proxy": { + "advanced": true, + "display_name": "OpenAI Proxy", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "openai_proxy", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + }, + "request_timeout": { + "advanced": true, + "display_name": "Request Timeout", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "request_timeout", + "password": false, + "placeholder": "", + "rangeSpec": { + "max": 1, + "min": -1, + "step": 0.1, + "step_type": "float" + }, + "required": false, + "show": true, + "title_case": false, + "type": "float" + }, + "show_progress_bar": { + "advanced": true, + "display_name": "Show Progress Bar", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "show_progress_bar", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "skip_empty": { + "advanced": true, + "display_name": "Skip Empty", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "skip_empty", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "tiktoken_enable": { + "advanced": true, + "display_name": "TikToken Enable", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": false, + "name": "tiktoken_enable", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": true + }, + "tiktoken_model_name": { + "advanced": true, + "display_name": "TikToken Model Name", + "dynamic": false, + "fileTypes": [], + "file_path": "", + "info": "", + "input_types": [ + "Text" + ], + "list": false, + "load_from_db": false, + "multiline": false, + "name": "tiktoken_model_name", + "password": false, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str" + } + } }, - "id": "OpenAIEmbeddings-9TPjc" + "type": "OpenAIEmbeddings" }, - "selected": false, - "width": 384, + "dragging": false, "height": 383, + "id": "OpenAIEmbeddings-9TPjc", + "position": { + "x": 2814.0402191223047, + "y": 1955.9268168273086 + }, "positionAbsolute": { "x": 2814.0402191223047, "y": 1955.9268168273086 }, - "dragging": false - } - ], - "edges": [ - { - "source": "TextOutput-BDknO", - "target": "Prompt-xeI6K", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextOutputœ,œidœ:œTextOutput-BDknOœ}", - "targetHandle": "{œfieldNameœ:œcontextœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "id": "reactflow__edge-TextOutput-BDknO{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œTextOutputœ,œidœ:œTextOutput-BDknOœ}-Prompt-xeI6K{œfieldNameœ:œcontextœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "context", - "id": "Prompt-xeI6K", - "inputTypes": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "object", - "Text", - "str" - ], - "dataType": "TextOutput", - "id": "TextOutput-BDknO" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "ChatInput-yxMKE", - "target": "Prompt-xeI6K", - "sourceHandle": "{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}", - "targetHandle": "{œfieldNameœ:œquestionœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "id": "reactflow__edge-ChatInput-yxMKE{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}-Prompt-xeI6K{œfieldNameœ:œquestionœ,œidœ:œPrompt-xeI6Kœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "question", - "id": "Prompt-xeI6K", - "inputTypes": [ - "Document", - "BaseOutputParser", - "Record", - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "Text", - "str", - "object", - "Record" - ], - "dataType": "ChatInput", - "id": "ChatInput-yxMKE" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "Prompt-xeI6K", - "target": "OpenAIModel-EjXlN", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-xeI6Kœ}", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-EjXlNœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "id": "reactflow__edge-Prompt-xeI6K{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-xeI6Kœ}-OpenAIModel-EjXlN{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-EjXlNœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-EjXlN", - "inputTypes": [ - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "object", - "Text", - "str" - ], - "dataType": "Prompt", - "id": "Prompt-xeI6K" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "OpenAIModel-EjXlN", - "target": "ChatOutput-Q39I8", - "sourceHandle": "{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-EjXlNœ}", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-Q39I8œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "id": "reactflow__edge-OpenAIModel-EjXlN{œbaseClassesœ:[œobjectœ,œTextœ,œstrœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-EjXlNœ}-ChatOutput-Q39I8{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-Q39I8œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-Q39I8", - "inputTypes": [ - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "object", - "Text", - "str" - ], - "dataType": "OpenAIModel", - "id": "OpenAIModel-EjXlN" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "File-t0a6a", - "target": "RecursiveCharacterTextSplitter-tR9QM", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-t0a6aœ}", - "targetHandle": "{œfieldNameœ:œinputsœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ,œinputTypesœ:[œDocumentœ,œRecordœ],œtypeœ:œDocumentœ}", - "id": "reactflow__edge-File-t0a6a{œbaseClassesœ:[œRecordœ],œdataTypeœ:œFileœ,œidœ:œFile-t0a6aœ}-RecursiveCharacterTextSplitter-tR9QM{œfieldNameœ:œinputsœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ,œinputTypesœ:[œDocumentœ,œRecordœ],œtypeœ:œDocumentœ}", - "data": { - "targetHandle": { - "fieldName": "inputs", - "id": "RecursiveCharacterTextSplitter-tR9QM", - "inputTypes": [ - "Document", - "Record" - ], - "type": "Document" - }, - "sourceHandle": { - "baseClasses": [ - "Record" - ], - "dataType": "File", - "id": "File-t0a6a" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "selected": false - }, - { - "source": "OpenAIEmbeddings-ZlOk1", - "sourceHandle": "{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-ZlOk1œ}", - "target": "AstraDBSearch-41nRz", - "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}", - "data": { - "targetHandle": { - "fieldName": "embedding", - "id": "AstraDBSearch-41nRz", - "inputTypes": null, - "type": "Embeddings" - }, - "sourceHandle": { - "baseClasses": [ - "Embeddings" - ], - "dataType": "OpenAIEmbeddings", - "id": "OpenAIEmbeddings-ZlOk1" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIEmbeddings-ZlOk1{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-ZlOk1œ}-AstraDBSearch-41nRz{œfieldNameœ:œembeddingœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}" - }, - { - "source": "ChatInput-yxMKE", - "sourceHandle": "{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}", - "target": "AstraDBSearch-41nRz", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "AstraDBSearch-41nRz", - "inputTypes": [ - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "Text", - "str", - "object", - "Record" - ], - "dataType": "ChatInput", - "id": "ChatInput-yxMKE" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-ChatInput-yxMKE{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ,œRecordœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-yxMKEœ}-AstraDBSearch-41nRz{œfieldNameœ:œinput_valueœ,œidœ:œAstraDBSearch-41nRzœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" - }, - { - "source": "RecursiveCharacterTextSplitter-tR9QM", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œRecursiveCharacterTextSplitterœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ}", - "target": "AstraDB-eUCSS", - "targetHandle": "{œfieldNameœ:œinputsœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œRecordœ}", - "data": { - "targetHandle": { - "fieldName": "inputs", - "id": "AstraDB-eUCSS", - "inputTypes": null, - "type": "Record" - }, - "sourceHandle": { - "baseClasses": [ - "Record" - ], - "dataType": "RecursiveCharacterTextSplitter", - "id": "RecursiveCharacterTextSplitter-tR9QM" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-RecursiveCharacterTextSplitter-tR9QM{œbaseClassesœ:[œRecordœ],œdataTypeœ:œRecursiveCharacterTextSplitterœ,œidœ:œRecursiveCharacterTextSplitter-tR9QMœ}-AstraDB-eUCSS{œfieldNameœ:œinputsœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œRecordœ}", - "selected": false - }, - { - "source": "OpenAIEmbeddings-9TPjc", - "sourceHandle": "{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-9TPjcœ}", - "target": "AstraDB-eUCSS", - "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}", - "data": { - "targetHandle": { - "fieldName": "embedding", - "id": "AstraDB-eUCSS", - "inputTypes": null, - "type": "Embeddings" - }, - "sourceHandle": { - "baseClasses": [ - "Embeddings" - ], - "dataType": "OpenAIEmbeddings", - "id": "OpenAIEmbeddings-9TPjc" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-OpenAIEmbeddings-9TPjc{œbaseClassesœ:[œEmbeddingsœ],œdataTypeœ:œOpenAIEmbeddingsœ,œidœ:œOpenAIEmbeddings-9TPjcœ}-AstraDB-eUCSS{œfieldNameœ:œembeddingœ,œidœ:œAstraDB-eUCSSœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}", - "selected": false - }, - { - "source": "AstraDBSearch-41nRz", - "sourceHandle": "{œbaseClassesœ:[œRecordœ],œdataTypeœ:œAstraDBSearchœ,œidœ:œAstraDBSearch-41nRzœ}", - "target": "TextOutput-BDknO", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-BDknOœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}", - "data": { - "targetHandle": { - "fieldName": "input_value", - "id": "TextOutput-BDknO", - "inputTypes": [ - "Record", - "Text" - ], - "type": "str" - }, - "sourceHandle": { - "baseClasses": [ - "Record" - ], - "dataType": "AstraDBSearch", - "id": "AstraDBSearch-41nRz" - } - }, - "style": { - "stroke": "#555" - }, - "className": "stroke-gray-900 stroke-connection", - "id": "reactflow__edge-AstraDBSearch-41nRz{œbaseClassesœ:[œRecordœ],œdataTypeœ:œAstraDBSearchœ,œidœ:œAstraDBSearch-41nRzœ}-TextOutput-BDknO{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-BDknOœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}" + "selected": false, + "type": "genericNode", + "width": 384 } ], "viewport": { @@ -3401,7 +3307,8 @@ } }, "description": "Visit https://pre-release.langflow.org/tutorials/rag-with-astradb for a detailed guide of this project.\nThis project give you both Ingestion and RAG in a single file. You'll need to visit https://astra.datastax.com/ to create an Astra DB instance, your Token and grab an API Endpoint.\nRunning this project requires you to add a file in the Files component, then define a Collection Name and click on the Play icon on the Astra DB component. \n\nAfter the ingestion ends you are ready to click on the Run button at the lower left corner and start asking questions about your data.", - "name": "Vector Store RAG", + "id": "51e2b78a-199b-4054-9f32-e288eef6924c", + "is_component": false, "last_tested_version": "1.0.0a0", - "is_component": false + "name": "Vector Store RAG" } \ No newline at end of file diff --git a/src/backend/base/langflow/interface/initialize/loading.py b/src/backend/base/langflow/interface/initialize/loading.py index 03de827b3..afe653e42 100644 --- a/src/backend/base/langflow/interface/initialize/loading.py +++ b/src/backend/base/langflow/interface/initialize/loading.py @@ -7,7 +7,8 @@ import orjson from loguru import logger from langflow.custom.eval import eval_custom_component_code -from langflow.schema.schema import Record +from langflow.graph.utils import get_artifact_type, post_process_raw +from langflow.schema import Record if TYPE_CHECKING: from langflow.custom import CustomComponent @@ -70,7 +71,7 @@ def update_params_with_load_from_db_fields( try: key = None try: - key = custom_component.variables(params[field]) + key = custom_component.variables(params[field], field) except ValueError as e: # check if "User id is not set" is in the error message if "User id is not set" in str(e) and not fallback_to_env_vars: @@ -84,8 +85,12 @@ def update_params_with_load_from_db_fields( logger.info(f"Using environment variable {params[field]} for {field}") if key is None: logger.warning(f"Could not get value for {field}. Setting it to None.") + params[field] = key + except TypeError as exc: + raise exc + except Exception as exc: logger.error(f"Failed to get value for {field} from custom component. Setting it to None. Error: {exc}") @@ -124,4 +129,14 @@ async def instantiate_custom_component(params, user_id, vertex, fallback_to_env_ custom_repr = build_result if not isinstance(custom_repr, str): custom_repr = str(custom_repr) - return custom_component, build_result, {"repr": custom_repr} + raw = custom_component.repr_value + if hasattr(raw, "data") and raw is not None: + raw = raw.data + + elif hasattr(raw, "model_dump") and raw is not None: + raw = raw.model_dump() + + artifact_type = get_artifact_type(custom_component, build_result) + raw = post_process_raw(raw, artifact_type) + artifact = {"repr": custom_repr, "raw": raw, "type": artifact_type} + return custom_component, build_result, artifact diff --git a/src/backend/base/langflow/memory.py b/src/backend/base/langflow/memory.py index f44958fdd..e812f449c 100644 --- a/src/backend/base/langflow/memory.py +++ b/src/backend/base/langflow/memory.py @@ -1,9 +1,9 @@ import warnings -from typing import List, Optional, Union +from typing import List, Optional from loguru import logger -from langflow.schema import Record +from langflow.schema.message import Message from langflow.services.deps import get_monitor_service from langflow.services.monitor.schema import MessageModel @@ -39,54 +39,52 @@ def get_messages( order=order, ) - records: list[Record] = [] + messages: list[Message] = [] # messages_df has a timestamp # it gets the last 5 messages, for example # but now they are ordered from most recent to least recent # so we need to reverse the order messages_df = messages_df[::-1] if order == "DESC" else messages_df for row in messages_df.itertuples(): - record = Record( - data={ - "text": row.message, - "sender": row.sender, - "sender_name": row.sender_name, - "session_id": row.session_id, - "timestamp": row.timestamp, - }, + msg = Message( + text=row.text, + sender=row.sender, + session_id=row.session_id, + sender_name=row.sender_name, + timestamp=row.timestamp, ) - records.append(record) - return records + messages.append(msg) + + return messages -def add_messages(records: Union[list[Record], Record], flow_id: Optional[str] = None): +def add_messages(messages: Message | list[Message], flow_id: Optional[str] = None): """ Add a message to the monitor service. """ try: monitor_service = get_monitor_service() + if not isinstance(messages, list): + messages = [messages] - if isinstance(records, Record): - records = [records] + if not all(isinstance(message, Message) for message in messages): + types = ", ".join([str(type(message)) for message in messages]) + raise ValueError(f"The messages must be instances of Message. Found: {types}") - if not all(isinstance(record, (Record, str)) for record in records): - types = ", ".join([str(type(record)) for record in records]) - raise ValueError(f"The records must be instances of Record. Found: {types}") + messages_models: list[MessageModel] = [] + for msg in messages: + msg.timestamp = monitor_service.get_timestamp() + messages_models.append(MessageModel.from_message(msg, flow_id=flow_id)) - messages: list[MessageModel] = [] - for record in records: - record.timestamp = monitor_service.get_timestamp() - messages.append(MessageModel.from_record(record, flow_id=flow_id)) - - for message in messages: + for message_model in messages_models: try: - monitor_service.add_message(message) + monitor_service.add_message(message_model) except Exception as e: logger.error(f"Error adding message to monitor service: {e}") logger.exception(e) raise e - return records + return messages_models except Exception as e: logger.exception(e) raise e @@ -100,28 +98,22 @@ def delete_messages(session_id: str): session_id (str): The session ID associated with the messages to delete. """ monitor_service = get_monitor_service() - monitor_service.delete_messages(session_id) + monitor_service.delete_messages_session(session_id) def store_message( - message: Union[str, Record], - session_id: Optional[str] = None, - sender: Optional[str] = None, - sender_name: Optional[str] = None, + message: Message, flow_id: Optional[str] = None, -) -> List[Record]: +) -> List[Message]: """ Stores a message in the memory. Args: - message (Union[str, Record]): The message to be stored. It can be either a string or a Record object. - session_id (Optional[str]): The session ID associated with the message. - sender (Optional[str]): The sender ID associated with the message. - sender_name (Optional[str]): The name of the sender associated with the message. + message (Message): The message to store. flow_id (Optional[str]): The flow ID associated with the message. When running from the CustomComponent you can access this using `self.graph.flow_id`. Returns: - List[Record]: A list of records containing the stored message. + List[Message]: A list of records containing the stored message. Raises: ValueError: If any of the required parameters (session_id, sender, sender_name) is not provided. @@ -130,26 +122,7 @@ def store_message( warnings.warn("No message provided.") return [] - if not session_id or not sender or not sender_name: + if not message.session_id or not message.sender or not message.sender_name: raise ValueError("All of session_id, sender, and sender_name must be provided.") - if isinstance(message, Record): - record = message - record.data.update( - { - "session_id": session_id, - "sender": sender, - "sender_name": sender_name, - } - ) - elif isinstance(message, str): - record = Record( - data={ - "text": message, - "session_id": session_id, - "sender": sender, - "sender_name": sender_name, - }, - ) - - return add_messages([record], flow_id=flow_id) + return add_messages([message], flow_id=flow_id) diff --git a/src/backend/base/langflow/schema/__init__.py b/src/backend/base/langflow/schema/__init__.py index 14230578c..9f7e3b384 100644 --- a/src/backend/base/langflow/schema/__init__.py +++ b/src/backend/base/langflow/schema/__init__.py @@ -1,4 +1,4 @@ from .dotdict import dotdict -from .schema import Record +from .record import Record __all__ = ["Record", "dotdict"] diff --git a/src/backend/base/langflow/schema/image.py b/src/backend/base/langflow/schema/image.py new file mode 100644 index 000000000..552f75b8b --- /dev/null +++ b/src/backend/base/langflow/schema/image.py @@ -0,0 +1,63 @@ +import base64 + +from PIL import Image as PILImage +from pydantic import BaseModel + +from langflow.services.deps import get_storage_service + +IMAGE_ENDPOINT = "/files/images/" + + +def is_image_file(file_path): + try: + with PILImage.open(file_path) as img: + img.verify() # Verify that it is, in fact, an image + return True + except (IOError, SyntaxError): + return False + + +async def get_file_paths(files: list[str]): + storage_service = get_storage_service() + file_paths = [] + for file in files: + flow_id, file_name = file.split("/") + file_paths.append(storage_service.build_full_path(flow_id=flow_id, file_name=file_name)) + return file_paths + + +async def get_files( + file_paths: list[str], + convert_to_base64: bool = False, +): + storage_service = get_storage_service() + file_objects: list[str | bytes] = [] + for file_path in file_paths: + flow_id, file_name = file_path.split("/") + file_object = await storage_service.get_file(flow_id=flow_id, file_name=file_name) + if convert_to_base64: + file_base64 = base64.b64encode(file_object).decode("utf-8") + file_objects.append(file_base64) + else: + file_objects.append(file_object) + return file_objects + + +class Image(BaseModel): + path: str | None = None + url: str | None = None + + def to_base64(self): + if self.path: + files = get_files([self.path], convert_to_base64=True) + return files[0] + raise ValueError("Image path is not set.") + + def to_content_dict(self): + return { + "type": "image_url", + "image_url": self.to_base64(), + } + + def get_url(self): + return f"{IMAGE_ENDPOINT}{self.path}" diff --git a/src/backend/base/langflow/schema/message.py b/src/backend/base/langflow/schema/message.py new file mode 100644 index 000000000..865d684bf --- /dev/null +++ b/src/backend/base/langflow/schema/message.py @@ -0,0 +1,111 @@ +from datetime import datetime, timezone +from typing import Annotated, Any, AsyncIterator, Iterator, Optional + +from langchain_core.messages import AIMessage, BaseMessage, HumanMessage +from langchain_core.prompt_values import ImagePromptValue +from langchain_core.prompts.image import ImagePromptTemplate +from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, field_serializer + +from langflow.schema.image import Image, get_file_paths, is_image_file +from langflow.schema.record import Record + + +def _timestamp_to_str(timestamp: datetime) -> str: + return timestamp.strftime("%Y-%m-%d %H:%M:%S") + + +class Message(BaseModel): + model_config = ConfigDict(arbitrary_types_allowed=True) + # Helper class to deal with image data + text: Optional[str | AsyncIterator | Iterator] = Field(default="") + sender: str + sender_name: str + files: Optional[list[str | Image]] = Field(default=[]) + session_id: Optional[str] = Field(default="") + timestamp: Annotated[str, BeforeValidator(_timestamp_to_str)] = Field( + default=datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + ) + flow_id: Optional[str] = None + + def model_post_init(self, __context: Any) -> None: + new_files = [] + for file in self.files or []: + if is_image_file(file): + new_files.append(Image(path=file)) + else: + new_files.append(file) + self.files = new_files + + def to_lc_message( + self, + ) -> BaseMessage: + """ + Converts the Record to a BaseMessage. + + Returns: + BaseMessage: The converted BaseMessage. + """ + # The idea of this function is to be a helper to convert a Record to a BaseMessage + # It will use the "sender" key to determine if the message is Human or AI + # If the key is not present, it will default to AI + # But first we check if all required keys are present in the data dictionary + # they are: "text", "sender" + if self.text is None or not self.sender: + raise ValueError("Missing required keys ('text', 'sender') in Message.") + + if self.sender == "User": + if self.files: + contents = [{"type": "text", "text": self.text}] + contents.extend(self.get_file_content_dicts()) + human_message = HumanMessage(content=contents) + else: + human_message = HumanMessage( + content=[{"type": "text", "text": self.text}], + ) + + return human_message + + return AIMessage(content=self.text) + + @classmethod + def from_record(cls, record: Record) -> "Message": + """ + Converts a BaseMessage to a Record. + + Args: + record (BaseMessage): The BaseMessage to convert. + + Returns: + Record: The converted Record. + """ + + return cls( + text=record.text, + sender=record.sender, + sender_name=record.sender_name, + files=record.files, + session_id=record.session_id, + timestamp=record.timestamp, + flow_id=record.flow_id, + ) + + @field_serializer("text", mode="plain") + def serialize_text(self, value): + if isinstance(value, AsyncIterator): + return "" + elif isinstance(value, Iterator): + return "" + return value + + async def get_file_content_dicts(self): + content_dicts = [] + files = await get_file_paths(self.files) + + for file in files: + if isinstance(file, Image): + content_dicts.append(file.to_content_dict()) + else: + image_template = ImagePromptTemplate() + image_prompt_value: ImagePromptValue = image_template.invoke(input={"path": file}) + content_dicts.append({"type": "image_url", "image_url": image_prompt_value.image_url}) + return content_dicts diff --git a/src/backend/base/langflow/schema/record.py b/src/backend/base/langflow/schema/record.py new file mode 100644 index 000000000..67d9b5da8 --- /dev/null +++ b/src/backend/base/langflow/schema/record.py @@ -0,0 +1,205 @@ +import copy +import json +from typing import Optional, cast + +from langchain_core.documents import Document +from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage +from langchain_core.prompt_values import ImagePromptValue +from langchain_core.prompts.image import ImagePromptTemplate +from pydantic import BaseModel, model_serializer, model_validator + + +class Record(BaseModel): + """ + Represents a record with text and optional data. + + Attributes: + data (dict, optional): Additional data associated with the record. + """ + + text_key: str = "text" + data: dict = {} + default_value: Optional[str] = "" + + @model_validator(mode="before") + def validate_data(cls, values): + if not values.get("data"): + values["data"] = {} + # Any other keyword should be added to the data dictionary + for key in values: + if key not in values["data"] and key not in {"text_key", "data", "default_value"}: + values["data"][key] = values[key] + return values + + @model_serializer(mode="plain", when_used="json") + def serialize_model(self): + data = {k: v.to_json() if hasattr(v, "to_json") else v for k, v in self.data.items()} + return data + + def get_text(self): + """ + Retrieves the text value from the data dictionary. + + If the text key is present in the data dictionary, the corresponding value is returned. + Otherwise, the default value is returned. + + Returns: + The text value from the data dictionary or the default value. + """ + return self.data.get(self.text_key, self.default_value) + + @classmethod + def from_document(cls, document: Document) -> "Record": + """ + Converts a Document to a Record. + + Args: + document (Document): The Document to convert. + + Returns: + Record: The converted Record. + """ + data = document.metadata + data["text"] = document.page_content + return cls(data=data, text_key="text") + + @classmethod + def from_lc_message(cls, message: BaseMessage) -> "Record": + """ + Converts a BaseMessage to a Record. + + Args: + message (BaseMessage): The BaseMessage to convert. + + Returns: + Record: The converted Record. + """ + data: dict = {"text": message.content} + data["metadata"] = cast(dict, message.to_json()) + return cls(data=data, text_key="text") + + def __add__(self, other: "Record") -> "Record": + """ + Combines the data of two records by attempting to add values for overlapping keys + for all types that support the addition operation. Falls back to the value from 'other' + record when addition is not supported. + """ + combined_data = self.data.copy() + for key, value in other.data.items(): + # If the key exists in both records and both values support the addition operation + if key in combined_data: + try: + combined_data[key] += value + except TypeError: + # Fallback: Use the value from 'other' record if addition is not supported + combined_data[key] = value + else: + # If the key is not in the first record, simply add it + combined_data[key] = value + + return Record(data=combined_data) + + def to_lc_document(self) -> Document: + """ + Converts the Record to a Document. + + Returns: + Document: The converted Document. + """ + text = self.data.pop(self.text_key, self.default_value) + return Document(page_content=text, metadata=self.data) + + def to_lc_message( + self, + ) -> HumanMessage | SystemMessage: + """ + Converts the Record to a BaseMessage. + + Returns: + BaseMessage: The converted BaseMessage. + """ + # The idea of this function is to be a helper to convert a Record to a BaseMessage + # It will use the "sender" key to determine if the message is Human or AI + # If the key is not present, it will default to AI + # But first we check if all required keys are present in the data dictionary + # they are: "text", "sender" + if not all(key in self.data for key in ["text", "sender"]): + raise ValueError(f"Missing required keys ('text', 'sender') in Record: {self.data}") + sender = self.data.get("sender", "Machine") + text = self.data.get("text", "") + files = self.data.get("files", []) + if sender == "User": + if files: + contents = [{"type": "text", "text": text}] + for file_path in files: + image_template = ImagePromptTemplate() + image_prompt_value: ImagePromptValue = image_template.invoke(input={"path": file_path}) + contents.append({"type": "image_url", "image_url": image_prompt_value.image_url}) + human_message = HumanMessage(content=contents) + else: + human_message = HumanMessage( + content=[{"type": "text", "text": text}], + ) + + return human_message + + return AIMessage(content=text) + + def __getattr__(self, key): + """ + Allows attribute-like access to the data dictionary. + """ + try: + if key.startswith("__"): + return self.__getattribute__(key) + if key in {"data", "text_key"} or key.startswith("_"): + return super().__getattr__(key) + + return self.data.get(key, self.default_value) + except KeyError: + # Fallback to default behavior to raise AttributeError for undefined attributes + raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") + + def __setattr__(self, key, value): + """ + Allows attribute-like setting of values in the data dictionary, + while still allowing direct assignment to class attributes. + """ + if key in {"data", "text_key"} or key.startswith("_"): + super().__setattr__(key, value) + else: + self.data[key] = value + + def __delattr__(self, key): + """ + Allows attribute-like deletion from the data dictionary. + """ + if key in {"data", "text_key"} or key.startswith("_"): + super().__delattr__(key) + else: + del self.data[key] + + def __deepcopy__(self, memo): + """ + Custom deepcopy implementation to handle copying of the Record object. + """ + # Create a new Record object with a deep copy of the data dictionary + return Record(data=copy.deepcopy(self.data, memo), text_key=self.text_key, default_value=self.default_value) + + # check which attributes the Record has by checking the keys in the data dictionary + def __dir__(self): + return super().__dir__() + list(self.data.keys()) + + def __str__(self) -> str: + # return a JSON string representation of the Record atributes + try: + data = {k: v.to_json() if hasattr(v, "to_json") else v for k, v in self.data.items()} + return json.dumps(data, indent=4) + except Exception: + return str(self.data) + + def __contains__(self, key): + return key in self.data + + def __eq__(self, other): + return isinstance(other, Record) and self.data == other.data diff --git a/src/backend/base/langflow/schema/schema.py b/src/backend/base/langflow/schema/schema.py index 921bd65b2..5153941a5 100644 --- a/src/backend/base/langflow/schema/schema.py +++ b/src/backend/base/langflow/schema/schema.py @@ -1,179 +1,17 @@ -import copy -import json -from typing import Literal, Optional, cast - -from langchain_core.documents import Document -from langchain_core.messages import AIMessage, BaseMessage, HumanMessage -from pydantic import BaseModel, model_validator - - -class Record(BaseModel): - """ - Represents a record with text and optional data. - - Attributes: - data (dict, optional): Additional data associated with the record. - """ - - text_key: str = "text" - data: dict = {} - default_value: Optional[str] = "" - - @model_validator(mode="before") - def validate_data(cls, values): - if not values.get("data"): - values["data"] = {} - # Any other keyword should be added to the data dictionary - for key in values: - if key not in values["data"] and key not in {"text_key", "data", "default_value"}: - values["data"][key] = values[key] - return values - - def get_text(self): - """ - Retrieves the text value from the data dictionary. - - If the text key is present in the data dictionary, the corresponding value is returned. - Otherwise, the default value is returned. - - Returns: - The text value from the data dictionary or the default value. - """ - return self.data.get(self.text_key, self.default_value) - - @classmethod - def from_document(cls, document: Document) -> "Record": - """ - Converts a Document to a Record. - - Args: - document (Document): The Document to convert. - - Returns: - Record: The converted Record. - """ - data = document.metadata - data["text"] = document.page_content - return cls(data=data, text_key="text") - - @classmethod - def from_lc_message(cls, message: BaseMessage) -> "Record": - """ - Converts a BaseMessage to a Record. - - Args: - message (BaseMessage): The BaseMessage to convert. - - Returns: - Record: The converted Record. - """ - data: dict = {"text": message.content} - data["metadata"] = cast(dict, message.to_json()) - return cls(data=data, text_key="text") - - def __add__(self, other: "Record") -> "Record": - """ - Combines the data of two records by attempting to add values for overlapping keys - for all types that support the addition operation. Falls back to the value from 'other' - record when addition is not supported. - """ - combined_data = self.data.copy() - for key, value in other.data.items(): - # If the key exists in both records and both values support the addition operation - if key in combined_data: - try: - combined_data[key] += value - except TypeError: - # Fallback: Use the value from 'other' record if addition is not supported - combined_data[key] = value - else: - # If the key is not in the first record, simply add it - combined_data[key] = value - - return Record(data=combined_data) - - def to_lc_document(self) -> Document: - """ - Converts the Record to a Document. - - Returns: - Document: The converted Document. - """ - text = self.data.pop(self.text_key, self.default_value) - return Document(page_content=text, metadata=self.data) - - def to_lc_message(self) -> BaseMessage: - """ - Converts the Record to a BaseMessage. - - Returns: - BaseMessage: The converted BaseMessage. - """ - # The idea of this function is to be a helper to convert a Record to a BaseMessage - # It will use the "sender" key to determine if the message is Human or AI - # If the key is not present, it will default to AI - # But first we check if all required keys are present in the data dictionary - # they are: "text", "sender" - if not all(key in self.data for key in ["text", "sender"]): - raise ValueError(f"Missing required keys ('text', 'sender') in Record: {self.data}") - sender = self.data.get("sender", "Machine") - text = self.data.get("text", "") - if sender == "User": - return HumanMessage(content=text) - return AIMessage(content=text) - - def __getattr__(self, key): - """ - Allows attribute-like access to the data dictionary. - """ - try: - if key.startswith("__"): - return self.__getattribute__(key) - if key in {"data", "text_key"} or key.startswith("_"): - return super().__getattr__(key) - - return self.data.get(key, self.default_value) - except KeyError: - # Fallback to default behavior to raise AttributeError for undefined attributes - raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") - - def __setattr__(self, key, value): - """ - Allows attribute-like setting of values in the data dictionary, - while still allowing direct assignment to class attributes. - """ - if key in {"data", "text_key"} or key.startswith("_"): - super().__setattr__(key, value) - else: - self.data[key] = value - - def __delattr__(self, key): - """ - Allows attribute-like deletion from the data dictionary. - """ - if key in {"data", "text_key"} or key.startswith("_"): - super().__delattr__(key) - else: - del self.data[key] - - def __deepcopy__(self, memo): - """ - Custom deepcopy implementation to handle copying of the Record object. - """ - # Create a new Record object with a deep copy of the data dictionary - return Record(data=copy.deepcopy(self.data, memo), text_key=self.text_key, default_value=self.default_value) - - # check which attributes the Record has by checking the keys in the data dictionary - def __dir__(self): - return super().__dir__() + list(self.data.keys()) - - def __str__(self) -> str: - # return a JSON string representation of the Record atributes - - return json.dumps(self.data) +from typing import Literal +from typing_extensions import TypedDict INPUT_FIELD_NAME = "input_value" InputType = Literal["chat", "text", "any"] OutputType = Literal["chat", "text", "any", "debug"] + + +class StreamURL(TypedDict): + location: str + + +class Log(TypedDict): + message: str | dict | StreamURL + type: str diff --git a/src/backend/base/langflow/services/cache/utils.py b/src/backend/base/langflow/services/cache/utils.py index ff19836ef..a89963f56 100644 --- a/src/backend/base/langflow/services/cache/utils.py +++ b/src/backend/base/langflow/services/cache/utils.py @@ -23,6 +23,9 @@ class CacheMiss: def __repr__(self): return "" + def __bool__(self): + return False + def create_cache_folder(func): def wrapper(*args, **kwargs): diff --git a/src/backend/base/langflow/services/database/models/flow/model.py b/src/backend/base/langflow/services/database/models/flow/model.py index 7727c7b86..a3f9a055d 100644 --- a/src/backend/base/langflow/services/database/models/flow/model.py +++ b/src/backend/base/langflow/services/database/models/flow/model.py @@ -13,7 +13,7 @@ from pydantic import field_serializer, field_validator from sqlalchemy import UniqueConstraint from sqlmodel import JSON, Column, Field, Relationship, SQLModel -from langflow.schema.schema import Record +from langflow.schema import Record if TYPE_CHECKING: from langflow.services.database.models.folder import Folder @@ -29,6 +29,7 @@ class FlowBase(SQLModel): is_component: Optional[bool] = Field(default=False, nullable=True) updated_at: Optional[datetime] = Field(default_factory=lambda: datetime.now(timezone.utc), nullable=True) webhook: Optional[bool] = Field(default=False, nullable=True, description="Can be used on the webhook endpoint") + folder_id: Optional[UUID] = Field(default=None, nullable=True) endpoint_name: Optional[str] = Field(default=None, nullable=True, index=True) @field_validator("endpoint_name") diff --git a/src/backend/base/langflow/services/monitor/schema.py b/src/backend/base/langflow/services/monitor/schema.py index b3a9ce5c6..4491fd0c5 100644 --- a/src/backend/base/langflow/services/monitor/schema.py +++ b/src/backend/base/langflow/services/monitor/schema.py @@ -1,57 +1,70 @@ import json from datetime import datetime -from typing import TYPE_CHECKING, Any, Optional +from typing import Any, Optional from pydantic import BaseModel, Field, field_serializer, field_validator -if TYPE_CHECKING: - from langflow.schema import Record +from langflow.schema.message import Message -class TransactionModel(BaseModel): - index: Optional[int] = Field(default=None) - timestamp: Optional[datetime] = Field(default_factory=datetime.now, alias="timestamp") - flow_id: str - source: str - target: str - target_args: dict - status: str - error: Optional[str] = None - +class DefaultModel(BaseModel): class Config: from_attributes = True populate_by_name = True + json_encoders = { + datetime: lambda v: v.isoformat(), + } + + def json(self, **kwargs): + # Usa a função de serialização personalizada + return super().json(**kwargs, encoder=self.custom_encoder) + + @staticmethod + def custom_encoder(obj): + if isinstance(obj, datetime): + return obj.isoformat() + raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable") + + +class TransactionModel(DefaultModel): + index: Optional[int] = Field(default=None) + timestamp: Optional[datetime] = Field(default_factory=datetime.now, alias="timestamp") + vertex_id: str + target_id: str | None = None + inputs: dict + outputs: Optional[dict] = None + status: str + error: Optional[str] = None + flow_id: Optional[str] = Field(default=None, alias="flow_id") # validate target_args in case it is a JSON - @field_validator("target_args", mode="before") + @field_validator("outputs", "inputs", mode="before") def validate_target_args(cls, v): if isinstance(v, str): return json.loads(v) return v - @field_serializer("target_args") + @field_serializer("outputs", "inputs") def serialize_target_args(v): if isinstance(v, dict): return json.dumps(v) return v -class TransactionModelResponse(BaseModel): +class TransactionModelResponse(DefaultModel): index: Optional[int] = Field(default=None) timestamp: Optional[datetime] = Field(default_factory=datetime.now, alias="timestamp") - flow_id: str - source: str - target: str - target_args: dict + vertex_id: str + inputs: dict + outputs: Optional[dict] = None status: str error: Optional[str] = None - - class Config: - from_attributes = True - populate_by_name = True + flow_id: Optional[str] = Field(default=None, alias="flow_id") + source: Optional[str] = None + target: Optional[str] = None # validate target_args in case it is a JSON - @field_validator("target_args", mode="before") + @field_validator("outputs", "inputs", mode="before") def validate_target_args(cls, v): if isinstance(v, str): return json.loads(v) @@ -67,38 +80,34 @@ class TransactionModelResponse(BaseModel): return v -class MessageModel(BaseModel): +class MessageModel(DefaultModel): index: Optional[int] = Field(default=None) flow_id: Optional[str] = Field(default=None, alias="flow_id") timestamp: datetime = Field(default_factory=datetime.now) sender: str sender_name: str session_id: str - message: str - artifacts: dict + text: str + files: list[str] = [] - class Config: - from_attributes = True - populate_by_name = True - - @field_validator("artifacts", mode="before") - def validate_target_args(cls, v): + @field_validator("files", mode="before") + def validate_files(cls, v): if isinstance(v, str): return json.loads(v) return v @classmethod - def from_record(cls, record: "Record", flow_id: Optional[str] = None): + def from_message(cls, message: Message, flow_id: Optional[str] = None): # first check if the record has all the required fields - if not record.data or ("sender" not in record.data and "sender_name" not in record.data): - raise ValueError("The record does not have the required fields 'sender' and 'sender_name' in the data.") + if not message.text or not message.sender or not message.sender_name: + raise ValueError("The message does not have the required fields 'sender' and 'sender_name' in the data.") return cls( - sender=record.sender, - sender_name=record.sender_name, - message=record.text, - session_id=record.session_id, - artifacts=record.artifacts or {}, - timestamp=record.timestamp, + sender=message.sender, + sender_name=message.sender_name, + text=message.text, + session_id=message.session_id, + files=message.files or [], + timestamp=message.timestamp, flow_id=flow_id, ) @@ -106,12 +115,6 @@ class MessageModel(BaseModel): class MessageModelResponse(MessageModel): index: Optional[int] = Field(default=None) - @field_validator("artifacts", mode="before") - def serialize_artifacts(v): - if isinstance(v, str): - return json.loads(v) - return v - @field_validator("index", mode="before") def validate_id(cls, v): if isinstance(v, float): @@ -123,13 +126,13 @@ class MessageModelResponse(MessageModel): class MessageModelRequest(MessageModel): - message: str = Field(default="") + text: str = Field(default="") sender: str = Field(default="") sender_name: str = Field(default="") session_id: str = Field(default="") -class VertexBuildModel(BaseModel): +class VertexBuildModel(DefaultModel): index: Optional[int] = Field(default=None, alias="index", exclude=True) id: Optional[str] = Field(default=None, alias="id") flow_id: str @@ -139,10 +142,6 @@ class VertexBuildModel(BaseModel): artifacts: dict timestamp: datetime = Field(default_factory=datetime.now) - class Config: - from_attributes = True - populate_by_name = True - @field_serializer("data", "artifacts") def serialize_dict(v): if isinstance(v, dict): @@ -152,7 +151,7 @@ class VertexBuildModel(BaseModel): v[key] = value.model_dump() elif isinstance(value, list) and all(isinstance(i, BaseModel) for i in value): v[key] = [i.model_dump() for i in value] - return json.dumps(v) + return json.dumps(v, default=str) elif isinstance(v, BaseModel): return v.model_dump_json() return v diff --git a/src/backend/base/langflow/services/monitor/service.py b/src/backend/base/langflow/services/monitor/service.py index 31d63b0b7..949877f4c 100644 --- a/src/backend/base/langflow/services/monitor/service.py +++ b/src/backend/base/langflow/services/monitor/service.py @@ -92,8 +92,6 @@ class MonitorService(Service): with duckdb.connect(str(self.db_path)) as conn: df = conn.execute(query).df() - print(query) - return df.to_dict(orient="records") def delete_vertex_builds(self, flow_id: Optional[str] = None): @@ -143,7 +141,7 @@ class MonitorService(Service): order: Optional[str] = "DESC", limit: Optional[int] = None, ): - query = "SELECT index, flow_id, sender_name, sender, session_id, message, artifacts, timestamp FROM messages" + query = "SELECT index, flow_id, sender_name, sender, session_id, text, timestamp FROM messages" conditions = [] if sender: conditions.append(f"sender = '{sender}'") @@ -177,7 +175,9 @@ class MonitorService(Service): order_by: Optional[str] = "timestamp", flow_id: Optional[str] = None, ): - query = "SELECT index,flow_id, source, target, target_args, status, error, timestamp FROM transactions" + query = ( + "SELECT index,flow_id, status, error, timestamp, vertex_id, inputs, outputs, target_id FROM transactions" + ) conditions = [] if source: conditions.append(f"source = '{source}'") @@ -192,7 +192,7 @@ class MonitorService(Service): query += " WHERE " + " AND ".join(conditions) if order_by: - query += f" ORDER BY {order_by}" + query += f" ORDER BY {order_by} DESC" with duckdb.connect(str(self.db_path)) as conn: df = conn.execute(query).df() diff --git a/src/backend/base/langflow/services/monitor/utils.py b/src/backend/base/langflow/services/monitor/utils.py index f603b3fde..706d62348 100644 --- a/src/backend/base/langflow/services/monitor/utils.py +++ b/src/backend/base/langflow/services/monitor/utils.py @@ -119,21 +119,16 @@ async def log_message( sender_name: str, message: str, session_id: str, - artifacts: Optional[dict] = None, + files: Optional[list] = None, flow_id: Optional[str] = None, ): try: - from langflow.graph.vertex.base import Vertex - - if isinstance(session_id, Vertex): - session_id = await session_id.build() # type: ignore - monitor_service = get_monitor_service() row = { "sender": sender, "sender_name": sender_name, "message": message, - "artifacts": artifacts or {}, + "files": files or [], "session_id": session_id, "timestamp": monitor_service.get_timestamp(), "flow_id": flow_id, @@ -183,17 +178,19 @@ def build_clean_params(target: "Vertex") -> dict: return params -def log_transaction(vertex: "Vertex", status, error=None): +def log_transaction(flow_id, vertex: "Vertex", status, target: Optional["Vertex"] = None, error=None): try: monitor_service = get_monitor_service() clean_params = build_clean_params(vertex) data = { - "vertex_id": vertex.id, + "vertex_id": str(vertex.id), + "target_id": str(target.id) if target else None, "inputs": clean_params, - "output": str(vertex.result), + "outputs": vertex.result.model_dump_json() if vertex.result else None, "timestamp": monitor_service.get_timestamp(), "status": status, "error": error, + "flow_id": flow_id, } monitor_service.add_row(table_name="transactions", data=data) except Exception as e: diff --git a/src/backend/base/langflow/services/settings/base.py b/src/backend/base/langflow/services/settings/base.py index 4f50cb756..679d16627 100644 --- a/src/backend/base/langflow/services/settings/base.py +++ b/src/backend/base/langflow/services/settings/base.py @@ -70,7 +70,7 @@ class Settings(BaseSettings): """Database URL for Langflow. If not provided, Langflow will use a SQLite database.""" pool_size: int = 10 """The number of connections to keep open in the connection pool. If not provided, the default is 10.""" - max_overflow: int = 10 + max_overflow: int = 20 """The number of connections to allow that can be opened beyond the pool size. If not provided, the default is 10.""" cache_type: str = "async" remove_api_keys: bool = False diff --git a/src/backend/base/langflow/services/variable/service.py b/src/backend/base/langflow/services/variable/service.py index 84671e0f9..b2389e890 100644 --- a/src/backend/base/langflow/services/variable/service.py +++ b/src/backend/base/langflow/services/variable/service.py @@ -54,11 +54,19 @@ class VariableService(Service): self, user_id: Union[UUID, str], name: str, + field: str, session: Session = Depends(get_session), ) -> str: # we get the credential from the database # credential = session.query(Variable).filter(Variable.user_id == user_id, Variable.name == name).first() variable = session.exec(select(Variable).where(Variable.user_id == user_id, Variable.name == name)).first() + + if variable.type == "Credential" and field == "session_id": + raise TypeError( + f"variable {name} of type 'Credential' cannot be used in a Session ID field " + "because its purpose is to prevent the exposure of values." + ) + # we decrypt the value if not variable or not variable.value: raise ValueError(f"{name} variable not found.") diff --git a/src/backend/base/langflow/template/field/prompt.py b/src/backend/base/langflow/template/field/prompt.py index ccc5d01a0..138b90131 100644 --- a/src/backend/base/langflow/template/field/prompt.py +++ b/src/backend/base/langflow/template/field/prompt.py @@ -10,5 +10,5 @@ class DefaultPromptField(TemplateField): advanced: bool = False multiline: bool = True - input_types: list[str] = ["Document", "Record", "Text"] + input_types: list[str] = ["Document", "Message", "Record", "Text"] value: str = "" # Set the value to empty string diff --git a/src/backend/base/langflow/utils/schemas.py b/src/backend/base/langflow/utils/schemas.py index fbbec2429..647941f59 100644 --- a/src/backend/base/langflow/utils/schemas.py +++ b/src/backend/base/langflow/utils/schemas.py @@ -2,7 +2,18 @@ import enum from typing import Dict, List, Optional, Union from langchain_core.messages import BaseMessage -from pydantic import BaseModel, model_validator +from pydantic import BaseModel, field_validator, model_validator +from typing_extensions import TypedDict + +from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES + + +class File(TypedDict): + """File schema.""" + + path: str + name: str + type: str class ChatOutputResponse(BaseModel): @@ -14,6 +25,47 @@ class ChatOutputResponse(BaseModel): session_id: Optional[str] = None stream_url: Optional[str] = None component_id: Optional[str] = None + files: List[File] = [] + type: str + + @field_validator("files", mode="before") + def validate_files(cls, files): + """Validate files.""" + if not files: + return files + + for file in files: + if not isinstance(file, dict): + raise ValueError("Files must be a list of dictionaries.") + + if not all(key in file for key in ["path", "name", "type"]): + # If any of the keys are missing, we should extract the + # values from the file path + path = file.get("path") + if not path: + raise ValueError("File path is required.") + + name = file.get("name") + if not name: + name = path.split("/")[-1] + file["name"] = name + _type = file.get("type") + if not _type: + # get the file type from the path + extension = path.split(".")[-1] + file_types = set(TEXT_FILE_TYPES + IMG_FILE_TYPES) + if extension and extension in file_types: + _type = extension + else: + for file_type in file_types: + if file_type in path: + _type = file_type + break + if not _type: + raise ValueError("File type is required.") + file["type"] = _type + + return files @classmethod def from_message( diff --git a/src/backend/base/langflow/utils/util.py b/src/backend/base/langflow/utils/util.py index bc7efc161..89b44bd0e 100644 --- a/src/backend/base/langflow/utils/util.py +++ b/src/backend/base/langflow/utils/util.py @@ -7,8 +7,7 @@ from typing import Any, Dict, List, Optional, Union from docstring_parser import parse - -from langflow.schema.schema import Record +from langflow.schema import Record from langflow.services.deps import get_settings_service from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS from langflow.utils import constants diff --git a/src/frontend/.prettierignore b/src/frontend/.prettierignore index 07ed7069a..a007feab0 100644 --- a/src/frontend/.prettierignore +++ b/src/frontend/.prettierignore @@ -1 +1 @@ -build/* \ No newline at end of file +build/* diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json index 1f50cfedc..14729dfcb 100644 --- a/src/frontend/package-lock.json +++ b/src/frontend/package-lock.json @@ -60,6 +60,7 @@ "react-dom": "^18.2.21", "react-error-boundary": "^4.0.11", "react-hook-form": "^7.51.4", + "react-hotkeys-hook": "^4.5.0", "react-icons": "^5.0.1", "react-laag": "^2.0.5", "react-markdown": "^8.0.7", @@ -480,7 +481,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "extraneous": true, "inBundle": true, "license": "MIT", "engines": { @@ -1924,12 +1924,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.0.tgz", - "integrity": "sha512-rNX5lbNidamSUorBhB4XZ9SQTjAqfe5M+p37Z8ic0jPFBMo5iCtQz1kRWkEMg+rYOKSlVycpQmpqjSFq7LXOfg==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.1.tgz", + "integrity": "sha512-1hZ4TNvD5z9VuhNJ/walIjvMVvYkZKf71axoF/uiAqpntQJXpG64dlXhoDXE3OczPuTuvjf/M5KWFg5VAVUS3Q==", "dev": true, "dependencies": { - "playwright": "1.44.0" + "playwright": "1.44.1" }, "bin": { "playwright": "cli.js" @@ -5989,9 +5989,9 @@ "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" }, "node_modules/electron-to-chromium": { - "version": "1.4.778", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.778.tgz", - "integrity": "sha512-C6q/xcUJf/2yODRxAVCfIk4j3y3LMsD0ehiE2RQNV2cxc8XU62gR6vvYh3+etSUzlgTfil+qDHI1vubpdf0TOA==" + "version": "1.4.780", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.780.tgz", + "integrity": "sha512-NPtACGFe7vunRYzvYqVRhQvsDrTevxpgDKxG/Vcbe0BTNOY+5+/2mOXSw2ls7ToNbE5Bf/+uQbjTxcmwMozpCw==" }, "node_modules/emoji-regex": { "version": "10.3.0", @@ -7619,6 +7619,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", "devOptional": true, "dependencies": { "once": "^1.3.0", @@ -10304,11 +10305,11 @@ } }, "node_modules/playwright": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.0.tgz", - "integrity": "sha512-F9b3GUCLQ3Nffrfb6dunPOkE5Mh68tR7zN32L4jCk4FjQamgesGay7/dAAe1WaMEGV04DkdJfcJzjoCKygUaRQ==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.1.tgz", + "integrity": "sha512-qr/0UJ5CFAtloI3avF95Y0L1xQo6r3LQArLIg/z/PoGJ6xa+EwzrwO5lpNr/09STxdHuUoP2mvuELJS+hLdtgg==", "dependencies": { - "playwright-core": "1.44.0" + "playwright-core": "1.44.1" }, "bin": { "playwright": "cli.js" @@ -10321,9 +10322,9 @@ } }, "node_modules/playwright-core": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.0.tgz", - "integrity": "sha512-ZTbkNpFfYcGWohvTTl+xewITm7EOuqIqex0c7dNZ+aXsbrLj0qI8XlGKfPpipjm0Wny/4Lt4CJsWJk1stVS5qQ==", + "version": "1.44.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.1.tgz", + "integrity": "sha512-wh0JWtYTrhv1+OSsLPgFzGzt67Y7BE/ZS3jEqgGBlp2ppp1ZDj8c+9IARNW4dwf1poq5MgHreEM2KV/GuR4cFA==", "bin": { "playwright-core": "cli.js" }, @@ -11022,6 +11023,15 @@ "react": "^16.8.0 || ^17 || ^18" } }, + "node_modules/react-hotkeys-hook": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-4.5.0.tgz", + "integrity": "sha512-Samb85GSgAWFQNvVt3PS90LPPGSf9mkH/r4au81ZP1yOIFayLC3QAvqTgGtJ8YEDMXtPmaVBs6NgipHO6h4Mug==", + "peerDependencies": { + "react": ">=16.8.1", + "react-dom": ">=16.8.1" + } + }, "node_modules/react-icons": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.2.1.tgz", diff --git a/src/frontend/package.json b/src/frontend/package.json index c799841f7..bb7efd38d 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -55,6 +55,7 @@ "react-dom": "^18.2.21", "react-error-boundary": "^4.0.11", "react-hook-form": "^7.51.4", + "react-hotkeys-hook": "^4.5.0", "react-icons": "^5.0.1", "react-laag": "^2.0.5", "react-markdown": "^8.0.7", @@ -81,7 +82,7 @@ "start": "vite", "build": "vite build", "serve": "vite preview", - "format": "npx prettier --write \"{docs,src}/**/*.{js,jsx,ts,tsx,json,md}\" --ignore-path .prettierignore", + "format": "npx prettier --write \"{tests,src}/**/*.{js,jsx,ts,tsx,json,md}\" --ignore-path .prettierignore", "type-check": "tsc --noEmit --pretty --project tsconfig.json && vite" }, "simple-git-hooks": { diff --git a/src/frontend/playwright.config.ts b/src/frontend/playwright.config.ts index eeb9497ae..5af71db80 100644 --- a/src/frontend/playwright.config.ts +++ b/src/frontend/playwright.config.ts @@ -45,6 +45,9 @@ export default defineConfig({ name: "chromium", use: { ...devices["Desktop Chrome"], + launchOptions: { + // headless: false, + }, contextOptions: { // chromium-specific permissions permissions: ["clipboard-read", "clipboard-write"], @@ -57,6 +60,7 @@ export default defineConfig({ // use: { // ...devices["Desktop Firefox"], // launchOptions: { + // headless: false, // firefoxUserPrefs: { // "dom.events.asyncClipboard.readText": true, // "dom.events.testing.asyncClipboard": true, diff --git a/src/frontend/src/App.css b/src/frontend/src/App.css index 809959757..125282e2c 100644 --- a/src/frontend/src/App.css +++ b/src/frontend/src/App.css @@ -90,31 +90,31 @@ body { } ::-webkit-scrollbar-track { - background-color: #f1f1f1 !important; + background-color: hsl(var(--muted)) !important; border-radius: 10px; } ::-webkit-scrollbar-thumb { - background-color: #ccc !important; + background-color: hsl(var(--border)) !important; border-radius: 999px !important; } ::-webkit-scrollbar-thumb:hover { - background-color: #bbb !important; + background-color: hsl(var(--ring)) !important; } .jv-indent::-webkit-scrollbar-track { - background-color: #f1f1f1 !important; + background-color: hsl(var(--muted)) !important; border-radius: 10px; } .jv-indent::-webkit-scrollbar-thumb { - background-color: #ccc !important; + background-color: hsl(var(--border)) !important; border-radius: 999px !important; } .jv-indent::-webkit-scrollbar-thumb:hover { - background-color: #bbb !important; + background-color: hsl(var(--ring)) !important; } .custom-hover { @@ -138,33 +138,6 @@ body { background-color: #bbb !important; } -.ag-body-horizontal-scroll-viewport, -.ag-body-vertical-scroll-viewport { - cursor: auto; -} - -.ag-body-horizontal-scroll-viewport::-webkit-scrollbar, -.ag-body-vertical-scroll-viewport::-webkit-scrollbar { - width: 8px; - height: 8px; -} - -.ag-body-horizontal-scroll-viewport::-webkit-scrollbar-track, -.ag-body-vertical-scroll-viewport::-webkit-scrollbar-track { - background-color: #f1f1f1; -} - -.ag-body-horizontal-scroll-viewport::-webkit-scrollbar-thumb, -.ag-body-vertical-scroll-viewport::-webkit-scrollbar-thumb { - background-color: #ccc; - border-radius: 999px; -} - -.ag-body-horizontal-scroll-viewport::-webkit-scrollbar-thumb:hover, -.ag-body-vertical-scroll-viewport::-webkit-scrollbar-thumb:hover { - background-color: #bbb; -} - /* This CSS is to not apply the border for the column having 'no-border' class */ .no-border.ag-cell:focus { border: none !important; @@ -174,3 +147,17 @@ body { border: none !important; outline: none; } + +/* selected */ +.react-flow__edge.selected .react-flow__edge-path { + stroke: var(--selected) !important; +} + +.react-flow__edge .react-flow__edge-path { + stroke: var(--connection) !important; +} + +.ag-react-container { + width: 100%; + height: 100%; +} diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index 36f2ad9f9..4a60f453f 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -29,10 +29,10 @@ export default function App() { useTrackLastVisitedPath(); const removeFromTempNotificationList = useAlertStore( - (state) => state.removeFromTempNotificationList + (state) => state.removeFromTempNotificationList, ); const tempNotificationList = useAlertStore( - (state) => state.tempNotificationList + (state) => state.tempNotificationList, ); const [fetchError, setFetchError] = useState(false); const isLoading = useFlowsManagerStore((state) => state.isLoading); @@ -50,7 +50,7 @@ export default function App() { const refreshVersion = useDarkStore((state) => state.refreshVersion); const refreshStars = useDarkStore((state) => state.refreshStars); const setGlobalVariables = useGlobalVariablesStore( - (state) => state.setGlobalVariables + (state) => state.setGlobalVariables, ); const checkHasStore = useStoreStore((state) => state.checkHasStore); const navigate = useNavigate(); diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/components/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/components/index.tsx new file mode 100644 index 000000000..bd28aad11 --- /dev/null +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/components/index.tsx @@ -0,0 +1,12 @@ +import { Textarea } from "../../../../../../../components/ui/textarea"; + +export default function ErrorOutput({ value }: { value: string }) { + return ( +