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
29.08k stars 3.71k forks source link

Prompt component does not pass variables correctly #3536

Closed Gluepower closed 3 weeks ago

Gluepower commented 4 weeks ago

Bug Description

I have prompt with two variables. {image_url} Value of image is https://oaidalleapiprodscus.blob.core.windows.net/private/org-N0bzhj17kGCdvkPCuGgpUuhO/user-RwGFQKsTTGw8hOO1ResFbpwQ/img-GH9Zkmf4RabhW48gVeZslvyb.png?st=2024-08-23T19%3A00%3A31Z&se=2024-08-23T21%3A00%3A31Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-08-23T18%3A20%3A28Z&ske=2024-08-24T18%3A20%3A28Z&sks=b&skv=2024-08-04&sig=HXgLmH4hDFvbuV/rPEX//ifP0PLXUUlCYP9ZDpFEAHM%3D {post_id} Value of Post ID is 11620

Prompt is Task: Upload the image from the provided URL to WordPress and set it as the featured image for the specified post. Image URL: {image_url} Post ID: {post_id}

This worked on 1.0.15, but after I upgraded to 1.0.16 the second variable is not passed on, it repeats the image one.

Component output Task: Upload the image from the provided URL to WordPress and set it as the featured image for the specified post. Image URL: https://oaidalleapiprodscus.blob.core.windows.net/private/org-N0bzhj17kGCdvkPCuGgpUuhO/user-RwGFQKsTTGw8hOO1ResFbpwQ/img-GH9Zkmf4RabhW48gVeZslvyb.png?st=2024-08-23T19%3A00%3A31Z&se=2024-08-23T21%3A00%3A31Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-08-23T18%3A20%3A28Z&ske=2024-08-24T18%3A20%3A28Z&sks=b&skv=2024-08-04&sig=HXgLmH4hDFvbuV/rPEX//ifP0PLXUUlCYP9ZDpFEAHM%3D Post ID: https://oaidalleapiprodscus.blob.core.windows.net/private/org-N0bzhj17kGCdvkPCuGgpUuhO/user-RwGFQKsTTGw8hOO1ResFbpwQ/img-GH9Zkmf4RabhW48gVeZslvyb.png?st=2024-08-23T19%3A00%3A31Z&se=2024-08-23T21%3A00%3A31Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-08-23T18%3A20%3A28Z&ske=2024-08-24T18%3A20%3A28Z&sks=b&skv=2024-08-04&sig=HXgLmH4hDFvbuV/rPEX//ifP0PLXUUlCYP9ZDpFEAHM%3D

Reproduction

Create prompt with multiple variables. Add value in each. Try to build prompt and you will find that only first variable is being pulled. image

image

Expected behavior

multiple variables should work

Who can help?

No response

Operating System

Render

Langflow Version

1.0.16

Python Version

3.12

Screenshot

No response

Flow File

No response

dosubot[bot] commented 4 weeks ago

The issue with the prompt component in Langflow version 1.0.16 not passing the second variable correctly and repeating the first variable is likely due to how the build_prompt method is implemented. The method uses Message.from_template_and_variables(**self._attributes) to create the prompt, but it seems that the variables are not being correctly mapped.

Here is the relevant part of the code:

class PromptComponent(Component):
    display_name: str = "Prompt"
    description: str = "Create a prompt template with dynamic variables."
    icon = "prompts"
    trace_type = "prompt"

    inputs = [
        PromptInput(name="template", display_name="Template"),
    ]

    outputs = [
        Output(display_name="Prompt Message", name="prompt", method="build_prompt"),
    ]

    async def build_prompt(
        self,
    ) -> Message:
        prompt = await Message.from_template_and_variables(**self._attributes)
        self.status = prompt.text
        return prompt

The problem might be in how self._attributes is populated or how Message.from_template_and_variables processes these attributes. If self._attributes contains duplicate keys or if the method does not correctly distinguish between different variables, it could result in the same variable being used multiple times.

To fix this, ensure that self._attributes correctly maps each variable to its corresponding value and that Message.from_template_and_variables correctly processes these mappings. You might need to debug or modify the from_template_and_variables method to handle multiple variables properly [[1]](https://github.com/langflow-ai/langflow/blob/dev/src/backend/base/langflow/initial_setup/starter_projects/Langflow Prompt Chaining.json).

To continue talking to Dosu, mention @dosu.

edwinjosechittilappilly commented 3 weeks ago

Hi @Gluepower,

Thanks for your feedback! It looks like the scenario is working as expected in the latest version of Langflow (v1.0.17).

Would you be able to try updating your Langflow installation to see if that resolves the issue?

For reference, I've attached the screenshots you previously sent and a sample flow that you mentioned (in case they're helpful).

Please let me know if updating Langflow resolves the issue, or if you encounter any problems during the update process.

Screenshot 2024-08-28 at 1 45 20 PM Screenshot 2024-08-28 at 1 45 06 PM

Testing#3536.json

Gluepower commented 3 weeks ago

Hi @edwinjosechittilappilly

It is intermittent. If I freeze path most of the time will do well. However, when I run complete flow it will show this error. I never had this issue with 1.0.15 and before. It showed up with 1.0.16 and with 1.0.17 is the same. Here is short video going through the flow to show components. At the end is running full flow and it shows this error.

https://youtu.be/pQlPWLmrmp0

edwinjosechittilappilly commented 3 weeks ago

Yes It might be related. Based on further investigation, I believe this issue is not related to the Prompt component but rather to the LLM component and/or the data sending functions in downstream of LLM components as mentioned in #3619.

Closing this issue. Please refer to #3619 for further discussion