langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
36.95k stars 4.32k forks source link

Custom Component Creation - Multiple Outputs Not Working in Versions 1.0.19 and Main #4185

Open edwinjosechittilappilly opened 1 month ago

edwinjosechittilappilly commented 1 month ago

Bug Description

Issue: When creating a custom component using multiple outputs, the functionality is broken in both version 1.0.19 and the main branch of Langflow. This worked correctly in version 1.0.18.

Component Code Example:

from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output
from langflow.schema.message import Message

class MultiTextInputComponent(TextComponent):
    display_name = "Text Input"
    description = "Get text inputs from the Playground."
    icon = "type"
    name = "TextInput"

    inputs = [
        MultilineInput(
            name="user_input",
            display_name="Text",
            info="Text to be passed as input.",
        ),
        MultilineInput(
            name="person",
            display_name="Text",
            info="Persona in which the reply should be given.",
        ),
    ]
    outputs = [
        Output(display_name="user", name="text", method="user_response"),
        Output(display_name="person", name="text", method="person_response")
    ]

    def user_response(self) -> Message:
        return Message(
            text=self.user_input,
        )
    def person_response(self) -> Message:
        return Message(
            text=self.person,
        )

Additional Information: This issue seems to have been introduced in version 1.0.19. The component works as expected in 1.0.18.

https://github.com/user-attachments/assets/c23a5cc2-1dfc-43a2-a35e-3e80ab109296

Reproduction

Steps to Reproduce:

1.  Create a custom component with multiple outputs as shown in the code above.
2.  Attempt to run it in versions 1.0.19 or main.
3.  Observe that multiple outputs are not generated.

Expected behavior

Expected Behavior: Both outputs (user_response and person_response) should be created and returned correctly.

Actual Behavior: In versions 1.0.19 and main, only one output is created. The second output is not generated, breaking the expected functionality.

Who can help?

@cris

Operating System

Mac OS

Langflow Version

Version Information: • Langflow: 1.0.19 (also broken in main) • Working Version: 1.0.18

Python Version

3.12

Screenshot

No response

Flow File

No response

Cristhianzl commented 4 weeks ago

Hi @edwinjosechittilappilly,

The issue here is that the output names currently aren’t unique, which is causing conflicts. To resolve this, each output needs a distinct name. By updating the code as follows:

outputs = [
    Output(display_name="user", name="text_user", method="user_response"),
    Output(display_name="person", name="text_person", method="person_response")
]

_name="text_person"_ _name="textuser"

you’ll be able to see both outputs separately, as shown here:

image

Does that make sense? Thanks!