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/components/agents.mdx b/docs/docs/components/agents.mdx index f8917e4e2..cdc49a76d 100644 --- a/docs/docs/components/agents.mdx +++ b/docs/docs/components/agents.mdx @@ -1,11 +1,13 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Agents -

- 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! ๐Ÿ› ๏ธ๐Ÿ“ -

+

+ 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! ๐Ÿ› ๏ธ๐Ÿ“ +

Agents are components that use reasoning to make decisions and take actions, designed to autonomously perform tasks or provide services with some degree of agency. LLM chains can only perform hardcoded sequences of actions, while agents use LLMs to reason through which actions to take, and in which order. @@ -87,4 +89,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/chains.mdx b/docs/docs/components/chains.mdx index fd3b5bd5d..91477644d 100644 --- a/docs/docs/components/chains.mdx +++ b/docs/docs/components/chains.mdx @@ -6,11 +6,11 @@ import Admonition from "@theme/Admonition"; # Chains -

- Thank you for your patience while we enhance our documentation. It may - have some imperfections. Share your feedback or report issues to help us - improve! ๐Ÿ› ๏ธ๐Ÿ“ -

+

+ Thank you for your patience while we enhance our documentation. It may have + some imperfections. Share your feedback or report issues to help us improve! + ๐Ÿ› ๏ธ๐Ÿ“ +

Chains, in the context of language models, refer to a series of calls made to a language model. This approach allows for using the output of one call as the input for another. Different chain types facilitate varying complexity levels, making them useful for creating pipelines and executing specific scenarios. 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 8e503da06..7664b0406 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 @@ -29,10 +29,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. @@ -54,6 +56,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. @@ -61,10 +64,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. @@ -127,10 +132,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. @@ -151,10 +158,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. @@ -177,14 +186,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. @@ -205,14 +217,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. @@ -233,10 +248,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/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 3ed3d60ca..9da89de3f 100644 --- a/docs/docs/components/model_specs.mdx +++ b/docs/docs/components/model_specs.mdx @@ -1,11 +1,13 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Large Language Models (LLMs) -

- Thank you for your patience as we refine our documentation. You might encounter some inconsistencies. Please help us improve by sharing your feedback or reporting any issues! ๐Ÿ› ๏ธ๐Ÿ“ -

+

+ Thank you for your patience as we refine our documentation. You might + encounter some inconsistencies. Please help us improve by sharing your + feedback or reporting any issues! ๐Ÿ› ๏ธ๐Ÿ“ +

A Large Language Model (LLM) is a foundational component of Langflow. It provides a uniform interface for interacting with LLMs from various providers, including OpenAI, Cohere, and HuggingFace. Langflow extensively uses LLMs across its chains and agents, employing them to generate text based on specific prompts or inputs. @@ -37,7 +39,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). @@ -128,7 +132,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`. @@ -140,4 +145,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 825842df7..f86695e37 100644 --- a/docs/docs/components/retrievers.mdx +++ b/docs/docs/components/retrievers.mdx @@ -1,11 +1,13 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Retrievers -

- We appreciate your patience as we enhance our documentation. It may have some imperfections. Please share your feedback or report issues to help us improve. ๐Ÿ› ๏ธ๐Ÿ“ -

+

+ We appreciate your patience as we enhance our documentation. It may have + some imperfections. Please share your feedback or report issues to help us + improve. ๐Ÿ› ๏ธ๐Ÿ“ +

A retriever is an interface that returns documents in response to an unstructured query. It's broader than a vector store because it doesn't need to store documents; it only needs to retrieve them. 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 940c304eb..25d458360 100644 --- a/docs/docs/components/tools.mdx +++ b/docs/docs/components/tools.mdx @@ -1,11 +1,13 @@ -import Admonition from '@theme/Admonition'; +import Admonition from "@theme/Admonition"; # Tools -

- Thanks for your patience as we refine our documentation. It might have some rough edges currently. Please share your feedback or report issues to help us enhance it! ๐Ÿ› ๏ธ๐Ÿ“ -

+

+ Thanks for your patience as we refine our documentation. It might have some + rough edges currently. Please share your feedback or report issues to help + us enhance it! ๐Ÿ› ๏ธ๐Ÿ“ +

### SearchApi diff --git a/docs/docs/components/utilities.mdx b/docs/docs/components/utilities.mdx index 5f2a86d4d..8ef1f91c8 100644 --- a/docs/docs/components/utilities.mdx +++ b/docs/docs/components/utilities.mdx @@ -3,9 +3,9 @@ import Admonition from "@theme/Admonition"; # Utilities - 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! ๐Ÿ› ๏ธ๐Ÿ“ + 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! + ๐Ÿ› ๏ธ๐Ÿ“ Utilities are a set of actions that can be used to perform common tasks in a flow. They are available in the **Utilities** section in the sidebar. @@ -86,7 +86,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 9c408ad17..fb5efdfdb 100644 --- a/docs/docs/deployment/backend-only.md +++ b/docs/docs/deployment/backend-only.md @@ -4,7 +4,7 @@ You can run Langflow in `--backend-only` mode to expose your Langflow app as an 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 @@ -42,7 +42,7 @@ Note the flow ID of `ef7e0554-69e5-4e3e-ab29-ee83bcd8d9ef`. You can find this ID 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`. + 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: diff --git a/docs/static/data/AstraDB-RAG-Flows.json b/docs/static/data/AstraDB-RAG-Flows.json index e57a15248..1825fe798 100644 --- a/docs/static/data/AstraDB-RAG-Flows.json +++ b/docs/static/data/AstraDB-RAG-Flows.json @@ -81,7 +81,10 @@ "fileTypes": [], "file_path": "", "password": false, - "options": ["Machine", "User"], + "options": [ + "Machine", + "User" + ], "name": "sender", "display_name": "Sender Type", "advanced": true, @@ -89,7 +92,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "sender_name": { "type": "str", @@ -109,7 +114,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "session_id": { "type": "str", @@ -128,13 +135,20 @@ "info": "If provided, the message will be stored in the memory.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "_type": "CustomComponent" }, "description": "Get chat inputs from the Playground.", "icon": "ChatInput", - "base_classes": ["Text", "str", "object", "Record"], + "base_classes": [ + "Text", + "str", + "object", + "Record" + ], "display_name": "Chat Input", "documentation": "", "custom_fields": { @@ -144,7 +158,10 @@ "session_id": null, "return_record": null }, - "output_types": ["Text", "Record"], + "output_types": [ + "Text", + "Record" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -181,7 +198,10 @@ "name": "input_value", "display_name": "Value", "advanced": false, - "input_types": ["Record", "Text"], + "input_types": [ + "Record", + "Text" + ], "dynamic": false, "info": "Text or Record to be passed as output.", "load_from_db": false, @@ -223,20 +243,28 @@ "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"] + "input_types": [ + "Text" + ] }, "_type": "CustomComponent" }, "description": "Display a text output in the Playground.", "icon": "type", - "base_classes": ["object", "Text", "str"], + "base_classes": [ + "object", + "Text", + "str" + ], "display_name": "Extracted Chunks", "documentation": "", "custom_fields": { "input_value": null, "record_template": null }, - "output_types": ["Text"], + "output_types": [ + "Text" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -282,7 +310,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "chunk_size": { "type": "int", @@ -394,7 +424,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "disallowed_special": { "type": "str", @@ -403,7 +435,9 @@ "list": false, "show": true, "multiline": false, - "value": ["all"], + "value": [ + "all" + ], "fileTypes": [], "file_path": "", "password": false, @@ -414,7 +448,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "embedding_ctx_length": { "type": "int", @@ -477,7 +513,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "model_kwargs": { "type": "NestedDict", @@ -515,7 +553,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_api_key": { "type": "str", @@ -534,7 +574,9 @@ "info": "", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "OPENAI_API_KEY" }, "openai_api_type": { @@ -554,7 +596,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_api_version": { "type": "str", @@ -573,7 +617,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_organization": { "type": "str", @@ -592,7 +638,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_proxy": { "type": "str", @@ -611,7 +659,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "request_timeout": { "type": "float", @@ -636,142 +686,142 @@ }, <<<<<<< HEAD "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.field_typing import Prompt, InputField, Text\nfrom langflow.interface.custom.custom_component import CustomComponent\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\": InputField(display_name=\"Template\"),\n \"code\": InputField(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" + "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.field_typing import Prompt, InputField, Text\nfrom langflow.interface.custom.custom_component import CustomComponent\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\": InputField(display_name=\"Template\"),\n \"code\": InputField(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" ], - "name": "", - "display_name": "Prompt", - "documentation": "", - "custom_fields": { - "template": [ - "context", - "question" - ] - }, - "output_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" ], - "full_path": null, - "field_formatters": {}, - "frozen": false, - "field_order": [], - "beta": false, - "error": null + "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" + } }, - "id": "Prompt-xeI6K", "description": "Create a prompt template with dynamic variables.", - "display_name": "Prompt" + "icon": "prompts", + "is_input": null, + "is_output": null, + "is_composition": null, + "base_classes": [ + "object", + "Text", + "str" + ], + "name": "", + "display_name": "Prompt", + "documentation": "", + "custom_fields": { + "template": [ + "context", + "question" + ] + }, + "output_types": [ + "Text" + ], + "full_path": null, + "field_formatters": {}, + "frozen": false, + "field_order": [], + "beta": false, + "error": null + }, + "id": "Prompt-xeI6K", + "description": "Create a prompt template with dynamic variables.", + "display_name": "Prompt" }, "selected": false, "width": 384, "height": 477, "positionAbsolute": { - "x": 2969.0261961391298, - "y": 442.1613649809069 + "x": 2969.0261961391298, + "y": 442.1613649809069 }, "dragging": false ======= @@ -852,13 +902,17 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "_type": "CustomComponent" >>>>>>> origin/dev }, "description": "Generate embeddings using OpenAI models.", - "base_classes": ["Embeddings"], + "base_classes": [ + "Embeddings" + ], "display_name": "OpenAI Embeddings", "documentation": "", "custom_fields": { @@ -885,7 +939,9 @@ "tiktoken_enable": null, "tiktoken_model_name": null }, - "output_types": ["Embeddings"], + "output_types": [ + "Embeddings" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -926,7 +982,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "code": { "type": "code", @@ -1011,7 +1069,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_api_base": { "type": "str", @@ -1030,7 +1090,9 @@ "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"] + "input_types": [ + "Text" + ] }, "openai_api_key": { "type": "str", @@ -1049,7 +1111,9 @@ "info": "The OpenAI API Key to use for the OpenAI model.", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "OPENAI_API_KEY" }, "stream": { @@ -1088,7 +1152,9 @@ "info": "System message to pass to the model.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "temperature": { "type": "float", @@ -1119,7 +1185,11 @@ }, "description": "Generates text using OpenAI LLMs.", "icon": "OpenAI", - "base_classes": ["object", "Text", "str"], + "base_classes": [ + "object", + "Text", + "str" + ], "display_name": "OpenAI", "documentation": "", "custom_fields": { @@ -1133,7 +1203,9 @@ "stream": null, "system_message": null }, - "output_types": ["Text"], + "output_types": [ + "Text" + ], "field_formatters": {}, "frozen": false, "field_order": [ @@ -1203,7 +1275,9 @@ "name": "template", "display_name": "Template", "advanced": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "dynamic": false, "info": "", "load_from_db": false, @@ -1268,14 +1342,23 @@ "is_input": null, "is_output": null, "is_composition": null, - "base_classes": ["object", "Text", "str"], + "base_classes": [ + "object", + "Text", + "str" + ], "name": "", "display_name": "Prompt", "documentation": "", "custom_fields": { - "template": ["context", "question"] + "template": [ + "context", + "question" + ] }, - "output_types": ["Text"], + "output_types": [ + "Text" + ], "full_path": null, "field_formatters": {}, "frozen": false, @@ -1338,7 +1421,9 @@ "name": "input_value", "display_name": "Message", "advanced": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "dynamic": false, "info": "", "load_from_db": false, @@ -1362,7 +1447,9 @@ "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"] + "input_types": [ + "Text" + ] }, "return_record": { "type": "bool", @@ -1394,7 +1481,10 @@ "fileTypes": [], "file_path": "", "password": false, - "options": ["Machine", "User"], + "options": [ + "Machine", + "User" + ], "name": "sender", "display_name": "Sender Type", "advanced": true, @@ -1402,7 +1492,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "sender_name": { "type": "str", @@ -1422,7 +1514,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "session_id": { "type": "str", @@ -1441,13 +1535,20 @@ "info": "If provided, the message will be stored in the memory.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "_type": "CustomComponent" }, "description": "Display a chat message in the Playground.", "icon": "ChatOutput", - "base_classes": ["object", "Text", "Record", "str"], + "base_classes": [ + "object", + "Text", + "Record", + "str" + ], "display_name": "Chat Output", "documentation": "", "custom_fields": { @@ -1458,7 +1559,10 @@ "return_record": null, "record_template": null }, - "output_types": ["Text", "Record"], + "output_types": [ + "Text", + "Record" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -1559,14 +1663,18 @@ }, "description": "A generic file loader.", "icon": "file-text", - "base_classes": ["Record"], + "base_classes": [ + "Record" + ], "display_name": "File", "documentation": "", "custom_fields": { "path": null, "silent_errors": null }, - "output_types": ["Record"], + "output_types": [ + "Record" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -1607,7 +1715,10 @@ "name": "inputs", "display_name": "Input", "advanced": false, - "input_types": ["Document", "Record"], + "input_types": [ + "Document", + "Record" + ], "dynamic": false, "info": "The texts to split.", "load_from_db": false, @@ -1686,13 +1797,19 @@ "info": "The characters to split on.\nIf left empty defaults to [\"\\n\\n\", \"\\n\", \" \", \"\"].", "load_from_db": false, "title_case": false, - "input_types": ["Text"], - "value": [""] + "input_types": [ + "Text" + ], + "value": [ + "" + ] }, "_type": "CustomComponent" }, "description": "Split text into chunks of a specified length.", - "base_classes": ["Record"], + "base_classes": [ + "Record" + ], "display_name": "Recursive Character Text Splitter", "documentation": "https://docs.langflow.org/components/text-splitters#recursivecharactertextsplitter", "custom_fields": { @@ -1701,7 +1818,9 @@ "chunk_size": null, "chunk_overlap": null }, - "output_types": ["Record"], + "output_types": [ + "Record" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -1764,7 +1883,9 @@ "info": "Input value to search", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "api_endpoint": { "type": "str", @@ -1783,7 +1904,9 @@ "info": "API endpoint URL for the Astra DB service.", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "ASTRA_DB_API_ENDPOINT" }, "batch_size": { @@ -1911,7 +2034,9 @@ "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"], + "input_types": [ + "Text" + ], "value": "langflow" }, "metadata_indexing_exclude": { @@ -1931,7 +2056,9 @@ "info": "Optional list of metadata fields to exclude from the indexing.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "metadata_indexing_include": { "type": "str", @@ -1950,7 +2077,9 @@ "info": "Optional list of metadata fields to include in the indexing.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "metric": { "type": "str", @@ -1969,7 +2098,9 @@ "info": "Optional distance metric for vector comparisons in the vector store.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "namespace": { "type": "str", @@ -1988,7 +2119,9 @@ "info": "Optional namespace within Astra DB to use for the collection.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "number_of_results": { "type": "int", @@ -2039,7 +2172,10 @@ "fileTypes": [], "file_path": "", "password": false, - "options": ["Similarity", "MMR"], + "options": [ + "Similarity", + "MMR" + ], "name": "search_type", "display_name": "Search Type", "advanced": false, @@ -2047,7 +2183,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "setup_mode": { "type": "str", @@ -2060,7 +2198,11 @@ "fileTypes": [], "file_path": "", "password": false, - "options": ["Sync", "Async", "Off"], + "options": [ + "Sync", + "Async", + "Off" + ], "name": "setup_mode", "display_name": "Setup Mode", "advanced": true, @@ -2068,7 +2210,9 @@ "info": "Configuration mode for setting up the vector store, with options like \u201cSync\u201d, \u201cAsync\u201d, or \u201cOff\u201d.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "token": { "type": "str", @@ -2087,14 +2231,18 @@ "info": "Authentication token for accessing Astra DB.", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "ASTRA_DB_APPLICATION_TOKEN" }, "_type": "CustomComponent" }, "description": "Searches an existing Astra DB Vector Store.", "icon": "AstraDB", - "base_classes": ["Record"], + "base_classes": [ + "Record" + ], "display_name": "Astra DB Search", "documentation": "", "custom_fields": { @@ -2117,7 +2265,9 @@ "metadata_indexing_exclude": null, "collection_indexing_policy": null }, - "output_types": ["Record"], + "output_types": [ + "Record" + ], "field_formatters": {}, "frozen": false, "field_order": [ @@ -2204,7 +2354,9 @@ "info": "API endpoint URL for the Astra DB service.", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "ASTRA_DB_API_ENDPOINT" }, "batch_size": { @@ -2332,7 +2484,9 @@ "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"], + "input_types": [ + "Text" + ], "value": "langflow" }, "metadata_indexing_exclude": { @@ -2352,7 +2506,9 @@ "info": "Optional list of metadata fields to exclude from the indexing.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "metadata_indexing_include": { "type": "str", @@ -2371,7 +2527,9 @@ "info": "Optional list of metadata fields to include in the indexing.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "metric": { "type": "str", @@ -2390,7 +2548,9 @@ "info": "Optional distance metric for vector comparisons in the vector store.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "namespace": { "type": "str", @@ -2409,7 +2569,9 @@ "info": "Optional namespace within Astra DB to use for the collection.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "pre_delete_collection": { "type": "bool", @@ -2441,7 +2603,11 @@ "fileTypes": [], "file_path": "", "password": false, - "options": ["Sync", "Async", "Off"], + "options": [ + "Sync", + "Async", + "Off" + ], "name": "setup_mode", "display_name": "Setup Mode", "advanced": true, @@ -2449,7 +2615,9 @@ "info": "Configuration mode for setting up the vector store, with options like \u201cSync\u201d, \u201cAsync\u201d, or \u201cOff\u201d.", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "token": { "type": "str", @@ -2468,14 +2636,18 @@ "info": "Authentication token for accessing Astra DB.", "load_from_db": true, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "ASTRA_DB_APPLICATION_TOKEN" }, "_type": "CustomComponent" }, "description": "Builds or loads an Astra DB Vector Store.", "icon": "AstraDB", - "base_classes": ["VectorStore"], + "base_classes": [ + "VectorStore" + ], "display_name": "Astra DB", "documentation": "", "custom_fields": { @@ -2496,7 +2668,9 @@ "metadata_indexing_exclude": null, "collection_indexing_policy": null }, - "output_types": ["VectorStore"], + "output_types": [ + "VectorStore" + ], "field_formatters": {}, "frozen": false, "field_order": [ @@ -2548,7 +2722,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "chunk_size": { "type": "int", @@ -2660,7 +2836,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "disallowed_special": { "type": "str", @@ -2669,7 +2847,9 @@ "list": false, "show": true, "multiline": false, - "value": ["all"], + "value": [ + "all" + ], "fileTypes": [], "file_path": "", "password": false, @@ -2680,7 +2860,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "embedding_ctx_length": { "type": "int", @@ -2743,7 +2925,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "model_kwargs": { "type": "NestedDict", @@ -2781,7 +2965,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_api_key": { "type": "str", @@ -2800,7 +2986,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"], + "input_types": [ + "Text" + ], "value": "" }, "openai_api_type": { @@ -2820,7 +3008,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_api_version": { "type": "str", @@ -2839,7 +3029,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_organization": { "type": "str", @@ -2858,7 +3050,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "openai_proxy": { "type": "str", @@ -2877,7 +3071,9 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "request_timeout": { "type": "float", @@ -2977,12 +3173,16 @@ "info": "", "load_from_db": false, "title_case": false, - "input_types": ["Text"] + "input_types": [ + "Text" + ] }, "_type": "CustomComponent" }, "description": "Generate embeddings using OpenAI models.", - "base_classes": ["Embeddings"], + "base_classes": [ + "Embeddings" + ], "display_name": "OpenAI Embeddings", "documentation": "", "custom_fields": { @@ -3009,7 +3209,9 @@ "tiktoken_enable": null, "tiktoken_model_name": null }, - "output_types": ["Embeddings"], + "output_types": [ + "Embeddings" + ], "field_formatters": {}, "frozen": false, "field_order": [], @@ -3038,11 +3240,20 @@ "targetHandle": { "fieldName": "context", "id": "Prompt-xeI6K", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "inputTypes": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["object", "Text", "str"], + "baseClasses": [ + "object", + "Text", + "str" + ], "dataType": "TextOutput", "id": "TextOutput-BDknO" } @@ -3063,11 +3274,21 @@ "targetHandle": { "fieldName": "question", "id": "Prompt-xeI6K", - "inputTypes": ["Document", "BaseOutputParser", "Record", "Text"], + "inputTypes": [ + "Document", + "BaseOutputParser", + "Record", + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["Text", "str", "object", "Record"], + "baseClasses": [ + "Text", + "str", + "object", + "Record" + ], "dataType": "ChatInput", "id": "ChatInput-yxMKE" } @@ -3088,11 +3309,17 @@ "targetHandle": { "fieldName": "input_value", "id": "OpenAIModel-EjXlN", - "inputTypes": ["Text"], + "inputTypes": [ + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["object", "Text", "str"], + "baseClasses": [ + "object", + "Text", + "str" + ], "dataType": "Prompt", "id": "Prompt-xeI6K" } @@ -3113,11 +3340,17 @@ "targetHandle": { "fieldName": "input_value", "id": "ChatOutput-Q39I8", - "inputTypes": ["Text"], + "inputTypes": [ + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["object", "Text", "str"], + "baseClasses": [ + "object", + "Text", + "str" + ], "dataType": "OpenAIModel", "id": "OpenAIModel-EjXlN" } @@ -3138,11 +3371,16 @@ "targetHandle": { "fieldName": "inputs", "id": "RecursiveCharacterTextSplitter-tR9QM", - "inputTypes": ["Document", "Record"], + "inputTypes": [ + "Document", + "Record" + ], "type": "Document" }, "sourceHandle": { - "baseClasses": ["Record"], + "baseClasses": [ + "Record" + ], "dataType": "File", "id": "File-t0a6a" } @@ -3166,7 +3404,9 @@ "type": "Embeddings" }, "sourceHandle": { - "baseClasses": ["Embeddings"], + "baseClasses": [ + "Embeddings" + ], "dataType": "OpenAIEmbeddings", "id": "OpenAIEmbeddings-ZlOk1" } @@ -3186,11 +3426,18 @@ "targetHandle": { "fieldName": "input_value", "id": "AstraDBSearch-41nRz", - "inputTypes": ["Text"], + "inputTypes": [ + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["Text", "str", "object", "Record"], + "baseClasses": [ + "Text", + "str", + "object", + "Record" + ], "dataType": "ChatInput", "id": "ChatInput-yxMKE" } @@ -3214,7 +3461,9 @@ "type": "Record" }, "sourceHandle": { - "baseClasses": ["Record"], + "baseClasses": [ + "Record" + ], "dataType": "RecursiveCharacterTextSplitter", "id": "RecursiveCharacterTextSplitter-tR9QM" } @@ -3239,7 +3488,9 @@ "type": "Embeddings" }, "sourceHandle": { - "baseClasses": ["Embeddings"], + "baseClasses": [ + "Embeddings" + ], "dataType": "OpenAIEmbeddings", "id": "OpenAIEmbeddings-9TPjc" } @@ -3260,11 +3511,16 @@ "targetHandle": { "fieldName": "input_value", "id": "TextOutput-BDknO", - "inputTypes": ["Record", "Text"], + "inputTypes": [ + "Record", + "Text" + ], "type": "str" }, "sourceHandle": { - "baseClasses": ["Record"], + "baseClasses": [ + "Record" + ], "dataType": "AstraDBSearch", "id": "AstraDBSearch-41nRz" } @@ -3286,4 +3542,4 @@ "name": "Vector Store RAG", "last_tested_version": "1.0.0a0", "is_component": false -} +} \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index ceac78c72..c35e03fae 100644 --- a/poetry.lock +++ b/poetry.lock @@ -471,17 +471,17 @@ files = [ [[package]] name = "boto3" -version = "1.34.121" +version = "1.34.122" description = "The AWS SDK for Python" optional = false python-versions = ">=3.8" files = [ - {file = "boto3-1.34.121-py3-none-any.whl", hash = "sha256:4e79e400d6d44b4eee5deda6ac0ecd08a3f5a30c45a0d30712795cdc4459fd79"}, - {file = "boto3-1.34.121.tar.gz", hash = "sha256:ec89f3e0b0dc959c418df29e14d3748c0b05ab7acf7c0b90c839e9f340a659fa"}, + {file = "boto3-1.34.122-py3-none-any.whl", hash = "sha256:b2d7400ff84fa547e53b3d9acfa3c95d65d45b5886ba1ede1f7df4768d1cc0b1"}, + {file = "boto3-1.34.122.tar.gz", hash = "sha256:56840d8ce91654d182f1c113f0791fa2113c3aa43230c50b4481f235348a6037"}, ] [package.dependencies] -botocore = ">=1.34.121,<1.35.0" +botocore = ">=1.34.122,<1.35.0" jmespath = ">=0.7.1,<2.0.0" s3transfer = ">=0.10.0,<0.11.0" @@ -490,13 +490,13 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.34.121" +version = "1.34.122" description = "Low-level, data-driven core of boto 3." optional = false python-versions = ">=3.8" files = [ - {file = "botocore-1.34.121-py3-none-any.whl", hash = "sha256:25b05c7646a9f240cde1c8f839552a43f27e71e15c42600275dea93e219f7dd9"}, - {file = "botocore-1.34.121.tar.gz", hash = "sha256:1a8f94b917c47dfd84a0b531ab607dc53570efb0d073d8686600f2d2be985323"}, + {file = "botocore-1.34.122-py3-none-any.whl", hash = "sha256:6d75df3af831b62f0c7baa109728d987e0a8d34bfadf0476eb32e2f29a079a36"}, + {file = "botocore-1.34.122.tar.gz", hash = "sha256:9374e16a36f1062c3e27816e8599b53eba99315dfac71cc84fc3aee3f5d3cbe3"}, ] [package.dependencies] @@ -1450,13 +1450,13 @@ tests = ["pytest"] [[package]] name = "dataclasses-json" -version = "0.6.6" +version = "0.6.7" description = "Easily serialize dataclasses to and from JSON." optional = false python-versions = "<4.0,>=3.7" files = [ - {file = "dataclasses_json-0.6.6-py3-none-any.whl", hash = "sha256:e54c5c87497741ad454070ba0ed411523d46beb5da102e221efb873801b0ba85"}, - {file = "dataclasses_json-0.6.6.tar.gz", hash = "sha256:0c09827d26fffda27f1be2fed7a7a01a29c5ddcd2eb6393ad5ebf9d77e9deae8"}, + {file = "dataclasses_json-0.6.7-py3-none-any.whl", hash = "sha256:0dbf33f26c8d5305befd61b39d2b3414e8a407bedc2834dea9b8d642666fb40a"}, + {file = "dataclasses_json-0.6.7.tar.gz", hash = "sha256:b6b3e528266ea45b9535223bc53ca645f5208833c29229e847b3f26a1cc55fc0"}, ] [package.dependencies] @@ -1590,6 +1590,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" @@ -2392,8 +2409,8 @@ files = [ [package.dependencies] cffi = {version = ">=1.12.2", markers = "platform_python_implementation == \"CPython\" and sys_platform == \"win32\""} greenlet = [ - {version = ">=2.0.0", markers = "platform_python_implementation == \"CPython\" and python_version < \"3.11\""}, {version = ">=3.0rc3", markers = "platform_python_implementation == \"CPython\" and python_version >= \"3.11\""}, + {version = ">=2.0.0", markers = "platform_python_implementation == \"CPython\" and python_version < \"3.11\""}, ] "zope.event" = "*" "zope.interface" = "*" @@ -2552,12 +2569,12 @@ files = [ google-auth = ">=2.14.1,<3.0.dev0" googleapis-common-protos = ">=1.56.2,<2.0.dev0" grpcio = [ - {version = ">=1.33.2,<2.0dev", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""}, {version = ">=1.49.1,<2.0dev", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""}, + {version = ">=1.33.2,<2.0dev", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""}, ] grpcio-status = [ - {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""}, {version = ">=1.49.1,<2.0.dev0", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""}, + {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""}, ] proto-plus = ">=1.22.3,<2.0.0dev" protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<5.0.0.dev0" @@ -2626,13 +2643,13 @@ httplib2 = ">=0.19.0" [[package]] name = "google-cloud-aiplatform" -version = "1.54.0" +version = "1.54.1" description = "Vertex AI API client library" optional = false python-versions = ">=3.8" files = [ - {file = "google-cloud-aiplatform-1.54.0.tar.gz", hash = "sha256:6f5187d35a32951028465804fbb42b478362bf41e2b634ddd22b150299f6e1d8"}, - {file = "google_cloud_aiplatform-1.54.0-py2.py3-none-any.whl", hash = "sha256:7b3ed849b9fb59a01bd6f44444ccbb7d18495b867a26f913542f6b2d4c3de252"}, + {file = "google-cloud-aiplatform-1.54.1.tar.gz", hash = "sha256:01c231961cc1a1a3b049ea3ef71fb11e77b2d56d632d020ce09e419b27ff77f2"}, + {file = "google_cloud_aiplatform-1.54.1-py2.py3-none-any.whl", hash = "sha256:43f70fcd572f15317d769e5a0e04cfb7c0e259ead3fe581d2fba4f203ace5617"}, ] [package.dependencies] @@ -4323,13 +4340,13 @@ extended-testing = ["beautifulsoup4 (>=4.12.3,<5.0.0)", "lxml (>=4.9.3,<6.0)"] [[package]] name = "langchainhub" -version = "0.1.17" +version = "0.1.18" description = "The LangChain Hub API client" optional = false python-versions = "<4.0,>=3.8.1" files = [ - {file = "langchainhub-0.1.17-py3-none-any.whl", hash = "sha256:4c609b3948252c71670f0d98f73413b515cfd2f6701a7b40ce959203e6133e04"}, - {file = "langchainhub-0.1.17.tar.gz", hash = "sha256:af7df0cb1cebc7a6e0864e8632ae48ecad39ed96568f699c78657b9d04e50b46"}, + {file = "langchainhub-0.1.18-py3-none-any.whl", hash = "sha256:11501f15e7f34715ecc8892587daa35c6f2a3005e1f2926c9bcabd31fc2c100c"}, + {file = "langchainhub-0.1.18.tar.gz", hash = "sha256:f2d0d8bf3abe4ca5e70511d8220bdc9ccea28d5267bcfd0e5ef9c53bd5bd3bad"}, ] [package.dependencies] @@ -4435,13 +4452,13 @@ requests = ">=2,<3" [[package]] name = "litellm" -version = "1.40.4" +version = "1.40.7" description = "Library to easily interface with LLM API providers" optional = false python-versions = "!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*,>=3.8" files = [ - {file = "litellm-1.40.4-py3-none-any.whl", hash = "sha256:b3b8e4401f717c3a18595446bfdb80fc6bb74974aac4eae537fb7b3be37fbf9e"}, - {file = "litellm-1.40.4.tar.gz", hash = "sha256:3edaa1189742afd7c7df2b122f77373d47154a8fb6df6187ff5875e188baa3e1"}, + {file = "litellm-1.40.7-py3-none-any.whl", hash = "sha256:c98dd8733e632aba16f14bf82e56f7159222097a6d085b242a3140b5d3e7baa4"}, + {file = "litellm-1.40.7.tar.gz", hash = "sha256:557bb19e8e484d0dfe8e4eaa9ccefc888617852988a46d6e7adc41585a2c0600"}, ] [package.dependencies] @@ -4483,13 +4500,13 @@ test = ["httpx (>=0.24.1)", "pytest (>=7.4.0)", "scipy (>=1.10)"] [[package]] name = "locust" -version = "2.28.0" +version = "2.29.0" description = "Developer-friendly load testing framework" optional = false python-versions = ">=3.9" files = [ - {file = "locust-2.28.0-py3-none-any.whl", hash = "sha256:766be879db030c0118e7d9fca712f3538c4e628bdebf59468fa1c6c2fab217d3"}, - {file = "locust-2.28.0.tar.gz", hash = "sha256:260557eec866f7e34a767b6c916b5b278167562a280480aadb88f43d962fbdeb"}, + {file = "locust-2.29.0-py3-none-any.whl", hash = "sha256:aa9d94d3604ed9f2aab3248460d91e55d3de980a821dffdf8658b439b049d03f"}, + {file = "locust-2.29.0.tar.gz", hash = "sha256:649c99ce49d00720a3084c0109547035ad9021222835386599a8b545d31ebe51"}, ] [package.dependencies] @@ -4503,7 +4520,10 @@ msgpack = ">=1.0.0" psutil = ">=5.9.1" pywin32 = {version = "*", markers = "platform_system == \"Windows\""} pyzmq = ">=25.0.0" -requests = ">=2.26.0" +requests = [ + {version = ">=2.32.2", markers = "python_version > \"3.11\""}, + {version = ">=2.26.0", markers = "python_version <= \"3.11\""}, +] tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} Werkzeug = ">=2.0.0" @@ -5599,13 +5619,13 @@ sympy = "*" [[package]] name = "openai" -version = "1.32.0" +version = "1.33.0" description = "The official Python library for the openai API" optional = false python-versions = ">=3.7.1" files = [ - {file = "openai-1.32.0-py3-none-any.whl", hash = "sha256:953d57669f309002044fd2f678aba9f07a43256d74b3b00cd04afb5b185568ea"}, - {file = "openai-1.32.0.tar.gz", hash = "sha256:a6df15a7ab9344b1bc2bc8d83639f68b7a7e2453c0f5e50c1666547eee86f0bd"}, + {file = "openai-1.33.0-py3-none-any.whl", hash = "sha256:621163b56570897ab8389d187f686a53d4771fd6ce95d481c0a9611fe8bc4229"}, + {file = "openai-1.33.0.tar.gz", hash = "sha256:1169211a7b326ecbc821cafb427c29bfd0871f9a3e0947dd9e51acb3b0f1df78"}, ] [package.dependencies] @@ -5931,9 +5951,9 @@ files = [ [package.dependencies] numpy = [ + {version = ">=1.26.0,<2", markers = "python_version >= \"3.12\""}, {version = ">=1.22.4,<2", markers = "python_version < \"3.11\""}, {version = ">=1.23.2,<2", markers = "python_version == \"3.11\""}, - {version = ">=1.26.0,<2", markers = "python_version >= \"3.12\""}, ] python-dateutil = ">=2.8.2" pytz = ">=2020.1" @@ -9068,13 +9088,13 @@ files = [ [[package]] name = "typing-extensions" -version = "4.12.1" +version = "4.12.2" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.12.1-py3-none-any.whl", hash = "sha256:6024b58b69089e5a89c347397254e35f1bf02a907728ec7fee9bf0fe837d203a"}, - {file = "typing_extensions-4.12.1.tar.gz", hash = "sha256:915f5e35ff76f56588223f15fdd5938f9a1cf9195c0de25130c627e4d597f6d1"}, + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, ] [[package]] @@ -10081,4 +10101,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "d87bda272f67450430630924263690c2ae62416d0b240e029baaa8da07154bec" +content-hash = "0ee3f3bef82d57be2ab4ae7b70215ebca67b5bd5223e6a9322ee1837516a3cc6" diff --git a/pyproject.toml b/pyproject.toml index e707957cb..9879e64e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,6 +116,7 @@ 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"] diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index cc38b474a..1dbd68d8f 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}) 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 cbb78c99e..f6a2efbae 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/folders.py b/src/backend/base/langflow/api/v1/folders.py index 7402881c7..d55f9bd15 100644 --- a/src/backend/base/langflow/api/v1/folders.py +++ b/src/backend/base/langflow/api/v1/folders.py @@ -1,5 +1,7 @@ from typing import List +from langflow.helpers.flow import generate_unique_flow_name +from langflow.helpers.folders import generate_unique_folder_name import orjson from fastapi import APIRouter, Depends, File, HTTPException, Response, UploadFile, status from sqlalchemy import or_, update @@ -203,16 +205,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 +227,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..69a26def3 100644 --- a/src/backend/base/langflow/api/v1/monitor.py +++ b/src/backend/base/langflow/api/v1/monitor.py @@ -1,4 +1,6 @@ from typing import List, Optional + + from fastapi import APIRouter, Depends, HTTPException, Query from langflow.services.deps import get_monitor_service @@ -79,7 +81,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 +119,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 02a58f964..e8ec4bfb3 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 = [ @@ -28,3 +30,5 @@ FIELD_FORMAT_ATTRIBUTES = [ "options", "advanced", ] + +ORJSON_OPTIONS = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS | orjson.OPT_OMIT_MICROSECONDS diff --git a/src/backend/base/langflow/base/curl/parse.py b/src/backend/base/langflow/base/curl/parse.py index 892abdde2..c3c2d31ce 100644 --- a/src/backend/base/langflow/base/curl/parse.py +++ b/src/backend/base/langflow/base/curl/parse.py @@ -16,7 +16,7 @@ from collections import OrderedDict, namedtuple from http.cookies import SimpleCookie ParsedArgs = namedtuple( - "ParsedContext", + "ParsedArgs", [ "command", "url", @@ -64,21 +64,20 @@ def parse_curl_command(curl_command): "cookies": {}, } args = args_template.copy() - + method_on_curl = None i = 0 while i < len(tokens): token = tokens[i] if token == "-X": i += 1 args["method"] = tokens[i].lower() + method_on_curl = tokens[i].lower() elif token in ("-d", "--data"): i += 1 args["data"] = tokens[i] - args["method"] = "post" elif token in ("-b", "--data-binary", "--data-raw"): i += 1 args["data_binary"] = tokens[i] - args["method"] = "post" elif token in ("-H", "--header"): i += 1 args["headers"].append(tokens[i]) @@ -106,6 +105,8 @@ def parse_curl_command(curl_command): args["url"] = token i += 1 + args["method"] = method_on_curl or args["method"] + return ParsedArgs(**args) diff --git a/src/backend/base/langflow/base/data/utils.py b/src/backend/base/langflow/base/data/utils.py index c72c9b5b8..3779e8065 100644 --- a/src/backend/base/langflow/base/data/utils.py +++ b/src/backend/base/langflow/base/data/utils.py @@ -1,12 +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 @@ -31,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(".") @@ -94,6 +107,9 @@ def read_text_file(file_path: str) -> str: result = chardet.detect(raw_data) encoding = result["encoding"] + if encoding in ["Windows-1252", "Windows-1254"]: + encoding = "utf-8" + with open(file_path, "r", encoding=encoding) as f: return f.read() @@ -121,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 309480c0f..d82cf4293 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 Component -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(Component): @@ -15,7 +15,7 @@ class ChatComponent(Component): return { "input_value": { "input_types": ["Text"], - "display_name": "Message", + "display_name": "Text", "multiline": True, }, "sender": { @@ -40,98 +40,45 @@ class ChatComponent(Component): "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): + 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 84ef001cf..a9ec48848 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 Component 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(Component): 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/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/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/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/StoreMessage.py b/src/backend/base/langflow/components/experimental/StoreMessage.py index 761646188..19be36068 100644 --- a/src/backend/base/langflow/components/experimental/StoreMessage.py +++ b/src/backend/base/langflow/components/experimental/StoreMessage.py @@ -2,7 +2,7 @@ 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): @@ -31,12 +31,11 @@ class StoreMessageComponent(CustomComponent): sender_name: Optional[str] = None, session_id: Optional[str] = None, message: str = "", - ) -> List[Record]: + ) -> List[Message]: store_message( - sender=sender, - sender_name=sender_name, - session_id=session_id, - message=message, + message=Message( + text=message, sender=sender, sender_name=sender_name, flow_id=self.graph.flow_id, session_id=session_id + ) ) self.status = get_messages(session_id=session_id) 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/inputs/Prompt.py b/src/backend/base/langflow/components/inputs/Prompt.py index f14b9dbdd..961f3325f 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 Input, Prompt, Text +from langflow.field_typing import Input +from langflow.field_typing.prompt import Prompt class PromptComponent(CustomComponent): @@ -15,19 +14,11 @@ class PromptComponent(CustomComponent): "code": Input(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/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 bbb732f16..f2e93d19d 100644 --- a/src/backend/base/langflow/components/memories/AstraDBMessageReader.py +++ b/src/backend/base/langflow/components/memories/AstraDBMessageReader.py @@ -4,7 +4,7 @@ from langchain_astradb.chat_message_histories import AstraDBChatMessageHistory 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 AstraDBMessageReaderComponent(BaseMemoryComponent): diff --git a/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py b/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py index 265f60cf4..a95c7a15c 100644 --- a/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py +++ b/src/backend/base/langflow/components/memories/AstraDBMessageWriter.py @@ -1,11 +1,11 @@ from typing import Optional +from langchain_astradb import AstraDBChatMessageHistory +from langchain_core.messages import BaseMessage + from langflow.base.memory.memory import BaseMemoryComponent from langflow.field_typing import Text -from langflow.schema.schema import Record - -from langchain_core.messages import BaseMessage -from langchain_astradb import AstraDBChatMessageHistory +from langflow.schema import Record class AstraDBMessageWriterComponent(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/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/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 07ded028e..c9f7da8ee 100644 --- a/src/backend/base/langflow/components/vectorstores/AstraDB.py +++ b/src/backend/base/langflow/components/vectorstores/AstraDB.py @@ -1,11 +1,12 @@ from typing import List, Optional, Union + from langchain_astradb import AstraDBVectorStore from langchain_astradb.utils.astradb import SetupMode +from langchain_core.retrievers import BaseRetriever from langflow.custom import CustomComponent from langflow.field_typing import Embeddings, VectorStore from langflow.schema import Record -from langchain_core.retrievers import BaseRetriever class AstraDBVectorStoreComponent(CustomComponent): @@ -156,3 +157,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..5742aad7b 100644 --- a/src/backend/base/langflow/components/vectorstores/Chroma.py +++ b/src/backend/base/langflow/components/vectorstores/Chroma.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 ChromaComponent(CustomComponent): diff --git a/src/backend/base/langflow/components/vectorstores/Couchbase.py b/src/backend/base/langflow/components/vectorstores/Couchbase.py index f99ac7d40..81fa0727a 100644 --- a/src/backend/base/langflow/components/vectorstores/Couchbase.py +++ b/src/backend/base/langflow/components/vectorstores/Couchbase.py @@ -1,18 +1,16 @@ -from typing import List, Optional, Union - -from langchain_community.vectorstores import CouchbaseVectorStore - -from langflow.custom import CustomComponent -from langflow.field_typing import Embeddings, VectorStore -from langflow.schema import Record - from datetime import timedelta +from typing import List, Optional, Union from couchbase.auth import PasswordAuthenticator # type: ignore from couchbase.cluster import Cluster # type: ignore from couchbase.options import ClusterOptions # type: ignore +from langchain_community.vectorstores import CouchbaseVectorStore from langchain_core.retrievers import BaseRetriever +from langflow.custom import CustomComponent +from langflow.field_typing import Embeddings, VectorStore +from langflow.schema import Record + class CouchbaseComponent(CustomComponent): display_name = "Couchbase" 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 0a7926aa1..46ea3de21 100644 --- a/src/backend/base/langflow/custom/custom_component/custom_component.py +++ b/src/backend/base/langflow/custom/custom_component/custom_component.py @@ -378,13 +378,14 @@ class CustomComponent(BaseComponent): 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 9383008dc..5c925daf4 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 512e60529..807f9a77e 100644 --- a/src/backend/base/langflow/field_typing/constants.py +++ b/src/backend/base/langflow/field_typing/constants.py @@ -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..ef6c7ce9a --- /dev/null +++ b/src/backend/base/langflow/field_typing/prompt.py @@ -0,0 +1,41 @@ +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) + 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 a1600203e..8420adb19 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -4,7 +4,6 @@ from collections import defaultdict, deque from functools import partial from itertools import chain from typing import TYPE_CHECKING, Callable, Coroutine, Dict, Generator, List, Optional, Tuple, Type, Union - from loguru import logger from langflow.graph.edge.base import ContractEdge @@ -20,6 +19,7 @@ from langflow.schema.schema import INPUT_FIELD_NAME, InputType from langflow.services.cache.utils import CacheMiss from langflow.services.chat.service import ChatService from langflow.services.deps import get_chat_service +from langflow.services.monitor.utils import log_transaction if TYPE_CHECKING: from langflow.graph.schema import ResultData @@ -725,6 +725,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, ): @@ -752,7 +753,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"] @@ -766,7 +769,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}" @@ -779,9 +785,13 @@ class Graph: next_runnable_vertices, top_level_vertices = await self.get_next_and_top_level_vertices( lock, set_cache_coro, vertex ) + 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}") + 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 2ced35a1c..5d92dc694 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 @@ -394,7 +396,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. @@ -445,11 +447,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: @@ -462,12 +467,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, @@ -548,12 +552,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"): @@ -647,6 +652,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 @@ -687,6 +694,7 @@ class Vertex: self, user_id=None, inputs: Optional[Dict[str, Any]] = None, + files: Optional[list[str]] = None, requester: Optional["Vertex"] = None, **kwargs, ) -> Any: @@ -704,9 +712,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 1aed9a8dc..9123a21fa 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -1,13 +1,12 @@ import json -from typing import Any, AsyncIterator, Dict, Iterator, List +from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, Iterator, List import yaml -from git import TYPE_CHECKING 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.graph.vertex.utils import log_transaction from langflow.schema import Record @@ -153,6 +152,7 @@ class InterfaceVertex(ComponentVertex): 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 @@ -182,12 +182,14 @@ class InterfaceVertex(ComponentVertex): # it means that it is a stream of messages else: message = text_output - + 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 @@ -269,6 +271,8 @@ class InterfaceVertex(ComponentVertex): 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.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-01.png new file mode 100644 index 000000000..fa4fed5d1 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-01.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.png new file mode 100644 index 000000000..6519e7657 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-02.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.png new file mode 100644 index 000000000..512a5b037 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-03.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.png new file mode 100644 index 000000000..6c84a0792 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-04.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.png new file mode 100644 index 000000000..8e4b22298 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-05.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.png new file mode 100644 index 000000000..d317eb499 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-06.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.png new file mode 100644 index 000000000..ed2ed8214 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-07.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.png new file mode 100644 index 000000000..0785f59ea Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-08.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.png new file mode 100644 index 000000000..8dd5b1677 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-09.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.png new file mode 100644 index 000000000..058dff1a8 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-10.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.png new file mode 100644 index 000000000..a517fad0d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-11.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.png new file mode 100644 index 000000000..508590f18 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-12.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.png new file mode 100644 index 000000000..90865a49d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-13.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.png new file mode 100644 index 000000000..269621bb2 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-14.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.png new file mode 100644 index 000000000..da85a4e30 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-15.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.png new file mode 100644 index 000000000..cf30ae136 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-16.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.png new file mode 100644 index 000000000..d53cd7997 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-17.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.png new file mode 100644 index 000000000..e0ac43aab Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-18.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.png new file mode 100644 index 000000000..d04a96a27 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-19.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.png new file mode 100644 index 000000000..e2d6e99bc Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-20.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.png new file mode 100644 index 000000000..392b004e2 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-21.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.png new file mode 100644 index 000000000..606aed15d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-22.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.png new file mode 100644 index 000000000..c16d96d41 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-23.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.png new file mode 100644 index 000000000..e0dd6a1b2 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-24.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.png new file mode 100644 index 000000000..08aeb61c3 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-25.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.png new file mode 100644 index 000000000..312ef035c Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-26.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.png new file mode 100644 index 000000000..95972203e Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-01-27.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.png new file mode 100644 index 000000000..b55f875ac Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-01.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.png new file mode 100644 index 000000000..b51a3b136 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-02.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.png new file mode 100644 index 000000000..8b386a081 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-03.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.png new file mode 100644 index 000000000..e36804f81 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-04.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.png new file mode 100644 index 000000000..7e4661821 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-05.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.png new file mode 100644 index 000000000..5ce14b221 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-06.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.png new file mode 100644 index 000000000..c91f89584 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-07.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.png new file mode 100644 index 000000000..4f4c4ab2e Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-08.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.png new file mode 100644 index 000000000..9c1b5b34d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-09.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.png new file mode 100644 index 000000000..6746a9cc1 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-10.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.png new file mode 100644 index 000000000..771ed1869 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-11.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.png new file mode 100644 index 000000000..f32aa58ee Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-12.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.png new file mode 100644 index 000000000..ae8db49a6 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-13.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.png new file mode 100644 index 000000000..038272194 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-14.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.png new file mode 100644 index 000000000..073b456a0 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-15.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.png new file mode 100644 index 000000000..5369cf9af Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-16.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.png new file mode 100644 index 000000000..1f143bc30 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-17.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.png new file mode 100644 index 000000000..3456bf542 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-18.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.png new file mode 100644 index 000000000..a8f673724 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-19.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.png new file mode 100644 index 000000000..5384bf7a1 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-20.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.png new file mode 100644 index 000000000..1c6a39bbf Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-21.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.png new file mode 100644 index 000000000..976f94dc1 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-22.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.png new file mode 100644 index 000000000..c6ca79192 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-23.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.png new file mode 100644 index 000000000..429f74046 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-24.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.png new file mode 100644 index 000000000..38aeea19c Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-25.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.png new file mode 100644 index 000000000..65342b59d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-26.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.png b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.png new file mode 100644 index 000000000..1c2fc7717 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/People/People Avatar-02-27.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.png new file mode 100644 index 000000000..218c03407 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/026-alien.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.png new file mode 100644 index 000000000..f72f22226 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/027-satellite.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.png new file mode 100644 index 000000000..2e558a69d Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/028-alien.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.png new file mode 100644 index 000000000..6c3622fea Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/029-telescope.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.png new file mode 100644 index 000000000..f1b5cf777 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/030-books.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.png new file mode 100644 index 000000000..289a237c9 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/031-planet.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.png new file mode 100644 index 000000000..ca09192a6 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/032-constellation.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.png new file mode 100644 index 000000000..de3bf7548 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/033-planet.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.png new file mode 100644 index 000000000..0ed7f3a46 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/034-alien.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.png new file mode 100644 index 000000000..b58ec3148 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/035-globe.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.png new file mode 100644 index 000000000..4cb944fd2 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/036-eclipse.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.png new file mode 100644 index 000000000..f1e11b5ed Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/037-meteor.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.png new file mode 100644 index 000000000..63c8893ed Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/038-eclipse.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.png new file mode 100644 index 000000000..8b858f28e Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/039-Asteroid.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.png new file mode 100644 index 000000000..0befc44f1 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/040-mission.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.png new file mode 100644 index 000000000..d499c98b6 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/041-spaceship.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.png new file mode 100644 index 000000000..f13df646b Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/042-space shuttle.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.png new file mode 100644 index 000000000..136dc8031 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/043-space shuttle.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.png new file mode 100644 index 000000000..16d60e221 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/044-rocket.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.png new file mode 100644 index 000000000..fdb107548 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/045-astronaut.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.png new file mode 100644 index 000000000..e2808eb39 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/046-rocket.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.png new file mode 100644 index 000000000..cc3bbf904 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/047-computer.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.png new file mode 100644 index 000000000..0548cb820 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/048-satellite.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.png new file mode 100644 index 000000000..99654c52e Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/049-astronaut.png differ diff --git a/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.png b/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.png new file mode 100644 index 000000000..52c23b249 Binary files /dev/null and b/src/backend/base/langflow/initial_setup/profile_pictures/Space/050-space robot.png differ diff --git a/src/backend/base/langflow/initial_setup/setup.py b/src/backend/base/langflow/initial_setup/setup.py index 9ed8c8b9f..cec6577fe 100644 --- a/src/backend/base/langflow/initial_setup/setup.py +++ b/src/backend/base/langflow/initial_setup/setup.py @@ -2,6 +2,7 @@ import copy import json import logging import os +import shutil from collections import defaultdict from copy import deepcopy from datetime import datetime, timezone @@ -13,14 +14,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 aget_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.folder.utils import create_default_folder_if_it_doesnt_exist from langflow.services.database.models.user.crud import get_user_by_username -from langflow.services.deps import get_settings_service, get_variable_service, session_scope +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." @@ -78,6 +79,12 @@ def update_projects_components_with_latest_component_versions(project_data, all_ } ) node_data["template"][field_name][attr] = field_dict[attr] + 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) project_data_copy = update_new_output(project_data_copy) log_node_changes(node_changes_log) return project_data_copy @@ -167,6 +174,75 @@ def update_new_output(data): return 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: @@ -193,6 +269,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") @@ -224,7 +319,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") @@ -375,6 +470,7 @@ async 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, @@ -388,6 +484,7 @@ async 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/interface/initialize/loading.py b/src/backend/base/langflow/interface/initialize/loading.py index ab8c07a2d..3b9f90116 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 Component, CustomComponent @@ -85,7 +86,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: @@ -99,8 +100,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}") @@ -147,4 +152,14 @@ async def build_custom_component(params: dict, custom_component: "CustomComponen 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..9a07f4bc1 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,46 @@ 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, - }, - ) - records.append(record) + msg = Message(text=row.text, sender=row.sender, sender_name=row.sender_name, timestamp=row.timestamp) - 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 +92,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 +116,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 9c374a730..9f7e3b384 100644 --- a/src/backend/base/langflow/schema/__init__.py +++ b/src/backend/base/langflow/schema/__init__.py @@ -1,5 +1,4 @@ from .dotdict import dotdict -from .schema import Record -from .decision import Decision +from .record import Record -__all__ = ["Record", "dotdict", "Decision"] +__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..830f576ba --- /dev/null +++ b/src/backend/base/langflow/schema/record.py @@ -0,0 +1,202 @@ +import copy +import json +from typing import cast, Optional + +from langchain_core.documents import Document +from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage +from langchain_core.prompts.image import ImagePromptTemplate +from pydantic import BaseModel, model_serializer, model_validator +from langchain_core.prompt_values import ImagePromptValue + + +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 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/database/models/flow/model.py b/src/backend/base/langflow/services/database/models/flow/model.py index 7727c7b86..05953e736 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 diff --git a/src/backend/base/langflow/services/monitor/schema.py b/src/backend/base/langflow/services/monitor/schema.py index b3a9ce5c6..ca267ac2b 100644 --- a/src/backend/base/langflow/services/monitor/schema.py +++ b/src/backend/base/langflow/services/monitor/schema.py @@ -1,35 +1,35 @@ 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 + 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") class Config: from_attributes = True populate_by_name = True # 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) @@ -39,19 +39,21 @@ class TransactionModel(BaseModel): class TransactionModelResponse(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 + vertex_id: str + inputs: dict + outputs: Optional[dict] = None status: str error: Optional[str] = None + flow_id: Optional[str] = Field(default=None, alias="flow_id") + source: Optional[str] = None + target: Optional[str] = None class Config: from_attributes = True populate_by_name = True # 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) @@ -74,31 +76,31 @@ class MessageModel(BaseModel): 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 +108,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,7 +119,7 @@ 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="") diff --git a/src/backend/base/langflow/services/monitor/service.py b/src/backend/base/langflow/services/monitor/service.py index b7c6f0715..2badabc1f 100644 --- a/src/backend/base/langflow/services/monitor/service.py +++ b/src/backend/base/langflow/services/monitor/service.py @@ -132,7 +132,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}'") @@ -166,7 +166,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}'") @@ -181,7 +183,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 d03291ee4..c57b40e36 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(Input): 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/backend/base/langflow/utils/validate.py b/src/backend/base/langflow/utils/validate.py index 8c84a4615..d3edef561 100644 --- a/src/backend/base/langflow/utils/validate.py +++ b/src/backend/base/langflow/utils/validate.py @@ -159,7 +159,10 @@ def create_class(code, class_name): # Replace from langflow import CustomComponent with from langflow.custom import CustomComponent code = code.replace("from langflow import CustomComponent", "from langflow.custom import CustomComponent") - + code = code.replace( + "from langflow.interface.custom.custom_component import CustomComponent", + "from langflow.custom import CustomComponent", + ) module = ast.parse(code) exec_globals = prepare_global_scope(code, module) diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json index 7aa230dd7..c4a1ee671 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", @@ -1923,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" @@ -5988,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", @@ -7618,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", @@ -10303,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" @@ -10320,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" }, @@ -11021,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 c9219b5e5..c069b9da1 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -6,6 +6,7 @@ "@headlessui/react": "^1.7.17", "@hookform/resolvers": "^3.3.4", "@million/lint": "^0.0.73", + "react-hotkeys-hook": "^4.5.0", "@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.4", 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..5a97d371e 100644 --- a/src/frontend/src/App.css +++ b/src/frontend/src/App.css @@ -174,3 +174,12 @@ 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; +} diff --git a/src/frontend/src/CustomNodes/genericNode/components/HandleTooltipComponent/index.tsx b/src/frontend/src/CustomNodes/genericNode_temp/components/HandleTooltipComponent/index.tsx similarity index 96% rename from src/frontend/src/CustomNodes/genericNode/components/HandleTooltipComponent/index.tsx rename to src/frontend/src/CustomNodes/genericNode_temp/components/HandleTooltipComponent/index.tsx index 2dddabbb5..58e28ff3a 100644 --- a/src/frontend/src/CustomNodes/genericNode/components/HandleTooltipComponent/index.tsx +++ b/src/frontend/src/CustomNodes/genericNode_temp/components/HandleTooltipComponent/index.tsx @@ -1,10 +1,9 @@ -import { useRef } from "react"; import { TOOLTIP_EMPTY } from "../../../../constants/constants"; -import { groupByFamily } from "../../../../utils/utils"; -import TooltipRenderComponent from "../tooltipRenderComponent"; +import useFlowStore from "../../../../stores/flowStore"; import { useTypesStore } from "../../../../stores/typesStore"; import { NodeType } from "../../../../types/flow"; -import useFlowStore from "../../../../stores/flowStore"; +import { groupByFamily } from "../../../../utils/utils"; +import TooltipRenderComponent from "../tooltipRenderComponent"; export default function HandleTooltips({ left, diff --git a/src/frontend/src/CustomNodes/genericNode/components/OutputComponent/index.tsx b/src/frontend/src/CustomNodes/genericNode_temp/components/OutputComponent/index.tsx similarity index 99% rename from src/frontend/src/CustomNodes/genericNode/components/OutputComponent/index.tsx rename to src/frontend/src/CustomNodes/genericNode_temp/components/OutputComponent/index.tsx index c8cf9b9a5..9ea7abee2 100644 --- a/src/frontend/src/CustomNodes/genericNode/components/OutputComponent/index.tsx +++ b/src/frontend/src/CustomNodes/genericNode_temp/components/OutputComponent/index.tsx @@ -1,6 +1,8 @@ import { cloneDeep } from "lodash"; import { useUpdateNodeInternals } from "reactflow"; import ForwardedIconComponent from "../../../../components/genericIconComponent"; +import ShadTooltip from "../../../../components/shadTooltipComponent"; +import { Button } from "../../../../components/ui/button"; import { DropdownMenu, DropdownMenuContent, @@ -11,8 +13,6 @@ import useFlowStore from "../../../../stores/flowStore"; import { outputComponentType } from "../../../../types/components"; import { NodeDataType } from "../../../../types/flow"; import { cn } from "../../../../utils/utils"; -import { Button } from "../../../../components/ui/button"; -import ShadTooltip from "../../../../components/shadTooltipComponent"; export default function OutputComponent({ selected, @@ -40,7 +40,7 @@ export default function OutputComponent({ size="xs" className={cn( frozen ? "text-ice" : "", - "items-center gap-1 pl-2 pr-1.5 align-middle text-xs font-normal", + "items-center gap-1 pl-2 pr-1.5 align-middle text-xs font-normal" )} > {selected} diff --git a/src/frontend/src/CustomNodes/genericNode_temp/components/outputModal/components/switchOutputView/components/index.tsx b/src/frontend/src/CustomNodes/genericNode_temp/components/outputModal/components/switchOutputView/components/index.tsx new file mode 100644 index 000000000..bd28aad11 --- /dev/null +++ b/src/frontend/src/CustomNodes/genericNode_temp/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 ( +